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

Method detectEncoding

astyle/src/astyle_main.cpp:391–405  ·  view source on GitHub ↗

check files for 16 or 32 bit encoding the file must have a Byte Order Mark (BOM) NOTE: some string functions don't work with NULLs (e.g. length())

Source from the content-addressed store, hash-verified

389// the file must have a Byte Order Mark (BOM)
390// NOTE: some string functions don't work with NULLs (e.g. length())
391FileEncoding ASConsole::detectEncoding(const char* data, size_t dataSize) const
392{
393 FileEncoding encoding = ENCODING_8BIT;
394
395 if (dataSize >= 4 && memcmp(data, "\x00\x00\xFE\xFF", 4) == 0)
396 encoding = UTF_32BE;
397 else if (dataSize >= 4 && memcmp(data, "\xFF\xFE\x00\x00", 4) == 0)
398 encoding = UTF_32LE;
399 else if (dataSize >= 2 && memcmp(data, "\xFE\xFF", 2) == 0)
400 encoding = UTF_16BE;
401 else if (dataSize >= 2 && memcmp(data, "\xFF\xFE", 2) == 0)
402 encoding = UTF_16LE;
403
404 return encoding;
405}
406
407// error exit without a message
408void ASConsole::error() const

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected