return true;
}
+bool
+Parser::Tokenizer::suffix(SBuf &returnedToken, const CharacterSet &tokenChars, const SBuf::size_type limit)
+{
+ SBuf span = buf_;
+
+ if (limit < buf_.length())
+ span.consume(buf_.length() - limit); // ignore the N prefix characters
+
+ auto i = span.rbegin();
+ SBuf::size_type found = 0;
+ while (i != span.rend() && tokenChars[*i]) {
+ ++i;
+ ++found;
+ }
+ if (!found)
+ return false;
+ returnedToken = buf_;
+ buf_ = returnedToken.consume(buf_.length() - found);
+ return true;
+}
+
SBuf::size_type
Parser::Tokenizer::skipAll(const CharacterSet &tokenChars)
{
return false;
}
+bool
+Parser::Tokenizer::skipSuffix(const SBuf &tokenToSkip)
+{
+ if (buf_.length() < tokenToSkip.length())
+ return false;
+
+ SBuf::size_type offset = 0;
+ if (tokenToSkip.length() < buf_.length())
+ offset = buf_.length() - tokenToSkip.length();
+
+ if (buf_.substr(offset, SBuf::npos).cmp(tokenToSkip) == 0) {
+ buf_ = buf_.substr(0,offset);
+ return true;
+ }
+ return false;
+}
+
bool
Parser::Tokenizer::skip(const SBuf &tokenToSkip)
{
*/
bool prefix(SBuf &returnedToken, const CharacterSet &tokenChars, SBuf::size_type limit = SBuf::npos);
+ /** Extracts all sequential permitted characters up to an optional length limit.
+ * Operates on the trailing end of the buffer.
+ *
+ * Note that Tokenizer cannot tell whether the buffer will
+ * gain more data when/if more input becomes available later.
+ *
+ * \retval true one or more characters were found, the sequence (string) is placed in returnedToken
+ * \retval false no characters from the permitted set were found
+ */
+ bool suffix(SBuf &returnedToken, const CharacterSet &tokenChars, SBuf::size_type limit = SBuf::npos);
+
+ /** skips a given suffix character sequence (string)
+ * Operates on the trailing end of the buffer.
+ *
+ * Note that Tokenizer cannot tell whether the buffer will
+ * gain more data when/if more input becomes available later.
+ *
+ * \return whether the exact character sequence was found and skipped
+ */
+ bool skipSuffix(const SBuf &tokenToSkip);
+
/** skips a given character sequence (string)
*
* \return whether the exact character sequence was found and skipped