28#ifndef UTF8_FOR_CPP_CORE_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
29#define UTF8_FOR_CPP_CORE_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
37#if !defined UTF_CPP_CPLUSPLUS
38 #define UTF_CPP_CPLUSPLUS __cplusplus
41#if UTF_CPP_CPLUSPLUS >= 201103L
42 #define UTF_CPP_OVERRIDE override
43 #define UTF_CPP_NOEXCEPT noexcept
45 #define UTF_CPP_OVERRIDE
46 #define UTF_CPP_NOEXCEPT throw()
75 template<
typename octet_type>
78 return static_cast<uint8_t>(0xff & oc);
80 template<
typename u16_type>
83 return static_cast<uint16_t>(0xffff & oc);
85 template<
typename octet_type>
91 template <
typename u16>
97 template <
typename u16>
103 template <
typename u16>
109 template <
typename u32>
115 template <
typename octet_iterator>
116 inline typename std::iterator_traits<octet_iterator>::difference_type
122 else if ((lead >> 5) == 0x6)
124 else if ((lead >> 4) == 0xe)
126 else if ((lead >> 3) == 0x1e)
132 template <
typename octet_difference_type>
139 else if (cp < 0x800) {
143 else if (cp < 0x10000) {
154 template <
typename octet_iterator>
166 #define UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(IT, END) {utf_error ret = increase_safely(IT, END); if (ret != UTF8_OK) return ret;}
169 template <
typename octet_iterator>
180 template <
typename octet_iterator>
190 code_point = ((code_point << 6) & 0x7ff) + ((*it) & 0x3f);
195 template <
typename octet_iterator>
209 code_point += (*it) & 0x3f;
214 template <
typename octet_iterator>
232 code_point += (*it) & 0x3f;
237 #undef UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR
239 template <
typename octet_iterator>
247 octet_iterator original_it = it;
251 typedef typename std::iterator_traits<octet_iterator>::difference_type octet_difference_type;
294 template <
typename octet_iterator>
303 template <
typename octet_iterator,
typename octet_type>
306 *(result++) =
static_cast<octet_type
>(cp);
307 else if (cp < 0x800) {
308 *(result++) =
static_cast<octet_type
>((cp >> 6) | 0xc0);
309 *(result++) =
static_cast<octet_type
>((cp & 0x3f) | 0x80);
311 else if (cp < 0x10000) {
312 *(result++) =
static_cast<octet_type
>((cp >> 12) | 0xe0);
313 *(result++) =
static_cast<octet_type
>(((cp >> 6) & 0x3f) | 0x80);
314 *(result++) =
static_cast<octet_type
>((cp & 0x3f) | 0x80);
317 *(result++) =
static_cast<octet_type
>((cp >> 18) | 0xf0);
318 *(result++) =
static_cast<octet_type
>(((cp >> 12) & 0x3f)| 0x80);
319 *(result++) =
static_cast<octet_type
>(((cp >> 6) & 0x3f) | 0x80);
320 *(result++) =
static_cast<octet_type
>((cp & 0x3f) | 0x80);
334 template<
typename container_type>
335 std::back_insert_iterator<container_type>
append
336 (
uint32_t cp, std::back_insert_iterator<container_type> result) {
338 typename container_type::value_type>(cp, result);
344 template <
typename octet_iterator>
356 template <
typename octet_iterator>
359 octet_iterator result = start;
360 while (result != end) {
368 template <
typename octet_iterator>
369 inline bool is_valid(octet_iterator start, octet_iterator end)
374 template <
typename octet_iterator>
#define UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(IT, END)
Definition core.h:166
bool starts_with_bom(octet_iterator it, octet_iterator end)
Definition core.h:375
unsigned int uint32_t
Definition core.h:57
unsigned char uint8_t
Definition core.h:55
unsigned short uint16_t
Definition core.h:56
const uint8_t bom[]
The library API - functions intended to be called by the users.
Definition core.h:354
bool is_valid(octet_iterator start, octet_iterator end)
Definition core.h:369
octet_iterator find_invalid(octet_iterator start, octet_iterator end)
Definition core.h:357
const uint32_t CODE_POINT_MAX
Definition core.h:73
bool is_lead_surrogate(u16 cp)
Definition core.h:92
bool is_trail_surrogate(u16 cp)
Definition core.h:98
bool is_overlong_sequence(uint32_t cp, octet_difference_type length)
Definition core.h:133
bool is_surrogate(u16 cp)
Definition core.h:104
const uint32_t SURROGATE_OFFSET
Definition core.h:70
utf_error increase_safely(octet_iterator &it, octet_iterator end)
Helper for get_sequence_x.
Definition core.h:155
const uint16_t TRAIL_SURROGATE_MAX
Definition core.h:68
const uint16_t LEAD_OFFSET
Definition core.h:69
utf_error get_sequence_1(octet_iterator &it, octet_iterator end, uint32_t &code_point)
get_sequence_x functions decode utf-8 sequences of the length x
Definition core.h:170
const uint16_t TRAIL_SURROGATE_MIN
Definition core.h:67
bool is_code_point_valid(u32 cp)
Definition core.h:110
utf_error get_sequence_2(octet_iterator &it, octet_iterator end, uint32_t &code_point)
Definition core.h:181
utf_error
Definition core.h:151
@ INCOMPLETE_SEQUENCE
Definition core.h:151
@ INVALID_LEAD
Definition core.h:151
@ OVERLONG_SEQUENCE
Definition core.h:151
@ INVALID_CODE_POINT
Definition core.h:151
@ NOT_ENOUGH_ROOM
Definition core.h:151
@ UTF8_OK
Definition core.h:151
uint16_t mask16(u16_type oc)
Definition core.h:81
bool is_trail(octet_type oc)
Definition core.h:86
utf_error validate_next(octet_iterator &it, octet_iterator end, uint32_t &code_point)
Definition core.h:240
utf_error get_sequence_3(octet_iterator &it, octet_iterator end, uint32_t &code_point)
Definition core.h:196
const uint16_t LEAD_SURROGATE_MIN
Definition core.h:65
utf_error get_sequence_4(octet_iterator &it, octet_iterator end, uint32_t &code_point)
Definition core.h:215
std::iterator_traits< octet_iterator >::difference_type sequence_length(octet_iterator lead_it)
Definition core.h:117
uint8_t mask8(octet_type oc)
Definition core.h:76
const uint16_t LEAD_SURROGATE_MAX
Definition core.h:66
octet_iterator append(uint32_t cp, octet_iterator result)
Definition core.h:304