// Search 'substr' in 'instr' and add a prefix to the 'substr'. // Returns TRUE on success, and the 'outstr' holds the result string. // Returns FALSE if 'substr' does not appear in 'instr'. // static BOOL AddNamespacePrefix( /* [in] */ char *instr, /* [in] */ const char *substr, /* [out] */ char * outstr) { assert(instr != NULL); assert(substr != NULL); assert(outstr != NULL); int nsubstr = strlen(substr); if (nsubstr == 0) { return FALSE; } char * p = strstr(instr, substr); if (p == NULL) { return FALSE; } int n = strlen(instr); char * instrend = instr + n; unsigned int neplstr = strlen(s_replstr); char * q; char * pbuf = outstr; pbuf[0] = 0; while (p != NULL) { if (p > instr) { n = p - instr; strncat(pbuf, instr, n); pbuf += n; } q = p + nsubstr; if (((p != instr && IsWordBoundary(*(p - 1))) || (p == instr)) && (((q < instrend) && IsWordBoundary(*q)) || (q == instrend))) { strcat(pbuf, s_replstr); pbuf += neplstr; } strncat(pbuf, p, nsubstr); pbuf += nsubstr; instr = p + nsubstr; p = strstr(instr, substr); } if (instr != instrend) { strcat(pbuf, instr); } return TRUE; }
// this function looks for portions of the text that can be skipped because it // begins with a word to ignore or one of its synonyms. // note that more than one item could match, all should be tried vector<size_t> CWord_substitution :: GetMatchLens(const string& text, const string& pattern, char prev_char) const { vector<size_t> match_lens; size_t len; if (!IsSetWord()) { // doesn't make sense } else if (!NStr::StartsWith(pattern, GetWord(), GetCase_sensitive() ? NStr::eCase : NStr::eNocase)) { // no match } else if (IsSetSynonyms()) { ITERATE(CWord_substitution::TSynonyms, syn, GetSynonyms()) { len = (*syn).length(); if (NStr::StartsWith(text, *syn, GetCase_sensitive() ? NStr::eCase : NStr::eNocase) && (!IsSetWhole_word() || (IsWordBoundary(prev_char) && IsWordBoundary(text.c_str()[len])))) { // text matches synonym match_lens.push_back(len); } } } else {