Exemplo n.º 1
0
// How many char objects can I process to get <= max_limit
// wchar_t objects?
int utf8_codecvt_facet::do_length(
    std::mbstate_t &,
    const char * from,
    const char * from_end,
    std::size_t max_limit
) const
{
    // RG - this code is confusing!  I need a better way to express it.
    // and test cases.

    // Invariants:
    // 1) last_octet_count has the size of the last measured character
    // 2) char_count holds the number of characters shown to fit
    // within the bounds so far (no greater than max_limit)
    // 3) from_next points to the octet 'last_octet_count' before the
    // last measured character.
    int last_octet_count=0;
    std::size_t char_count = 0;
    const char* from_next = from;
    // Use "<" because the buffer may represent incomplete characters
    while (from_next+last_octet_count <= from_end && char_count <= max_limit) {
        from_next += last_octet_count;
        last_octet_count = (get_octet_count(*from_next));
        ++char_count;
    }
    return from_next-from_end;
}
Exemplo n.º 2
0
 // continuing octets = octets except for the leading octet
 static unsigned int get_cont_octet_count(unsigned char lead_octet) {
     return get_octet_count(lead_octet) - 1;
 }