diff options
author | Nicolas Catania <niko@google.com> | 2010-01-27 11:13:27 -0800 |
---|---|---|
committer | Nicolas Catania <niko@google.com> | 2010-01-27 15:20:31 -0800 |
commit | f31fdb2e57186a552855e27f55036369ec1c279a (patch) | |
tree | e16544f5977c908cbabbecda59409338fe51dd16 /src | |
parent | fe47cee745a2b91cd9a2b98f7a82c9ad9fec726f (diff) | |
download | astl-f31fdb2e57186a552855e27f55036369ec1c279a.tar.gz |
Add char_traits support (needed for sstream).
Diffstat (limited to 'src')
-rw-r--r-- | src/string.cpp | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/src/string.cpp b/src/string.cpp index bb9e35a..6eed77d 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -207,7 +207,7 @@ string::string(const value_type *str) { if (NULL != str) { - Constructor(str, strlen(str)); + Constructor(str, traits_type::length(str)); } else { @@ -301,7 +301,7 @@ string& string::append(const value_type *str) { if (NULL != str) { - Append(str, strlen(str)); + Append(str, traits_type::length(str)); } return *this; } @@ -379,22 +379,16 @@ int string::compare(const value_type *other) const bool operator==(const string& left, const string& right) { - if (&left == &right) - { + if (&left == &right) { return true; } - else - { - // We can use strcmp here because even when the string is build from an - // array of char we insert the terminating '\0'. - return strcmp(left.mData, right.mData) == 0; - } + return (left.size() == right.size() && + !char_traits::compare(left.mData, right.mData, left.size())); } bool operator==(const string& left, const string::value_type *right) { - if (NULL == right) - { + if (NULL == right) { return false; } // We can use strcmp here because even when the string is build from an @@ -480,7 +474,7 @@ string& string::assign(const value_type *str) return *this; } clear(); - Constructor(str, strlen(str)); + Constructor(str, traits_type::length(str)); return *this; } |