MXS-1275: Inherit TrxBoundaryParser from CustomParser

This commit is contained in:
Johan Wikman
2017-05-31 13:17:42 +03:00
parent 9386143437
commit 1c6c19d6ae
3 changed files with 43 additions and 48 deletions

View File

@ -125,6 +125,25 @@ protected:
((*(m_pI + offset) == uc) || (*(m_pI + offset) == lc)); ((*(m_pI + offset) == uc) || (*(m_pI + offset) == lc));
} }
/**
* Peek current character.
*
* @param pC Upon successful return will be the current character.
*
* @return True, if the current character was returned, false otherwise.
* False will only be returned if the current position is at
* the end.
*/
bool peek_current_char(char* pC) const
{
if (m_pI != m_pEnd)
{
*pC = *m_pI;
}
return m_pI != m_pEnd;
}
/** /**
* Peek next character. * Peek next character.
* *
@ -134,16 +153,16 @@ protected:
* False will only be returned if the current position is at * False will only be returned if the current position is at
* the end. * the end.
*/ */
bool peek_next_char(char* pC) bool peek_next_char(char* pC) const
{ {
bypass_whitespace(); bool rc = (m_pI + 1 < m_pEnd);
if (m_pI != m_pEnd) if (rc)
{ {
*pC = *m_pI; *pC = *(m_pI + 1);
} }
return m_pI != m_pEnd; return rc;
} }
/** /**

View File

@ -14,7 +14,7 @@
#include <maxscale/cppdefs.hh> #include <maxscale/cppdefs.hh>
#include <ctype.h> #include <ctype.h>
#include <maxscale/modutil.h> #include <maxscale/customparser.hh>
#include <maxscale/query_classifier.h> #include <maxscale/query_classifier.h>
namespace maxscale namespace maxscale
@ -37,8 +37,11 @@ namespace maxscale
* of utmost importance; consequently it is defined in its entirety * of utmost importance; consequently it is defined in its entirety
* in the header to allow for aggressive inlining. * in the header to allow for aggressive inlining.
*/ */
class TrxBoundaryParser class TrxBoundaryParser : public maxscale::CustomParser
{ {
TrxBoundaryParser(const TrxBoundaryParser&);
TrxBoundaryParser& operator = (const TrxBoundaryParser&);
public: public:
enum token_t enum token_t
{ {
@ -88,10 +91,6 @@ public:
* @endcode * @endcode
*/ */
TrxBoundaryParser() TrxBoundaryParser()
: m_pSql(NULL)
, m_len(0)
, m_pI(NULL)
, m_pEnd(NULL)
{ {
} }
@ -546,29 +545,6 @@ private:
return type_mask; return type_mask;
} }
inline bool is_next_alpha(char uc, int offset = 1) const
{
ss_dassert(uc >= 'A' && uc <= 'Z');
char lc = uc + ('a' - 'A');
return
((m_pI + offset) < m_pEnd) &&
((*(m_pI + offset) == uc) || (*(m_pI + offset) == lc));
}
bool peek_next_char(char* pC) const
{
bool rc = (m_pI + 1 < m_pEnd);
if (rc)
{
*pC = *(m_pI + 1);
}
return rc;
}
// Significantly faster than library version. // Significantly faster than library version.
static char toupper(char c) static char toupper(char c)
{ {
@ -825,16 +801,6 @@ private:
return token; return token;
} }
private:
TrxBoundaryParser(const TrxBoundaryParser&);
TrxBoundaryParser& operator = (const TrxBoundaryParser&);
private:
const char* m_pSql;
int m_len;
const char* m_pI;
const char* m_pEnd;
}; };
} }

View File

@ -374,9 +374,15 @@ private:
// the identifier and if it is followed by a "=" we consume the value. // the identifier and if it is followed by a "=" we consume the value.
{ {
char c; char c;
if (consume_id() && peek_next_char(&c) && (c == '=')) if (consume_id())
{ {
consume_value(); bypass_whitespace();
if (peek_current_char(&c) && (c == '='))
{
++m_pI;
consume_value();
}
} }
else else
{ {
@ -396,7 +402,9 @@ private:
if (rv != ERROR) if (rv != ERROR)
{ {
if (peek_next_char(&c)) bypass_whitespace();
if (peek_current_char(&c))
{ {
if (c == ',') if (c == ',')
{ {
@ -470,7 +478,9 @@ private:
if (!is_error(rv)) if (!is_error(rv))
{ {
if (peek_next_char(&c) && (c == ',')) bypass_whitespace();
if (peek_current_char(&c) && (c == ','))
{ {
++m_pI; ++m_pI;
} }