-----------------------------------------------------------------------------
| 195 | |
| 196 | //----------------------------------------------------------------------------- |
| 197 | U32 convertUTF16toUTF8N( const UTF16 *unistring, UTF8 *outbuffer, U32 len) |
| 198 | { |
| 199 | AssertFatal(len >= 1, "Buffer for unicode conversion must be large enough to hold at least the null terminator."); |
| 200 | PROFILE_START(convertUTF16toUTF8); |
| 201 | U32 walked, nCodeunits, codeunitLen; |
| 202 | UTF32 middleman; |
| 203 | |
| 204 | nCodeunits=0; |
| 205 | while( *unistring != '\0' && nCodeunits + 3 < len ) |
| 206 | { |
| 207 | walked = 1; |
| 208 | middleman = oneUTF16toUTF32(unistring,&walked); |
| 209 | codeunitLen = oneUTF32toUTF8(middleman, &outbuffer[nCodeunits]); |
| 210 | unistring += walked; |
| 211 | nCodeunits += codeunitLen; |
| 212 | } |
| 213 | |
| 214 | nCodeunits = getMin(nCodeunits,len - 1); |
| 215 | outbuffer[nCodeunits] = '\0'; |
| 216 | |
| 217 | PROFILE_END(); |
| 218 | return nCodeunits; |
| 219 | } |
| 220 | |
| 221 | U32 convertUTF16toUTF8DoubleNULL( const UTF16 *unistring, UTF8 *outbuffer, U32 len) |
| 222 | { |
no test coverage detected