Changeset - 47e44a081a36
[Not reviewed]
0 1 0
HanzZ - 13 years ago 2012-08-01 21:37:50
hanzz.k@gmail.com
Fixed ordering in utf8 header
1 file changed with 29 insertions and 29 deletions:
0 comments (0 inline, 0 general)
src/utf8/checked.h
Show inline comments
 
@@ -56,24 +56,53 @@ namespace utf8
 
        invalid_utf16 (uint16_t u) : u16(u) {}
 
        virtual const char* what() const throw() { return "Invalid UTF-16"; }
 
        uint16_t utf16_word() const {return u16;}
 
    };
 

	
 
    class not_enough_room : public std::exception {
 
    public:
 
        virtual const char* what() const throw() { return "Not enough space"; }
 
    };
 

	
 
    /// The library API - functions intended to be called by the users
 

	
 
    template <typename octet_iterator>
 
    octet_iterator append(uint32_t cp, octet_iterator result)
 
    {
 
        if (!internal::is_code_point_valid(cp))
 
            throw invalid_code_point(cp);
 

	
 
        if (cp < 0x80)                        // one octet
 
            *(result++) = static_cast<uint8_t>(cp);
 
        else if (cp < 0x800) {                // two octets
 
            *(result++) = static_cast<uint8_t>((cp >> 6)            | 0xc0);
 
            *(result++) = static_cast<uint8_t>((cp & 0x3f)          | 0x80);
 
        }
 
        else if (cp < 0x10000) {              // three octets
 
            *(result++) = static_cast<uint8_t>((cp >> 12)           | 0xe0);
 
            *(result++) = static_cast<uint8_t>(((cp >> 6) & 0x3f)     | 0x80);
 
            *(result++) = static_cast<uint8_t>((cp & 0x3f)          | 0x80);
 
        }
 
        else if (cp <= internal::CODE_POINT_MAX) {      // four octets
 
            *(result++) = static_cast<uint8_t>((cp >> 18)           | 0xf0);
 
            *(result++) = static_cast<uint8_t>(((cp >> 12)& 0x3f)     | 0x80);
 
            *(result++) = static_cast<uint8_t>(((cp >> 6) & 0x3f)     | 0x80);
 
            *(result++) = static_cast<uint8_t>((cp & 0x3f)          | 0x80);
 
        }
 
        else
 
            throw invalid_code_point(cp);
 

	
 
        return result;
 
    }
 

	
 
    template <typename octet_iterator, typename output_iterator>
 
    output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out, uint32_t replacement)
 
    {
 
        while (start != end) {
 
            octet_iterator sequence_start = start;
 
            internal::utf_error err_code = internal::validate_next(start, end);
 
            switch (err_code) {
 
                case internal::OK :
 
                    for (octet_iterator it = sequence_start; it != start; ++it)
 
                        *out++ = *it;
 
                    break;
 
                case internal::NOT_ENOUGH_ROOM:
 
@@ -94,53 +123,24 @@ namespace utf8
 
            }
 
        }
 
        return out;
 
    }
 

	
 
    template <typename octet_iterator, typename output_iterator>
 
    inline output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out)
 
    {
 
        static const uint32_t replacement_marker = internal::mask16(0xfffd);
 
        return replace_invalid(start, end, out, replacement_marker);
 
    }
 

	
 
    template <typename octet_iterator>
 
    octet_iterator append(uint32_t cp, octet_iterator result)
 
    {
 
        if (!internal::is_code_point_valid(cp))
 
            throw invalid_code_point(cp);
 

	
 
        if (cp < 0x80)                        // one octet
 
            *(result++) = static_cast<uint8_t>(cp);
 
        else if (cp < 0x800) {                // two octets
 
            *(result++) = static_cast<uint8_t>((cp >> 6)            | 0xc0);
 
            *(result++) = static_cast<uint8_t>((cp & 0x3f)          | 0x80);
 
        }
 
        else if (cp < 0x10000) {              // three octets
 
            *(result++) = static_cast<uint8_t>((cp >> 12)           | 0xe0);
 
            *(result++) = static_cast<uint8_t>(((cp >> 6) & 0x3f)     | 0x80);
 
            *(result++) = static_cast<uint8_t>((cp & 0x3f)          | 0x80);
 
        }
 
        else if (cp <= internal::CODE_POINT_MAX) {      // four octets
 
            *(result++) = static_cast<uint8_t>((cp >> 18)           | 0xf0);
 
            *(result++) = static_cast<uint8_t>(((cp >> 12)& 0x3f)     | 0x80);
 
            *(result++) = static_cast<uint8_t>(((cp >> 6) & 0x3f)     | 0x80);
 
            *(result++) = static_cast<uint8_t>((cp & 0x3f)          | 0x80);
 
        }
 
        else
 
            throw invalid_code_point(cp);
 

	
 
        return result;
 
    }
 

	
 
    template <typename octet_iterator>
 
    uint32_t next(octet_iterator& it, octet_iterator end)
 
    {
 
        uint32_t cp = 0;
 
        internal::utf_error err_code = internal::validate_next(it, end, &cp);
 
        switch (err_code) {
 
            case internal::OK :
 
                break;
 
            case internal::NOT_ENOUGH_ROOM :
 
                throw not_enough_room();
 
            case internal::INVALID_LEAD :
 
            case internal::INCOMPLETE_SEQUENCE :
0 comments (0 inline, 0 general)