Moved utf8.h/cpp to namespace json::
This commit is contained in:
parent
1c2e479012
commit
d4c48ea269
@ -1,7 +1,8 @@
|
||||
#include "utf8.h"
|
||||
#include <assert.h>
|
||||
|
||||
int _utf8_retrieve_size(uint8_t firstByte) {
|
||||
namespace json {
|
||||
int utf8_retrieve_size(uint8_t firstByte) {
|
||||
if (!(firstByte & 0b10000000))
|
||||
return 1;
|
||||
uint8_t a = 0b11000000;
|
||||
@ -15,7 +16,7 @@ int _utf8_retrieve_size(uint8_t firstByte) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t _utf8_retrieve_character(int sz, size_t pos, const char *string) {
|
||||
int32_t utf8_retrieve_character(int sz, size_t pos, const char *string) {
|
||||
if (sz == 1)
|
||||
return (int32_t)string[pos];
|
||||
uint32_t v = ((uint8_t)string[pos]) & (0b01111111 >> sz);
|
||||
@ -34,9 +35,9 @@ int32_t _utf8_retrieve_character(int sz, size_t pos, const char *string) {
|
||||
|
||||
void utf8_string_iterat(int32_t &cp, size_t &adj, size_t pos, const char *string, size_t string_size) {
|
||||
if (pos >= string_size) {cp = -1; return;}
|
||||
adj = _utf8_retrieve_size((uint8_t)string[pos]);
|
||||
adj = utf8_retrieve_size((uint8_t)string[pos]);
|
||||
if (adj < 0 || pos + adj > string_size) {cp = -1; return;}
|
||||
if ((cp = _utf8_retrieve_character(adj, pos, string)) < 0) {cp = -1; return;}
|
||||
if ((cp = utf8_retrieve_character(adj, pos, string)) < 0) {cp = -1; return;}
|
||||
}
|
||||
|
||||
bool isUtf8String(const std::string &str) {
|
||||
@ -80,3 +81,4 @@ int codepoint_to_utf8(uint32_t cp, std::string &out) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,10 @@
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
int _utf8_retrieve_size(uint8_t firstByte);
|
||||
namespace json {
|
||||
int utf8_retrieve_size(uint8_t firstByte);
|
||||
|
||||
int32_t _utf8_retrieve_character(int sz, size_t pos, const char *string);
|
||||
int32_t utf8_retrieve_character(int sz, size_t pos, const char *string);
|
||||
|
||||
void utf8_string_iterat(int32_t &cp, size_t &adj, size_t pos, const char *string, size_t string_size);
|
||||
|
||||
@ -14,5 +15,6 @@ bool isUtf8String(const std::string& str);
|
||||
|
||||
/* Returns -1 if cp is not in 0-0x10FFFF range */
|
||||
int codepoint_to_utf8(uint32_t cp, std::string& out);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user