Example #1
0
void unescape(std::string &str, char toUnescape)
{

  size_t pos;
  string escaped = escapeCharacter(toUnescape);
  while ((pos = str.find(escaped)) != string::npos)
  {
    str = str.replace(pos, escaped.size(), string(1, toUnescape));
  }

}
Example #2
0
void jsfGetEscapedString(JsVar *var, vcbprintf_callback user_callback, void *user_data) {
  user_callback("\"",user_data);
  JsvStringIterator it;
  jsvStringIteratorNew(&it, var, 0);
  while (jsvStringIteratorHasChar(&it)) {
    char ch = jsvStringIteratorGetChar(&it);
    user_callback(escapeCharacter(ch), user_data);
    jsvStringIteratorNext(&it);
  }
  jsvStringIteratorFree(&it);
  user_callback("\"",user_data);
}
Example #3
0
void escape(std::string &str, char toEscape)
{
  //cannot escape string that contains the escaped sequence already because the mapping is not one-to-one anymore
  string unescaped = str;
  unescape(unescaped, toEscape);
  if (unescaped != str)
  {
    throw exception();
  }
  //
  size_t pos;
  string escaped = escapeCharacter(toEscape);
  while ((pos = str.find(toEscape)) != string::npos)
  {
    str = str.replace(pos, 1, escaped);
  }

}