summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/string_util.cc32
-rw-r--r--base/string_util.h5
2 files changed, 8 insertions, 29 deletions
diff --git a/base/string_util.cc b/base/string_util.cc
index d84fadb..4ba8c4b 100644
--- a/base/string_util.cc
+++ b/base/string_util.cc
@@ -450,16 +450,6 @@ std::wstring ASCIIToWide(const std::string& ascii) {
return std::wstring(ascii.begin(), ascii.end());
}
-std::string UTF16ToASCII(const string16& utf16) {
- DCHECK(IsStringASCII(utf16));
- return std::string(utf16.begin(), utf16.end());
-}
-
-string16 ASCIIToUTF16(const std::string& ascii) {
- DCHECK(IsStringASCII(ascii));
- return string16(ascii.begin(), ascii.end());
-}
-
// Latin1 is just the low range of Unicode, so we can copy directly to convert.
bool WideToLatin1(const std::wstring& wide, std::string* latin1) {
std::string output;
@@ -482,28 +472,20 @@ bool IsString8Bit(const std::wstring& str) {
return true;
}
-template<class STR>
-static bool DoIsStringASCII(const STR& str) {
+bool IsStringASCII(const std::wstring& str) {
for (size_t i = 0; i < str.length(); i++) {
- typename ToUnsigned<typename STR::value_type>::Unsigned c = str[i];
- if (c > 0x7F)
+ if (str[i] > 0x7F)
return false;
}
return true;
}
-bool IsStringASCII(const std::wstring& str) {
- return DoIsStringASCII(str);
-}
-
-#if !defined(WCHAR_T_IS_UTF16)
-bool IsStringASCII(const string16& str) {
- return DoIsStringASCII(str);
-}
-#endif
-
bool IsStringASCII(const std::string& str) {
- return DoIsStringASCII(str);
+ for (size_t i = 0; i < str.length(); i++) {
+ if (static_cast<unsigned char>(str[i]) > 0x7F)
+ return false;
+ }
+ return true;
}
// Helper functions that determine whether the given character begins a
diff --git a/base/string_util.h b/base/string_util.h
index 93b4898..500a114 100644
--- a/base/string_util.h
+++ b/base/string_util.h
@@ -156,11 +156,9 @@ TrimPositions TrimWhitespace(const std::string& input,
std::wstring CollapseWhitespace(const std::wstring& text,
bool trim_sequences_with_line_breaks);
-// These convert between ASCII (7-bit) and Wide/UTF16 strings.
+// These convert between ASCII (7-bit) and UTF16 strings.
std::string WideToASCII(const std::wstring& wide);
std::wstring ASCIIToWide(const std::string& ascii);
-std::string UTF16ToASCII(const string16& utf16);
-string16 ASCIIToUTF16(const std::string& ascii);
// These convert between UTF-8, -16, and -32 strings. They are potentially slow,
// so avoid unnecessary conversions. The low-level versions return a boolean
@@ -237,7 +235,6 @@ bool IsStringUTF8(const std::string& str);
bool IsStringWideUTF8(const std::wstring& str);
bool IsStringASCII(const std::wstring& str);
bool IsStringASCII(const std::string& str);
-bool IsStringASCII(const string16& str);
// ASCII-specific tolower. The standard library's tolower is locale sensitive,
// so we don't want to use it here.