From 240fcee90ead3ab8207cc54f7e7c10303c6e1018 Mon Sep 17 00:00:00 2001 From: Pavel Tyunin Date: Tue, 6 Oct 2020 22:34:52 +0300 Subject: [PATCH] Move wxIsUTF8Prefix() to convauto.cpp --- include/wx/strconv.h | 2 -- src/common/convauto.cpp | 21 +++++++++++++++++++++ src/common/strconv.cpp | 20 -------------------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/include/wx/strconv.h b/include/wx/strconv.h index 21c5f136b1..c1b070d36a 100644 --- a/include/wx/strconv.h +++ b/include/wx/strconv.h @@ -387,8 +387,6 @@ private: int m_options; }; -bool wxIsUTF8Prefix(const char *src, size_t len); - // ---------------------------------------------------------------------------- // wxMBConvUTF16Base: for both LE and BE variants // ---------------------------------------------------------------------------- diff --git a/src/common/convauto.cpp b/src/common/convauto.cpp index 840841f5b6..9f3be27802 100644 --- a/src/common/convauto.cpp +++ b/src/common/convauto.cpp @@ -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 diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index d09b5ff2a4..23c2b0a545 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -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 // ============================================================================