QUtil::analyze_encoding(std::string const& val,
                        bool& has_8bit_chars,
                        bool& is_valid_utf8,
                        bool& is_utf16)
{
    has_8bit_chars = is_utf16 = is_valid_utf8 = false;
    if (QUtil::is_utf16(val))
    {
        has_8bit_chars = true;
        is_utf16 = true;
        return;
    }
    size_t len = val.length();
    bool any_errors = false;
    for (size_t i = 0; i < len; ++i)
    {
        bool error = false;
        unsigned long codepoint = get_next_utf8_codepoint(val, i, error);
        if (error)
        {
            any_errors = true;
        }
        if (codepoint >= 128)
        {
            has_8bit_chars = true;
        }
    }
    if (has_8bit_chars && (! any_errors))
    {
        is_valid_utf8 = true;
    }
}
QUtil::analyze_encoding(std::string const& val,
                        bool& has_8bit_chars,
                        bool& is_valid_utf8,
                        bool& is_utf16)
{
    has_8bit_chars = is_utf16 = is_valid_utf8 = false;
    if (QUtil::is_utf16(val))
    {
        has_8bit_chars = true;
        is_utf16 = true;
        return;
    }
    size_t len = val.length();
    bool any_errors = false;
    for (size_t i = 0; i < len; ++i)
    {
        bool error = false;
        unsigned long codepoint = get_next_utf8_codepoint(val, i, error);
        if (error)
        {
            any_errors = true;
        }
        if (codepoint >= 128)
        {
            has_8bit_chars = true;
        }
    }
    if (has_8bit_chars && (! any_errors))
    {
        is_valid_utf8 = true;
    }
}