summaryrefslogtreecommitdiff
path: root/src/mongo/db/fts/fts_query_parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/fts/fts_query_parser.cpp')
-rw-r--r--src/mongo/db/fts/fts_query_parser.cpp112
1 files changed, 54 insertions, 58 deletions
diff --git a/src/mongo/db/fts/fts_query_parser.cpp b/src/mongo/db/fts/fts_query_parser.cpp
index 5d73e69cb1e..6b2381c3366 100644
--- a/src/mongo/db/fts/fts_query_parser.cpp
+++ b/src/mongo/db/fts/fts_query_parser.cpp
@@ -34,77 +34,73 @@
namespace mongo {
- namespace fts {
+namespace fts {
- FTSQueryParser::FTSQueryParser( StringData str )
- : _pos(0), _raw( str ) {
- skipWhitespace();
- _previousWhiteSpace = true;
- }
-
- bool FTSQueryParser::more() const {
- return _pos < _raw.size();
- }
-
- QueryToken FTSQueryParser::next() {
- if ( _pos >= _raw.size() )
- return QueryToken( QueryToken::INVALID, "", 0, false );
+FTSQueryParser::FTSQueryParser(StringData str) : _pos(0), _raw(str) {
+ skipWhitespace();
+ _previousWhiteSpace = true;
+}
- unsigned start = _pos++;
- QueryToken::Type type = getType( _raw[start] );
+bool FTSQueryParser::more() const {
+ return _pos < _raw.size();
+}
- // Query Parser should never land on whitespace
- if ( type == QueryToken::WHITESPACE ) {
- invariant( false );
- }
+QueryToken FTSQueryParser::next() {
+ if (_pos >= _raw.size())
+ return QueryToken(QueryToken::INVALID, "", 0, false);
- if ( type == QueryToken::TEXT ) {
- while ( _pos < _raw.size() && getType( _raw[_pos] ) == type ) {
- _pos++;
- }
- }
+ unsigned start = _pos++;
+ QueryToken::Type type = getType(_raw[start]);
- StringData ret = _raw.substr( start, _pos - start );
- bool old = _previousWhiteSpace;
- _previousWhiteSpace = skipWhitespace();
+ // Query Parser should never land on whitespace
+ if (type == QueryToken::WHITESPACE) {
+ invariant(false);
+ }
- return QueryToken( type, ret, start, old );
+ if (type == QueryToken::TEXT) {
+ while (_pos < _raw.size() && getType(_raw[_pos]) == type) {
+ _pos++;
}
+ }
- bool FTSQueryParser::skipWhitespace() {
- unsigned start = _pos;
+ StringData ret = _raw.substr(start, _pos - start);
+ bool old = _previousWhiteSpace;
+ _previousWhiteSpace = skipWhitespace();
- while ( _pos < _raw.size() && getType( _raw[_pos] ) == QueryToken::WHITESPACE ) {
- _pos++;
- }
+ return QueryToken(type, ret, start, old);
+}
- return _pos > start;
- }
+bool FTSQueryParser::skipWhitespace() {
+ unsigned start = _pos;
+ while (_pos < _raw.size() && getType(_raw[_pos]) == QueryToken::WHITESPACE) {
+ _pos++;
+ }
- QueryToken::Type FTSQueryParser::getType( char c ) const {
- switch ( c ) {
- // Unicode TR29 defines these as Word Boundaries
- case '\n': // U+000A - LF
- case '\v': // U+000B - Veritical Tab
- case '\f': // U+000C - Form Feed
- case '\r': // U+000D - CR
- // Unicode TR29 remarks this could be used MidNum for Word Boundaries
- // but we treat this as a token separator
- case ' ': // U+0020 - Space
- return QueryToken::WHITESPACE;
- // Unicode TR29 has a particular note about the complexity of hyphens.
- // Since we use them for negation, we are sensitive to them, and we simply drop
- // them otherwise from words
- case '-':
- case '"':
- return QueryToken::DELIMITER;
- default:
- return QueryToken::TEXT;
- }
+ return _pos > start;
+}
- }
+QueryToken::Type FTSQueryParser::getType(char c) const {
+ switch (c) {
+ // Unicode TR29 defines these as Word Boundaries
+ case '\n': // U+000A - LF
+ case '\v': // U+000B - Veritical Tab
+ case '\f': // U+000C - Form Feed
+ case '\r': // U+000D - CR
+ // Unicode TR29 remarks this could be used MidNum for Word Boundaries
+ // but we treat this as a token separator
+ case ' ': // U+0020 - Space
+ return QueryToken::WHITESPACE;
+ // Unicode TR29 has a particular note about the complexity of hyphens.
+ // Since we use them for negation, we are sensitive to them, and we simply drop
+ // them otherwise from words
+ case '-':
+ case '"':
+ return QueryToken::DELIMITER;
+ default:
+ return QueryToken::TEXT;
}
-
+}
+}
}