diff options
author | David Storch <david.storch@10gen.com> | 2017-06-28 12:31:01 -0400 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2017-06-29 15:23:55 -0400 |
commit | f37ca39a93b5344992384392b3e57eed9c4cd1b0 (patch) | |
tree | 8aa5792d3741b6ae9a3a737baebea6f3dc27af40 /src/mongo/db/update/path_support.cpp | |
parent | 57e3704f443df1fb071e0af81421ce2999fad767 (diff) | |
download | mongo-f37ca39a93b5344992384392b3e57eed9c4cd1b0.tar.gz |
SERVER-28769 Implement PopNode.
Diffstat (limited to 'src/mongo/db/update/path_support.cpp')
-rw-r--r-- | src/mongo/db/update/path_support.cpp | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/mongo/db/update/path_support.cpp b/src/mongo/db/update/path_support.cpp index 993d4195bc4..5538f581385 100644 --- a/src/mongo/db/update/path_support.cpp +++ b/src/mongo/db/update/path_support.cpp @@ -43,19 +43,6 @@ using mongoutils::str::stream; namespace { -bool isNumeric(StringData str, size_t* num) { - size_t res = 0; - for (size_t i = 0; i < str.size(); ++i) { - if (str[i] < '0' || str[i] > '9') { - return false; - } else { - res = res * 10 + (str[i] - '0'); - } - } - *num = res; - return true; -} - Status maybePadTo(mutablebson::Element* elemArray, size_t sizeRequired) { dassert(elemArray->getType() == Array); @@ -82,6 +69,19 @@ Status maybePadTo(mutablebson::Element* elemArray, size_t sizeRequired) { } // unnamed namespace +bool isNumericPathComponent(StringData str, size_t* num) { + size_t res = 0; + for (size_t i = 0; i < str.size(); ++i) { + if (str[i] < '0' || str[i] > '9') { + return false; + } else { + res = res * 10 + (str[i] - '0'); + } + } + *num = res; + return true; +} + Status findLongestPrefix(const FieldRef& prefix, mutablebson::Element root, size_t* idxFound, @@ -111,7 +111,7 @@ Status findLongestPrefix(const FieldRef& prefix, break; case Array: - if (!isNumeric(prefixPart, &numericPart)) { + if (!isNumericPathComponent(prefixPart, &numericPart)) { viable = false; } else { curr = prev[numericPart]; @@ -184,7 +184,7 @@ Status createPathAt(const FieldRef& prefix, bool inArray = false; if (elemFound.getType() == mongo::Array) { size_t newIdx = 0; - if (!isNumeric(prefix.getPart(idxFound), &newIdx)) { + if (!isNumericPathComponent(prefix.getPart(idxFound), &newIdx)) { return Status(ErrorCodes::PathNotViable, str::stream() << "Cannot create field '" << prefix.getPart(idxFound) << "' in element {" |