std::string AlibabaCloud::PDS::XmlEscape()

in sdk/src/utils/Utils.cc [169:206]


std::string AlibabaCloud::PDS::XmlEscape(const std::string& value)
{
    struct Entity {
        const char* pattern;
        char value;
    };

    static const Entity entities[] = {
        { """, '\"' },
        { "&",  '&'  },
        { "'", '\'' },
        { "&lt;",	'<'  },
        { "&gt;",	'>'  },
        { "&#13;",	'\r' }
    };

    if (value.empty()) {
        return value;
    }

    std::stringstream ss;
    for (size_t i = 0; i < value.size(); i++) {
        bool flag = false;
        for (size_t j = 0; j < (sizeof(entities)/sizeof(entities[0])); j++) {
            if (value[i] == entities[j].value) {
                flag = true;
                ss << entities[j].pattern;
                break;
            }
        }

        if (!flag) {
            ss << value[i];
        }
    }

    return ss.str();
}