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

Unified Diff: third_party/cld/base/string_util.h

Issue 523108: Port back CLD to Linux and Mac and fix Trad Chinese detection (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 11 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
Index: third_party/cld/base/string_util.h
===================================================================
--- third_party/cld/base/string_util.h (revision 36372)
+++ third_party/cld/base/string_util.h (working copy)
@@ -7,17 +7,47 @@
#ifndef BASE_STRING_UTIL_H_
#define BASE_STRING_UTIL_H_
+#include <string>
#include <string.h>
namespace base {
+#ifdef WIN32
// Compare the two strings s1 and s2 without regard to case using
// the current locale; returns 0 if they are equal, 1 if s1 > s2, and -1 if
// s2 > s1 according to a lexicographic comparison.
inline int strcasecmp(const char* s1, const char* s2) {
return _stricmp(s1, s2);
}
+#else
+inline int strcasecmp(const char* s1, const char* s2) {
+ return strcasecmp(s1, s2);
+}
+#endif
+// This is mpcomplete's pattern for saving a string copy when dealing with
+// a function that writes results into a wchar_t[] and wanting the result to
+// end up in a std::wstring. It ensures that the std::wstring's internal
+// buffer has enough room to store the characters to be written into it, and
+// sets its .length() attribute to the right value.
+//
+// The reserve() call allocates the memory required to hold the string
+// plus a terminating null. This is done because resize() isn't
+// guaranteed to reserve space for the null. The resize() call is
+// simply the only way to change the string's 'length' member.
+//
+// XXX-performance: the call to wide.resize() takes linear time, since it fills
+// the string's buffer with nulls. I call it to change the length of the
+// string (needed because writing directly to the buffer doesn't do this).
+// Perhaps there's a constant-time way to change the string's length.
+template <class string_type>
+inline typename string_type::value_type* WriteInto(string_type* str,
+ size_t length_with_null) {
+ str->reserve(length_with_null);
+ str->resize(length_with_null - 1);
+ return &((*str)[0]);
}
+}
+
#endif // BASE_STRING_UTIL_H_
« no previous file with comments | « third_party/cld/bar/toolbar/cld/i18n/encodings/compact_lang_det/win/cld_unicodetext.cc ('k') | third_party/cld/cld.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698