Blame SOURCES/hunspell.rhbz918938.patch

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