示例#1
0
void xml_handle_entities(ustring & line, vector < size_t > *positions)
/*
  Changes the < and the > in the text to the xml entities &lt; and &gt
  Changes the ampersand (&) to &amp;
  Any positions affected by this will be adjusted.
*/
{
  size_t offposition;
  // Deal with &. This one is done first, 
  // else the ampersands inserted later will get changed too.
  offposition = line.find("&");
  while (offposition != string::npos) {
    line.replace(offposition, 1, "&amp;");
    if (positions)
      xml_positions_push_up(offposition, 4, *positions);
    // Do not repeat on the & just removed and inserted, but start searching after it.
    offposition = line.find("&", offposition + 3);
  }
  // Deal with <
  offposition = line.find("<");
  while (offposition != string::npos) {
    line.replace(offposition, 1, "&lt;");
    if (positions)
      xml_positions_push_up(offposition, 3, *positions);
    offposition = line.find("<", offposition);
  }
  // Deal with >
  offposition = line.find(">");
  while (offposition != string::npos) {
    line.replace(offposition, 1, "&gt;");
    if (positions)
      xml_positions_push_up(offposition, 3, *positions);
    offposition = line.find(">", offposition);
  }
}
示例#2
0
    ustringArrayT analyseWord (ustring str) {
        typedef bool (*_TrivialPointerToFunctions_) (ustring);

        ustringArrayT res(3);
        _TrivialPointerToFunctions_ testFuncs[3] =
            { isConsonant, isVowel, isConsonant };

        // First part: Consonant 1
        // Second part: Vowel
        // Third part: Consonant 2

        for (int part = 0; part < 3; part++) {
            res[part] = "";
            // This is safe due to short-circuit logic
            while (str.length () > 0 && testFuncs[part] (_(str[0]))) {
                res[part] += _(str[0]);
                str.replace (0, 1, "");
            }
        }

        // Special case: "qu" and "gi" are considered consonants
        if (analyseWordCheckSpecialConsonants (res, "qu") ||
            analyseWordCheckSpecialConsonants (res, "gi")) {
            res[0] += _(res[1][0]);
            res[1] = res[1].replace (0, 1, "");
        }

        return res;
    }
示例#3
0
  ustring replace(ustring source, ustring fromStr, ustring toStr, int offset, int times)
  {
    int total = 0;
    ustring::size_type pos=offset;
    while ( ( (pos = source.find(fromStr, pos)) < Glib::ustring::npos) && ( (times==0) || (total++<times) ) )
      {
	source.replace(pos, fromStr.length(), toStr);
	pos+=toStr.size();
      }
    return source;
  }
示例#4
0
bool replace_text(ustring & line, const ustring & look_for, const ustring & replace_with)
// Replaces some text. Returns true if any replacement was done.
{
  bool replacements_done = false;
  size_t offposition = line.find (look_for);
  while (offposition != string::npos) {
    line.replace (offposition, look_for.length (), replace_with);
    offposition = line.find (look_for, offposition + replace_with.length ());
    replacements_done = true;
  }
  return replacements_done;
}
示例#5
0
void xml_html_insert_emphasis(ustring & line, vector < size_t > &positions, vector < size_t > &lengths)
// This inserts the <b> tag to get the text bold.
{
  for (unsigned int i = 0; i < positions.size(); i++) {
    // Text to insert to highlight it.
    ustring taggedtext = "<b>" + line.substr(positions[i], lengths[i]) + "</b>";
    // Insert tag.
    line.replace(positions[i], lengths[i], taggedtext);
    // Push any following positions up.
    for (unsigned int i2 = i + 1; i2 < positions.size(); i2++) {
      positions[i2] = positions[i2] + 7;
    }
  }
}
示例#6
0
bool replace_text_between(ustring & line, const ustring & start, const ustring & end, const ustring & replacement)
// Replaces text that starts with "start" and ends with "end" with "replacement".
// Returns true if replacement was done.
{
  bool replacements_done = false;
  size_t beginpos = line.find(start);
  size_t endpos = line.find(end);
  while ((beginpos != string::npos) && (endpos != string::npos) && (endpos > beginpos)) {
    line.replace(beginpos, endpos - beginpos + end.length(), replacement);
    beginpos = line.find(start, beginpos + replacement.length());
    endpos = line.find(end, beginpos + replacement.length());
    replacements_done = true;
  }
  return replacements_done;
}
示例#7
0
    InputMethodT makeIMFromString (ustring imStr) {
        InputMethodT im;
        _size_t_ eolPos;
        ustring transPortion;
        ustring specialToken = (imStr.find (" -> ") != ustring::npos) ?
            _(" -> ") : _(" ");

        while (imStr.length () > 1) {
            eolPos = imStr.find ("\n");
            transPortion = imStr.substr (0, eolPos);
            imStr = imStr.replace (0, eolPos + 1, "");
            im = addTransformation
                (im, transPortion.replace (1, specialToken.length (), ""));
        }
        return standardizeIM (im);
    }
示例#8
0
  ustring replace(ustring source, std::map<ustring,ustring>strMap, int offset, int times)
  {
    int total = 0;
    ustring::size_type pos;

    for (std::map<ustring, ustring>::iterator i=strMap.begin(); i!=strMap.end(); ++i)
      {
	ustring fromStr = i->first;
	ustring toStr = i->second;
	pos=offset;
	while ( (pos = source.find(fromStr, pos)) < Glib::ustring::npos)
	  {
	    if ( (times!=0) && (total++>=times) )
	      return source;	// Don't work anymore

	    source.replace(pos, fromStr.length(), toStr);
	    pos+=toStr.size();
	  }
      }
    return source;
  }
示例#9
0
 ustring removeMarkFromWord (ustring word, _size_t_ pos) {
     ustring ch = _(word[pos]);
     return word.replace (pos, 1, removeMarkFromChar (ch));
 }