| 114 | |
| 115 | template <typename octet_difference_type> |
| 116 | inline bool is_overlong_sequence(uint32_t cp, octet_difference_type length) |
| 117 | { |
| 118 | if (cp < 0x80) { |
| 119 | if (length != 1) |
| 120 | return true; |
| 121 | } |
| 122 | else if (cp < 0x800) { |
| 123 | if (length != 2) |
| 124 | return true; |
| 125 | } |
| 126 | else if (cp < 0x10000) { |
| 127 | if (length != 3) |
| 128 | return true; |
| 129 | } |
| 130 | |
| 131 | return false; |
| 132 | } |
| 133 | |
| 134 | enum utf_error {UTF8_OK, NOT_ENOUGH_ROOM, INVALID_LEAD, INCOMPLETE_SEQUENCE, OVERLONG_SEQUENCE, INVALID_CODE_POINT}; |
| 135 |