MCPcopy Create free account
hub / github.com/HaxeFoundation/hxcpp / from_utf8

Function from_utf8

include/hx/CFFIPrime.h:101–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99
100template<typename T>
101inline const T *from_utf8(const char *inStr,int len,hx::IStringAlloc *inAlloc)
102{
103 int n = len;
104 if (n<0)
105 while(inStr[n])
106 n++;
107
108 const unsigned char *str = (const unsigned char *)inStr;
109 const unsigned char *end = str + n;
110 int count = 0;
111 while(str<end)
112 {
113 int ch = decode_advance_utf8(str,end);
114 count++;
115 if (sizeof(T)==2 && ch>=0x10000)
116 count++;
117 }
118 T *result = (T*)inAlloc->allocBytes( sizeof(T)*(count+1) );
119 T *dest = result;
120 str = (const unsigned char *)inStr;
121 while(str<end)
122 {
123 int ch = decode_advance_utf8(str,end);
124 if (sizeof(T)==2 && ch>=0x10000)
125 {
126 int over = (ch-0x10000);
127 *dest++ = (over>>10) + 0xd800;
128 *dest++ = (over&0x3ff) + 0xdc00;
129 }
130 else
131 *dest++ = ch;
132 }
133 *dest++ = 0;
134
135 return result;
136}
137
138}
139

Callers

nothing calls this directly

Calls 2

decode_advance_utf8Function · 0.85
allocBytesMethod · 0.45

Tested by

no test coverage detected