Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(999)

Unified Diff: base/string_util.h

Issue 28227: Add ToUpperASCII and StringToUpperASCII. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Use 2 instead of 1 in unit test to avoid confusion with small ell Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/string_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/string_util.h
===================================================================
--- base/string_util.h (revision 10341)
+++ base/string_util.h (working copy)
@@ -7,9 +7,10 @@
#ifndef BASE_STRING_UTIL_H_
#define BASE_STRING_UTIL_H_
+#include <stdarg.h> // va_list
+
#include <string>
#include <vector>
-#include <stdarg.h> // va_list
#include "base/basictypes.h"
#include "base/string16.h"
@@ -174,7 +175,7 @@
bool WideToUTF16(const wchar_t* src, size_t src_len, string16* output);
string16 WideToUTF16(const std::wstring& wide);
bool UTF16ToWide(const char16* src, size_t src_len, std::wstring* output);
-std::wstring UTF16ToWide(const string16& utf8);
+std::wstring UTF16ToWide(const string16& utf16);
bool UTF8ToUTF16(const char* src, size_t src_len, string16* output);
string16 UTF8ToUTF16(const std::string& utf8);
@@ -243,6 +244,26 @@
return output;
}
+// ASCII-specific toupper. The standard library's toupper is locale sensitive,
+// so we don't want to use it here.
+template <class Char> inline Char ToUpperASCII(Char c) {
+ return (c >= 'a' && c <= 'z') ? (c + ('A' - 'a')) : c;
+}
+
+// Converts the elements of the given string. This version uses a pointer to
+// clearly differentiate it from the non-pointer variant.
+template <class str> inline void StringToUpperASCII(str* s) {
+ for (typename str::iterator i = s->begin(); i != s->end(); ++i)
+ *i = ToUpperASCII(*i);
+}
+
+template <class str> inline str StringToUpperASCII(const str& s) {
+ // for std::string and std::wstring
+ str output(s);
+ StringToUpperASCII(&output);
+ return output;
+}
+
// Compare the lower-case form of the given string against the given ASCII
// string. This is useful for doing checking if an input string matches some
// token, and it is optimized to avoid intermediate string copies. This API is
« no previous file with comments | « no previous file | base/string_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698