integrated case-folding into unac for better performance
This commit is contained in:
+5
-4
@@ -1,5 +1,8 @@
|
||||
# @(#$Id: Makefile,v 1.8 2006-01-06 13:18:17 dockes Exp $ (C) 2005 J.F.Dockes
|
||||
|
||||
# Only test progs in there
|
||||
include ../mk/sysconf
|
||||
|
||||
# Only test executables get build in here
|
||||
PROGS = internfile unacpp textsplit
|
||||
|
||||
all: $(BIGLIB) $(PROGS)
|
||||
@@ -29,8 +32,6 @@ trinternfile.o : internfile.cpp
|
||||
$(CXX) $(CXXFLAGS) -DTEST_INTERNFILE -c -o trinternfile.o \
|
||||
internfile.cpp
|
||||
|
||||
clean::
|
||||
clean:
|
||||
rm -f *.o $(PROGS)
|
||||
|
||||
include ../mk/sysconf
|
||||
|
||||
|
||||
+10
-21
@@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: unacpp.cpp,v 1.5 2006-01-05 16:37:26 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: unacpp.cpp,v 1.6 2006-01-06 13:18:17 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
|
||||
#ifndef TEST_UNACPP
|
||||
@@ -17,28 +17,16 @@ using std::string;
|
||||
#include "unac.h"
|
||||
|
||||
|
||||
bool unac_cpp(const std::string &in, std::string &out, const char *encoding)
|
||||
bool unacmaybefold(const std::string &in, std::string &out,
|
||||
const char *encoding, bool dofold)
|
||||
{
|
||||
char *cout = 0;
|
||||
size_t out_len;
|
||||
|
||||
if (unac_string(encoding, in.c_str(), in.length(), &cout, &out_len) < 0) {
|
||||
char cerrno[20];
|
||||
sprintf(cerrno, "%d", errno);
|
||||
out = string("unac_string failed, errno : ") + cerrno;
|
||||
return false;
|
||||
}
|
||||
out.assign(cout, out_len);
|
||||
free(cout);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool unac_cpp_utf16be(const std::string &in, std::string &out)
|
||||
{
|
||||
char *cout = 0;
|
||||
size_t out_len;
|
||||
|
||||
if (unac_string_utf16(in.c_str(), in.length(), &cout, &out_len) < 0) {
|
||||
int status;
|
||||
status = dofold ?
|
||||
unacfold_string(encoding, in.c_str(), in.length(), &cout, &out_len) :
|
||||
unac_string(encoding, in.c_str(), in.length(), &cout, &out_len);
|
||||
if (status < 0) {
|
||||
char cerrno[20];
|
||||
sprintf(cerrno, "%d", errno);
|
||||
out = string("unac_string failed, errno : ") + cerrno;
|
||||
@@ -65,6 +53,7 @@ using namespace std;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
bool dofold = true;
|
||||
if (argc != 4) {
|
||||
cerr << "Usage: unacpp <encoding> <infile> <outfile>" << endl;
|
||||
exit(1);
|
||||
@@ -79,7 +68,7 @@ int main(int argc, char **argv)
|
||||
exit(1);
|
||||
}
|
||||
string ndata;
|
||||
if (!unac_cpp(odata, ndata, encoding)) {
|
||||
if (!unacmaybefold(odata, ndata, encoding, dofold)) {
|
||||
cerr << "unac: " << ndata << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
+4
-6
@@ -1,12 +1,10 @@
|
||||
#ifndef _UNACPP_H_INCLUDED_
|
||||
#define _UNACPP_H_INCLUDED_
|
||||
/* @(#$Id: unacpp.h,v 1.2 2006-01-05 16:37:26 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: unacpp.h,v 1.3 2006-01-06 13:18:17 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
#include <string>
|
||||
|
||||
// A small wrapper for unac.c
|
||||
extern bool unac_cpp(const std::string &in, std::string &out,
|
||||
const char *encoding = "UTF-8");
|
||||
extern bool unac_cpp_utf16be(const std::string &in, std::string &out);
|
||||
|
||||
// A small stringified wrapper for unac.c
|
||||
extern bool unacmaybefold(const std::string &in, std::string &out,
|
||||
const char *encoding, bool dofold);
|
||||
#endif /* _UNACPP_H_INCLUDED_ */
|
||||
|
||||
Reference in New Issue
Block a user