Move wxIsUTF8Prefix() to convauto.cpp
This commit is contained in:
@@ -387,8 +387,6 @@ private:
|
||||
int m_options;
|
||||
};
|
||||
|
||||
bool wxIsUTF8Prefix(const char *src, size_t len);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxMBConvUTF16Base: for both LE and BE variants
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@@ -23,6 +23,7 @@
|
||||
#endif
|
||||
|
||||
#include "wx/convauto.h"
|
||||
#include "wx/private/unicode.h"
|
||||
|
||||
// we use latin1 by default as it seems the least bad choice: the files we need
|
||||
// to detect input of don't always come from the user system (they are often
|
||||
@@ -266,6 +267,26 @@ bool wxConvAuto::InitFromInput(const char *src, size_t len)
|
||||
return true;
|
||||
}
|
||||
|
||||
// checks if the input can be the beginning of a valid UTF-8 string
|
||||
static bool wxIsUTF8Prefix(const char *src, size_t len)
|
||||
{
|
||||
unsigned char l;
|
||||
for ( size_t i = 0; i < len; ++i )
|
||||
{
|
||||
l = tableUtf8Lengths[(unsigned char)src[i]];
|
||||
if ( !l )
|
||||
return false; // invalid leading byte
|
||||
while ( --l )
|
||||
{
|
||||
if ( ++i == len )
|
||||
return true; // truncated sequence
|
||||
if ( (src[i] & 0xC0) != 0x80 )
|
||||
return false; // invalid continuation byte
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t
|
||||
wxConvAuto::ToWChar(wchar_t *dst, size_t dstLen,
|
||||
const char *src, size_t srcLen) const
|
||||
|
@@ -1447,26 +1447,6 @@ size_t wxMBConvUTF8::FromWChar(char *buf, size_t n,
|
||||
return len;
|
||||
}
|
||||
|
||||
// checks if the input can be the beginning of a valid UTF-8 string
|
||||
bool wxIsUTF8Prefix(const char *src, size_t len)
|
||||
{
|
||||
unsigned char l;
|
||||
for ( size_t i = 0; i < len; ++i )
|
||||
{
|
||||
l = tableUtf8Lengths[(unsigned char)src[i]];
|
||||
if ( !l )
|
||||
return false; // invalid leading byte
|
||||
while ( --l )
|
||||
{
|
||||
if ( ++i == len )
|
||||
return true; // truncated sequence
|
||||
if ( (src[i] & 0xC0) != 0x80 )
|
||||
return false; // invalid continuation byte
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// UTF-16
|
||||
// ============================================================================
|
||||
|
Reference in New Issue
Block a user