diff options
author | Eliot Horowitz <eliot@10gen.com> | 2012-12-10 15:16:37 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2012-12-10 15:16:37 -0500 |
commit | d8be68870faae1176018f65ad124f5d6c72c894b (patch) | |
tree | c1749b97ddcc29340dbb418dd86cd313f2e23177 /src/mongo/base | |
parent | d7d055b768462d8e4b8277ae45fd3ad08f90be91 (diff) | |
download | mongo-d8be68870faae1176018f65ad124f5d6c72c894b.tar.gz |
SERVER-7866 - use StringData's correct methods and substr
Diffstat (limited to 'src/mongo/base')
-rw-r--r-- | src/mongo/base/generate_error_codes.py | 2 | ||||
-rw-r--r-- | src/mongo/base/parse_number.cpp | 24 | ||||
-rw-r--r-- | src/mongo/base/string_data.cpp | 2 |
3 files changed, 7 insertions, 21 deletions
diff --git a/src/mongo/base/generate_error_codes.py b/src/mongo/base/generate_error_codes.py index 223a7dc9b75..86f0f62532c 100644 --- a/src/mongo/base/generate_error_codes.py +++ b/src/mongo/base/generate_error_codes.py @@ -123,7 +123,7 @@ def generate_source(filename, error_codes, error_classes): symbol_to_string_cases = ';\n '.join( 'case %s: return "%s"' % (ec[0], ec[0]) for ec in error_codes) string_to_symbol_cases = ';\n '.join( - 'if (!strncmp("%s", name.data(), name.size())) return %s' % (ec[0], ec[0]) + 'if (name == "%s") return %s' % (ec[0], ec[0]) for ec in error_codes) int_to_symbol_cases = ';\n '.join( 'case %s: return %s' % (ec[0], ec[0]) for ec in error_codes) diff --git a/src/mongo/base/parse_number.cpp b/src/mongo/base/parse_number.cpp index 21ffd11bc8c..675c2d82e41 100644 --- a/src/mongo/base/parse_number.cpp +++ b/src/mongo/base/parse_number.cpp @@ -22,20 +22,6 @@ namespace mongo { /** - * Returns the substring of "str" starting at the "begin"th character, ending just before the - * "end"th character. - */ - static inline StringData sdsubstr( - const StringData& str, size_t begin, size_t end = std::numeric_limits<size_t>::max()) { - - if (end > str.size()) - end = str.size(); - if (begin > str.size()) - begin = str.size(); - return StringData(str.data() + begin, end - begin); - } - - /** * Returns the value of the digit "c", with the same conversion behavior as strtol. * * Assumes "c" is an ASCII character or UTF-8 octet. @@ -78,7 +64,7 @@ namespace mongo { } if (foundSignMarker) - return sdsubstr(stringValue, 1); + return stringValue.substr(1); return stringValue; } @@ -101,10 +87,10 @@ namespace mongo { if (stringValue[0] == '0') { if (stringValue.size() > 1 && (stringValue[1] == 'x' || stringValue[1] == 'X')) { *outputBase = 16; - return sdsubstr(stringValue, 2); + return stringValue.substr(2); } *outputBase = 8; - return sdsubstr(stringValue, 1); + return stringValue.substr(1); } *outputBase = 10; return stringValue; @@ -112,9 +98,9 @@ namespace mongo { else { *outputBase = inputBase; if (inputBase == 16) { - StringData prefix = sdsubstr(stringValue, 0, 2); + StringData prefix = stringValue.substr(0, 2); if (prefix == "0x" || prefix == "0X") - return sdsubstr(stringValue, 2); + return stringValue.substr(2); } return stringValue; } diff --git a/src/mongo/base/string_data.cpp b/src/mongo/base/string_data.cpp index e8ff0162e8a..8a65e30c9fa 100644 --- a/src/mongo/base/string_data.cpp +++ b/src/mongo/base/string_data.cpp @@ -20,7 +20,7 @@ namespace mongo { std::ostream& operator<<(std::ostream& stream, const StringData& value) { - return stream.write(value.data(), value.size()); + return stream.write(value.rawData(), value.size()); } } // namespace mongo |