diff options
Diffstat (limited to 'libs/hunspell/src/phonet.c++')
-rw-r--r-- | libs/hunspell/src/phonet.c++ | 59 |
1 files changed, 24 insertions, 35 deletions
diff --git a/libs/hunspell/src/phonet.c++ b/libs/hunspell/src/phonet.c++ index 2b4d2ae504..17350e74a7 100644 --- a/libs/hunspell/src/phonet.c++ +++ b/libs/hunspell/src/phonet.c++ @@ -66,33 +66,30 @@ static int myisalpha(char ch) { return 1; } +/* Do phonetic transformation. */ /* phonetic transcription algorithm */ /* see: http://aspell.net/man-html/Phonetic-Code.html */ /* convert string to uppercase before this call */ -int phonet(const char* inword, char* target, int len, phonetable& parms) { - /** Do phonetic transformation. **/ - /** "len" = length of "inword" incl. '\0'. **/ +std::string phonet(const std::string& inword, phonetable& parms) { - /** result: >= 0: length of "target" **/ - /** otherwise: error **/ - - int i, j, k = 0, n, p, z; + int i, k = 0, p, z; int k0, n0, p0 = -333, z0; - char c, c0; + char c; const char* s; typedef unsigned char uchar; - char word[MAXPHONETUTF8LEN + 1]; - if (len == -1) - len = strlen(inword); + + size_t len = inword.size(); if (len > MAXPHONETUTF8LEN) - return 0; - strncpy(word, inword, MAXPHONETUTF8LEN); + return std::string(); + char word[MAXPHONETUTF8LEN + 1]; + strncpy(word, inword.c_str(), MAXPHONETUTF8LEN); word[MAXPHONETUTF8LEN] = '\0'; + std::string target; /** check word **/ - i = j = z = 0; + i = z = 0; while ((c = word[i]) != '\0') { - n = parms.hash[(uchar)c]; + int n = parms.hash[(uchar)c]; z0 = 0; if (n >= 0) { @@ -141,7 +138,7 @@ int phonet(const char* inword, char* target, int len, phonetable& parms) { (!myisalpha(word[i + k0])))) { /** search for followup rules, if: **/ /** parms.followup and k > 1 and NO '-' in searchstring **/ - c0 = word[i + k - 1]; + char c0 = word[i + k - 1]; n0 = parms.hash[(uchar)c0]; // if (parms.followup && k > 1 && n0 >= 0 @@ -216,9 +213,9 @@ int phonet(const char* inword, char* target, int len, phonetable& parms) { : 0; if (p0 == 1 && z == 0) { /** rule with '<' is used **/ - if (j > 0 && *s != '\0' && - (target[j - 1] == c || target[j - 1] == *s)) { - j--; + if (!target.empty() && *s != '\0' && + (target[target.size()-1] == c || target[target.size()-1] == *s)) { + target.erase(target.size() - 1); } z0 = 1; z = 1; @@ -236,10 +233,9 @@ int phonet(const char* inword, char* target, int len, phonetable& parms) { } else { /** no '<' rule used **/ i += k - 1; z = 0; - while (*s != '\0' && *(s + 1) != '\0' && j < len) { - if (j == 0 || target[j - 1] != *s) { - target[j] = *s; - j++; + while (*s != '\0' && *(s + 1) != '\0' && target.size() < len) { + if (target.empty() || target[target.size()-1] != *s) { + target.push_back(*s); } s++; } @@ -248,8 +244,7 @@ int phonet(const char* inword, char* target, int len, phonetable& parms) { if (parms.rules[n][0] != '\0' && strstr(parms.rules[n] + 1, "^^") != NULL) { if (c != '\0') { - target[j] = c; - j++; + target.push_back(c); } strmove(&word[0], &word[0] + i + 1); i = 0; @@ -262,15 +257,11 @@ int phonet(const char* inword, char* target, int len, phonetable& parms) { } /** end of while (parms.rules[n][0] == c) **/ } /** end of if (n >= 0) **/ if (z0 == 0) { - // if (k && (assert(p0!=-333),!p0) && j < len && c != '\0' - // && (!parms.collapse_result || j == 0 || target[j-1] != - // c)){ - if (k && !p0 && j < len && c != '\0' && - (1 || j == 0 || target[j - 1] != c)) { + if (k && !p0 && target.size() < len && c != '\0' && + (1 || target.empty() || target[target.size()-1] != c)) { /** condense only double letters **/ - target[j] = c; + target.push_back(c); /// printf("\n setting \n"); - j++; } i++; @@ -279,7 +270,5 @@ int phonet(const char* inword, char* target, int len, phonetable& parms) { } } /** end of while ((c = word[i]) != '\0') **/ - target[j] = '\0'; - return (j); - + return target; } /** end of function "phonet" **/ |