Esempio n. 1
0
static void replaceCharsetInMediaType(String& mediaType, const String& charsetValue)
{
    unsigned int pos = 0, len = 0;

    findCharsetInMediaType(mediaType, pos, len);

    if (!len) {
        // When no charset found, do nothing.
        return;
    }

    // Found at least one existing charset, replace all occurrences with new charset.
    while (len) {
        mediaType.replace(pos, len, charsetValue);
        unsigned int start = pos + charsetValue.length();
        findCharsetInMediaType(mediaType, pos, len, start);
    }
}
Esempio n. 2
0
static void setCharsetInMediaType(String& mediaType, const String& charsetValue)
{
    unsigned int pos = 0, len = 0;

    findCharsetInMediaType(mediaType, pos, len);

    if (!len) {
        // When no charset found, append new charset.
        mediaType.stripWhiteSpace();
        if (mediaType[mediaType.length() - 1] != ';')
            mediaType.append(";");
        mediaType.append(" charset=");
        mediaType.append(charsetValue);
    } else {
        // Found at least one existing charset, replace all occurrences with new charset.
        while (len) {
            mediaType.replace(pos, len, charsetValue);
            unsigned int start = pos + charsetValue.length();
            findCharsetInMediaType(mediaType, pos, len, start);
        }
    }
}
Esempio n. 3
0
String extractCharsetFromMediaType(const String& mediaType)
{
    unsigned int pos, len;
    findCharsetInMediaType(mediaType, pos, len);
    return mediaType.substring(pos, len);
}