Logo Search packages:      
Sourcecode: jaula version File versions

void JAULA::Value_String::stringRepr ( std::ostream &  ostr,
std::string const &  str 
) [static]

Represents a string in JSON Notation.

Parameters:
ostr stream where the representation is to be performed.
str String to represent
Description
Represents a string in JSON notation, surrounding it with quotes and changing all the non-printable symbols by its control codes or unicode values.

Definition at line 92 of file jaula_value_string.cc.

Referenced by repr().

  {
    ostr << '"';
    for (std::string::size_type i = 0; (i != str.size()); i++)
    {
      if (str[i] == '"')
        ostr << '\\' << '"';
      else if (str[i] == '\\')
        ostr << '\\' << '\\';
      else if (str[i] == '/')
        ostr << '\\' << '/';
      else if (str[i] == '\b')
        ostr << '\\' << 'b';
      else if (str[i] == '\f')
        ostr << '\\' << 'f';
      else if (str[i] == '\n')
        ostr << '\\' << 'n';
      else if (str[i] == '\r')
        ostr << '\\' << 'r';
      else if (str[i] == '\t')
        ostr << '\\' << 't';
      else if (str[i] == ' ')
        ostr << ' ';
      else if (isprint(str[i]))
        ostr << str[i];
      else
      {
        std::ostringstream  aux;
        int val = static_cast<int>(str[i]) & 0x00ff;
        aux << std::hex << val;
        ostr << '\\' << 'u';
        for (std::string::size_type j = 0; ((j + aux.str().size()) < 4); j++)
          ostr << '0';
        ostr << aux.str();
      }
    }
    ostr << '"';
  }


Generated by  Doxygen 1.6.0   Back to index