MCPcopy Create free account
hub / github.com/dirkvranckaert/AndroidDecompiler / Utf16LengthFromUtf8

Method Utf16LengthFromUtf8

astyle/src/astyle_main.cpp:2206–2229  ·  view source on GitHub ↗

Adapted from SciTE UniConversion.cxx. Copyright 1998-2001 by Neil Hodgson Modified for Artistic Style by Jim Pattee. Compute the length of an output utf-16 file given a utf-8 file. Return value is the size in BYTES (not wchar_t).

Source from the content-addressed store, hash-verified

2204// Compute the length of an output utf-16 file given a utf-8 file.
2205// Return value is the size in BYTES (not wchar_t).
2206size_t ASConsole::Utf16LengthFromUtf8(const char* data, size_t len) const
2207{
2208 size_t ulen = 0;
2209 size_t charLen;
2210 for (size_t i = 0; i < len;)
2211 {
2212 unsigned char ch = static_cast<unsigned char>(data[i]);
2213 if (ch < 0x80)
2214 charLen = 1;
2215 else if (ch < 0x80 + 0x40 + 0x20)
2216 charLen = 2;
2217 else if (ch < 0x80 + 0x40 + 0x20 + 0x10)
2218 charLen = 3;
2219 else
2220 {
2221 charLen = 4;
2222 ulen++;
2223 }
2224 i += charLen;
2225 ulen++;
2226 }
2227 // return value is the length in bytes (not wchar_t)
2228 return ulen * 2;
2229}
2230
2231// Adapted from SciTE Utf8_16.cxx.
2232// Copyright (C) 2002 Scott Kirkwood.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected