| 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_
|
|
|