From 7f18e1faabd18381cf4a8ab85ff24bb6b9b7f89d Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Mon, 11 Mar 2013 21:31:44 +0100 Subject: [PATCH] Add UTF8StringNonASCIICount --- util/text/utf8.cpp | 11 ++++++++--- util/text/utf8.h | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/util/text/utf8.cpp b/util/text/utf8.cpp index 10b239ea52..e77eb076bb 100644 --- a/util/text/utf8.cpp +++ b/util/text/utf8.cpp @@ -394,12 +394,17 @@ int u8_is_locale_utf8(const char *locale) return 0; } -bool UTF8StringHasNonASCII(const char *utf8string) { +int UTF8StringNonASCIICount(const char *utf8string) { UTF8 utf(utf8string); + int count = 0; while (!utf.end()) { int c = utf.next(); if (c > 127) - return true; + ++count; } - return false; + return count; +} + +bool UTF8StringHasNonASCII(const char *utf8string) { + return UTF8StringNonASCIICount(utf8string) > 0; } \ No newline at end of file diff --git a/util/text/utf8.h b/util/text/utf8.h index 84c2ae8c97..bd320979f8 100644 --- a/util/text/utf8.h +++ b/util/text/utf8.h @@ -35,4 +35,6 @@ private: int index_; }; +int UTF8StringNonASCIICount(const char *utf8string); + bool UTF8StringHasNonASCII(const char *utf8string); \ No newline at end of file