src/main.cxx
std::string escape(const string& value) {
    std::string s(value);
    std::string out = "";
    out.reserve(s.size());
    for (size_t i = 0; i < s.size(); i++) {
        char c = s[i];
        if ((unsigned char)c < 31)
            continue;

        switch (c) {
            case '"' : out += "\\\""; break;
            case '\\': out += "\\\\"; break;
            case '\b': out += "\\b" ; break;
            case '\f': out += "\\f" ; break;
            case '\n': out += "\\n" ; break;
            case '\r': out += "\\r" ; break;
            case '\t': out += "\\t" ; break;
            // case '/' : out += "\\/" ; break; // Unnecessary?
            default:
                out += c;
                // TODO: do something with unicode?
        }
    }

    return out;
}
// deal with quotes etc in json
deal with quotes etc in json
deal with quotes etc in json
std::string escape(const string& value) {
    std::string s(value);
    std::string out = "";
    out.reserve(s.size());
    for (size_t i = 0; i < s.size(); i++) {
        char c = s[i];
        if ((unsigned char)c < 31)
            continue;
        switch (c) {
            case '"' : out += "\\\""; break;
            case '\\': out += "\\\\"; break;
            case '\b': out += "\\b" ; break;
            case '\f': out += "\\f" ; break;
            case '\n': out += "\\n" ; break;
            case '\r': out += "\\r" ; break;
            case '\t': out += "\\t" ; break;
            default:
                out += c;
        }
    }
    return out;
}
std :: string escape ( const string & value ) { std :: string s ( value ) ; std :: string out = " " ; out . reserve ( s . size ( ) ) ; for ( size_t i = 0 ; i < s . size ( ) ; i ++ ) { char c = s [ i ] ; if ( ( unsigned char ) c < 31 ) continue ; switch ( c ) { case ' ' : out += " \\ \" " ; break ; case ' \\ ' : out += " \\ \\ " ; break ; case ' \b ' : out += " \\ " ; break ; case ' \f ' : out += " \\ " ; break ; case ' \n ' : out += " \\ " ; break ; case ' \r ' : out += " \\ " ; break ; case ' \t ' : out += " \\ " ; break ; default : out += c ; } } return out ; }
deal with quotes etc in json
deal with quotes etc in json
// case '/' : out += "\\/" ; break; // Unnecessary? // TODO: do something with unicode?