|
|
0af795 |
--- src/hunspell/hunspell.cxx 2011-02-02 12:04:29.000000000 +0000
|
|
|
0af795 |
+++ src/hunspell/hunspell.cxx 2013-03-13 16:50:50.667928521 +0000
|
|
|
0af795 |
@@ -12,6 +12,8 @@
|
|
|
0af795 |
#endif
|
|
|
0af795 |
#include "csutil.hxx"
|
|
|
0af795 |
|
|
|
0af795 |
+#include <string>
|
|
|
0af795 |
+
|
|
|
0af795 |
Hunspell::Hunspell(const char * affpath, const char * dpath, const char * key)
|
|
|
0af795 |
{
|
|
|
0af795 |
encoding = NULL;
|
|
|
0af795 |
@@ -1710,6 +1712,19 @@
|
|
|
0af795 |
return n;
|
|
|
0af795 |
}
|
|
|
0af795 |
|
|
|
0af795 |
+namespace
|
|
|
0af795 |
+{
|
|
|
0af795 |
+ void myrep(std::string& str, const std::string& search, const std::string& replace)
|
|
|
0af795 |
+ {
|
|
|
0af795 |
+ size_t pos = 0;
|
|
|
0af795 |
+ while ((pos = str.find(search, pos)) != std::string::npos)
|
|
|
0af795 |
+ {
|
|
|
0af795 |
+ str.replace(pos, search.length(), replace);
|
|
|
0af795 |
+ pos += replace.length();
|
|
|
0af795 |
+ }
|
|
|
0af795 |
+ }
|
|
|
0af795 |
+}
|
|
|
0af795 |
+
|
|
|
0af795 |
int Hunspell::spellml(char*** slst, const char * word)
|
|
|
0af795 |
{
|
|
|
0af795 |
char *q, *q2;
|
|
|
0af795 |
@@ -1721,26 +1736,26 @@
|
|
|
0af795 |
q2 = strstr(q2, "
|
|
|
0af795 |
if (!q2) return 0; // bad XML input
|
|
|
0af795 |
if (check_xml_par(q, "type=", "analyze")) {
|
|
|
0af795 |
- int n = 0, s = 0;
|
|
|
0af795 |
+ int n = 0;
|
|
|
0af795 |
if (get_xml_par(cw, strchr(q2, '>'), MAXWORDUTF8LEN - 10)) n = analyze(slst, cw);
|
|
|
0af795 |
if (n == 0) return 0;
|
|
|
0af795 |
// convert the result to ana1ana2 format
|
|
|
0af795 |
- for (int i = 0; i < n; i++) s+= strlen((*slst)[i]);
|
|
|
0af795 |
- char * r = (char *) malloc(6 + 5 * s + 7 * n + 7 + 1); // XXX 5*s->&->&
|
|
|
0af795 |
- if (!r) return 0;
|
|
|
0af795 |
- strcpy(r, "");
|
|
|
0af795 |
+ std::string r;
|
|
|
0af795 |
+ r.append("");
|
|
|
0af795 |
for (int i = 0; i < n; i++) {
|
|
|
0af795 |
- int l = strlen(r);
|
|
|
0af795 |
- strcpy(r + l, "");
|
|
|
0af795 |
- strcpy(r + l + 3, (*slst)[i]);
|
|
|
0af795 |
- mystrrep(r + l + 3, "\t", " ");
|
|
|
0af795 |
- mystrrep(r + l + 3, "<", "<");
|
|
|
0af795 |
- mystrrep(r + l + 3, "&", "&");
|
|
|
0af795 |
- strcat(r, "");
|
|
|
0af795 |
+ r.append("");
|
|
|
0af795 |
+
|
|
|
0af795 |
+ std::string entry((*slst)[i]);
|
|
|
0af795 |
free((*slst)[i]);
|
|
|
0af795 |
+ myrep(entry, "\t", " ");
|
|
|
0af795 |
+ myrep(entry, "&", "&");
|
|
|
0af795 |
+ myrep(entry, "<", "<");
|
|
|
0af795 |
+ r.append(entry);
|
|
|
0af795 |
+
|
|
|
0af795 |
+ r.append("");
|
|
|
0af795 |
}
|
|
|
0af795 |
- strcat(r, "");
|
|
|
0af795 |
- (*slst)[0] = r;
|
|
|
0af795 |
+ r.append("");
|
|
|
0af795 |
+ (*slst)[0] = mystrdup(r.c_str());
|
|
|
0af795 |
return 1;
|
|
|
0af795 |
} else if (check_xml_par(q, "type=", "stem")) {
|
|
|
0af795 |
if (get_xml_par(cw, strchr(q2, '>'), MAXWORDUTF8LEN - 1)) return stem(slst, cw);
|