本文整理汇总了C++中Token::Compare方法的典型用法代码示例。如果您正苦于以下问题:C++ Token::Compare方法的具体用法?C++ Token::Compare怎么用?C++ Token::Compare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Token
的用法示例。
在下文中一共展示了Token::Compare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Append
// Append the token with the specified value
Token* SqlParser::Append(Token *token, const char *str, const wchar_t *wstr, int len, Token *format)
{
if(token == NULL)
return NULL;
Token *append = new Token();
if(format == NULL)
*append = *token;
else
*append = *format;
append->prev = NULL;
append->next = NULL;
append->t_str = NULL;
append->t_wstr = NULL;
append->t_len = 0;
// If token starts with newline, add the same number of spaces before appended token
if(str != NULL && str[0] == '\n')
{
// Add newline token first
Token newline;
#ifdef WIN32
newline.type = TOKEN_SYMBOL;
newline.chr = '\r';
AppendCopy(token, &newline);
#endif
newline.type = TOKEN_SYMBOL;
newline.chr = '\n';
AppendCopy(token, &newline);
Token *prev = (format != NULL) ? format->prev : token->prev;
// Copy all blankes
while(prev != NULL && (prev->Compare(' ', L' ') == true || prev->Compare('\t', L'\t') == true))
{
AppendCopy(token, prev);
prev = prev->prev;
}
// Skip new line in the token
Token::Change(append, str + 1, wstr + 1, len - 1);
}
else
Token::Change(append, str, wstr, len);
Append(token, append);
return append;
}
示例2: GetNextToken
// MODIFIED BY option in EXPORT command
bool SqlParser::Db2ParseModifiedByOptions(Token **colsep_out)
{
bool exists = false;
Token *start = NULL;
// Options
while(true)
{
Token *next = GetNextToken();
if(next == NULL)
break;
if(start == NULL)
start = next;
// COLDELx where x is a single characater column delimiter
if(next->Compare("COLDEL", L"COLDEL", 0, 6) == true)
{
Token *del = NULL;
// x is a special punctuation character it is selected as a separate token
if(next->len == 6)
{
del = GetNextToken();
if(colsep_out != NULL)
*colsep_out = del;
}
exists = true;
}
else
// NOCHARDEL
if(next->Compare("NOCHARDEL", L"NOCHARDEL", 9) == true)
{
exists = true;
}
// Unknown option
else
{
PushBack(next);
break;
}
}
if(exists == true)
{
// Remove options
if(_target == SQL_ORACLE)
Token::Remove(start, GetLastToken());
}
return exists;
}
示例3: GetNextWordToken
// DB2 FETCH FIRST n ROWS ONLY clause in SELECT statement
bool SqlParser::ParseDb2FetchFirstRowOnly(Token *fetch, Token **rowlimit_soptions, int *rowlimit)
{
if(fetch == NULL || Token::Compare(fetch, "FETCH", L"FETCH", 5) == false)
return false;
Token *first = GetNextWordToken("FIRST", L"FIRST", 5);
if(first == NULL)
return false;
// Optional number of rows, meaning 1 row if skipped
Token *num = GetNextToken();
Token *rows = NULL;
if(num == NULL)
return false;
// Check if num already points to ROW or ROWS
if(num->Compare("ROW", L"ROW", 3) == true || num->Compare("ROWS", L"ROWS", 4) == true)
{
rows = num;
num = NULL;
}
// ROWS or ROW
if(rows == NULL)
rows = GetNextToken();
Token *only = GetNextWordToken("ONLY", L"ONLY", 4);
if(only == NULL)
return false;
// Set rowlimit to output
if(num == NULL && rowlimit != NULL)
*rowlimit = 1;
else
if(num != NULL && rowlimit_soptions != NULL)
*rowlimit_soptions = num;
// ROWNUM is used in Oracle
if(_target == SQL_ORACLE)
{
Token::Remove(fetch);
Token::Remove(first, only);
}
return true;
}
示例4: ParseSybaseExecuteProcedureStatement
// Sybase ADS EXECUTE PROCEDURE statement
bool SqlParser::ParseSybaseExecuteProcedureStatement(Token * /*execute*/)
{
Token *procedure = TOKEN_GETNEXTW("PROCEDURE");
if(procedure == NULL)
return false;
// Procedure name
Token *name = GetNextIdentToken();
if(name == NULL)
return false;
// List of parameters, empty () when there are no params
Token *open = TOKEN_GETNEXT('(');
Token *close = NULL;
if(open != NULL)
{
while(true)
{
Token *param = GetNextToken();
if(param == NULL)
break;
// () can be specified
if(param->Compare(')', L')') == true)
{
PushBack(param);
break;
}
ParseExpression(param);
// Next parameter
Token *comma = TOKEN_GETNEXT(',');
if(comma == NULL)
break;
}
close = TOKEN_GETNEXT(')');
}
// SQL Server does not allow ( and )
if(_target == SQL_SQL_SERVER)
{
Token::Remove(open);
Token::Remove(close);
}
if(_target != SQL_SYBASE_ADS)
Token::Remove(procedure);
return true;
}
示例5: Prepend
// Prepend the token with the specified value
Token* SqlParser::Prepend(Token *token, const char *str, const wchar_t *wstr, int len, Token *format)
{
if(token == NULL)
return NULL;
Token *prepend = new Token();
// Define how to format the token
if(format == NULL)
*prepend = *token;
else
*prepend = *format;
prepend->prev = NULL;
prepend->next = NULL;
prepend->t_str = NULL;
prepend->t_wstr = NULL;
prepend->t_len = 0;
prepend->flags = TOKEN_INSERTED;
Token::Change(prepend, str, wstr, len);
Prepend(token, prepend);
// If token ends with newline, add the same number of spaces after prepended token
if(str != NULL && str[len - 1] == '\n')
{
Token *prev = token->prev;
// Skip previously appended tokens
while(prev != NULL && prev->flags & TOKEN_INSERTED)
prev = prev->prev;
// Copy all blanks and tabs before appended token after new line
while(prev != NULL && (prev->Compare(' ', L' ') == true || prev->Compare('\t', L'\t') == true))
{
AppendCopy(prepend, prev);
prev = prev->prev;
}
}
return prepend;
}
示例6: ParseTeradataStorageClause
// Parse Teradata CREATE TABLE storage clause
bool SqlParser::ParseTeradataStorageClause(int obj_scope, Token *last_colname, Token *last_colend)
{
bool exists = false;
while(true)
{
Token *next = GetNextToken();
if(next == NULL)
break;
// UNIQUE PRIMARY INDEX hash partitioning clause
if(next->Compare("UNIQUE", L"UNIQUE", 6) == true)
{
Token *primary = GetNext("PRIMARY", L"PRIMARY", 7);
if(primary != NULL)
ParseTeradataPrimaryIndex(next, primary, obj_scope, last_colname, last_colend);
exists = true;
continue;
}
else
// PRIMARY INDEX hash partitioning clause
if(next->Compare("PRIMARY", L"PRIMARY", 7) == true)
{
ParseTeradataPrimaryIndex(NULL, next, obj_scope, last_colname, last_colend);
exists = true;
continue;
}
// Not a storage clause
PushBack(next);
break;
}
return exists;
}
示例7: GetNextWordToken
// Get next token and make sure it contains the specified word
Token* SqlParser::GetNextWordToken(const char *str, const wchar_t *wstr, int len)
{
Token *token = GetNextToken();
if(token == NULL)
return NULL;
if(token->Compare(str, wstr, len) == true)
return token;
else
PushBack(token);
return NULL;
}
示例8: GetNextCharToken
// Get the next token and make sure if contains the specified char
Token* SqlParser::GetNextCharToken(const char ch, const wchar_t wch)
{
Token *token = GetNextToken();
if(token == NULL)
return NULL;
if(token->Compare(ch, wch) == true)
return token;
else
PushBack(token);
return NULL;
}
示例9: while
// Parse SQL Server CREATE TABLE storage clause
bool SqlParser::ParseSqlServerStorageClause()
{
bool exists = false;
while(true)
{
Token *next = GetNext();
if(next == NULL)
break;
// ON filegroup_name
if(next->Compare("ON", L"ON", 2) == true)
{
// File group name
Token *name = GetNext();
if(_target != SQL_SQL_SERVER)
{
// Remove clause if it is the default PRIMARY file group
if(Token::Compare(name, "PRIMARY", L"PRIMARY", 7) == true ||
Token::Compare(name, "[PRIMARY]", L"[PRIMARY]", 9) == true)
{
Token::Remove(next, name);
}
}
exists = true;
}
else
{
PushBack(next);
break;
}
}
return exists;
}
示例10: Remove
// Set Removed flag for the token
void Token::Remove(Token *token, bool remove_spaces_before)
{
if(token == NULL)
return;
token->flags |= TOKEN_REMOVED;
Token *prev = token->prev;
Token *next = token->next;
if(prev == NULL)
return;
if(remove_spaces_before == true)
{
// Remove spaces token before the removed word (recursively), but only if there is a blank or ) , ;
// after removed token (otherwise tokens can be merged)
if(prev->Compare(' ', L' ') == true || prev->Compare('\t', L'\t') == true)
{
if(next != NULL)
{
if(next->IsBlank() == true || next->Compare(')', L')') == true ||
next->Compare(',', L',') == true || next->Compare(';', L';') == true)
Remove(prev);
}
else
// Next token can be not selected yet
if(token->next_start != NULL && token->remain_size > 1)
{
const char *cur = token->next_start;
if(*cur == ' ' || *cur == ')' || *cur == ',' || *cur == ';')
Remove(prev);
}
}
}
// In case cases better to remove spaces after: "SET var = 1" to "var := 1" when SET is removed
else
{
if(next != NULL && next->Compare(' ', L' ') == true)
Remove(next);
}
}
示例11: CreateOutputString
// Generate output
void SqlParser::CreateOutputString(const char **output, int *out_size)
{
if(output == NULL)
return;
Token *token = _tokens.GetFirst();
int len = 0;
int not_removed = 0;
int removed = 0;
// Calculate the output size in bytes and format output
while(token != NULL)
{
bool r = false;
bool n = false;
// If token removed its target length is 0
len += token->GetTargetLength();
if(token->IsRemoved() == false)
{
r = token->Compare('\r', L'\r');
if(r == false)
n = token->Compare('\n', L'\n');
}
// Check if we need to remove newline (0D0A \r\n on Windows, 0D on Unix)
if(r == true || n == true)
{
// String was not empty and all tokens removed
if(not_removed == 0 && removed != 0)
{
Token::Remove(token);
len--;
// If current is \r and next is \n remove \n
if(r == true && token->next != NULL && token->next->Compare('\n', L'\n') == true)
{
// Its size will be reduced in the next iteration
Token::Remove(token->next);
}
// Remove all spaces in this empty line
Token *cur = token->prev;
while(cur != NULL)
{
// Remove until new line
if(cur->Compare('\n', L'\n') || cur->Compare('\r', L'\r'))
break;
if(cur->IsBlank() == true && cur->IsRemoved() == false)
{
Token::Remove(cur);
len--;
}
cur = cur->prev;
}
}
not_removed = 0;
removed = 0;
}
// Calculate the number of removed and not removed tokens in line
else
{
if(token->IsBlank() == false)
{
if(token->IsRemoved() == true)
removed++;
else
not_removed++;
}
}
token = _tokens.GetNext();
}
if(len == 0)
{
*output = NULL;
if(out_size != NULL)
*out_size = 0;
return;
}
// Allocate buffer
char *out = new char[len + 1]; *out = 0;
token = _tokens.GetFirst();
int cur_len = 0;
while(token != NULL)
//.........这里部分代码省略.........
示例12: ParseTeradataTableOptions
// Teradata CREATE TABLE options before column definition
bool SqlParser::ParseTeradataTableOptions()
{
bool exists = false;
// , goes after table name before even first option
while(true)
{
Token *comma = GetNextCharToken(',', L',');
if(comma == NULL)
break;
// Most options can start with NO keyword to disable option
Token *no = GetNextWordToken("NO", L"NO", 2);
Token *next = GetNextToken();
if(next == NULL)
{
if(no != NULL)
PushBack(no);
break;
}
// [NO] FALLBACK to store a row copy
if(next->Compare("FALLBACK", L"FALLBACK", 8) == true)
{
if(_target != SQL_TERADATA)
Token::Remove(comma, next);
exists = true;
continue;
}
else
// [NO] BEFORE JOURNAL to store before image
if(next->Compare("BEFORE", L"BEFORE", 6) == true)
{
Token *journal = GetNextWordToken("JOURNAL", L"JOURNAL", 7);
if(_target != SQL_TERADATA && journal != NULL)
Token::Remove(comma, journal);
exists = true;
continue;
}
else
// [NO] AFTER JOURNAL to store after image
if(next->Compare("AFTER", L"AFTER", 5) == true)
{
Token *journal = GetNextWordToken("JOURNAL", L"JOURNAL", 7);
if(_target != SQL_TERADATA && journal != NULL)
Token::Remove(comma, journal);
exists = true;
continue;
}
if(no != NULL)
PushBack(no);
break;
}
return exists;
}
示例13: GetNextPlusMinusAsOperatorToken
// Get + or - as operator, not sign and number
Token* SqlParser::GetNextPlusMinusAsOperatorToken(const char ch, const wchar_t wch)
{
Token *token = GetNextToken();
if(token == NULL)
return NULL;
// If + or - already returned as separate token then exit, for example when there is "+ var"
if(token->Compare(ch, wch) == true)
return token;
// If a number follows + or - they will be in single token as +1, but check for + or - first
if(token->Compare(ch, wch, 0) == false)
{
PushBack(token);
return NULL;
}
// Change the first token to hold operator +/-
token->type = TOKEN_SYMBOL;
token->chr = ch;
token->wchr = 0;
token->str = NULL;
token->wstr = NULL;
// Rewind input pointer
_next_start -= token->len - 1;
_remain_size += token->len - 1;
token->len = 0;
token->next_start = _next_start;
token->remain_size = _remain_size;
/*// Separate +/- operator and number constant tokens
Token *token2 = new Token();
*token2 = *token;
token2->prev = NULL;
token2->next = NULL;
token2->t_str = NULL;
token2->t_wstr = NULL;
token2->t_len = 0;
// Second token hold number (decrease size by 1)
token2->type = TOKEN_WORD;
token2->chr = 0;
token2->wchr = 0;
token2->str = token2->str + 1;
token2->wstr = 0;
token2->len = token2->len - 1;
_tokens.Append(token, token2);
// Allow number to be selected as the next token
PushBack(token2); */
return token;
}
示例14: ParseSqlServerIndexOptions
// SQL Server index options WITH (PAD_INDEX = OFF, ...)
bool SqlParser::ParseSqlServerIndexOptions(Token *token)
{
if(token == NULL)
return false;
bool exists = false;
// Start with WITH keyword
if(token->Compare("WITH", L"WITH", 4) == false)
return false;
// ( can be omitted if FILLFACTOR is only specified
Token *open = GetNext('(', L'(');
while(true)
{
bool remove = false;
Token *option = GetNextToken();
if(option == NULL)
break;
// = between option name and value
/*Token *equal */ (void) GetNext('=', L'=');
Token *value = NULL;
// ALLOW_PAGE_LOCKS = ON | OFF
if(option->Compare("ALLOW_PAGE_LOCKS", L"ALLOW_PAGE_LOCKS", 16) == true)
{
value = GetNextToken();
if(_target != SQL_SQL_SERVER)
remove = true;
exists = true;
}
else
// ALLOW_ROW_LOCKS = ON | OFF
if(option->Compare("ALLOW_ROW_LOCKS", L"ALLOW_ROW_LOCKS", 15) == true)
{
value = GetNextToken();
if(_target != SQL_SQL_SERVER)
remove = true;
exists = true;
}
else
// FILLFACTOR = num
if(option->Compare("FILLFACTOR", L"FILLFACTOR", 10) == true)
{
value = GetNextToken();
if(_target != SQL_SQL_SERVER)
remove = true;
exists = true;
}
else
// IGNORE_DUP_KEY = ON | OFF
if(option->Compare("IGNORE_DUP_KEY", L"IGNORE_DUP_KEY", 14) == true)
{
value = GetNextToken();
if(_target != SQL_SQL_SERVER)
remove = true;
exists = true;
}
else
// PAD_INDEX = ON | OFF
if(option->Compare("PAD_INDEX", L"PAD_INDEX", 9) == true)
{
value = GetNextToken();
if(_target != SQL_SQL_SERVER)
remove = true;
exists = true;
}
else
// STATISTICS_NORECOMPUTE = ON | OFF
if(option->Compare("STATISTICS_NORECOMPUTE", L"STATISTICS_NORECOMPUTE", 22) == true)
{
value = GetNextToken();
if(_target != SQL_SQL_SERVER)
remove = true;
exists = true;
}
else
{
PushBack(option);
break;
}
//.........这里部分代码省略.........
示例15: ParseInformixStorageClause
// Parse Informix CREATE TABLE storage clause
bool SqlParser::ParseInformixStorageClause()
{
bool exists = false;
while(true)
{
Token *next = GetNextToken();
if(next == NULL)
break;
// EXTENT SIZE num
if(next->Compare("EXTENT", L"EXTENT", 6) == true)
{
Token *size = GetNextWordToken("SIZE", L"SIZE", 4);
Token *num = GetNextToken(size);
if(_target != SQL_INFORMIX && num != NULL)
Token::Remove(next, num);
exists = true;
continue;
}
else
// FRAGMENT BY partitioning clause
if(next->Compare("FRAGMENT", L"FRAGMENT", 8) == true)
{
ParseInformixFragmentBy(next);
exists = true;
continue;
}
else
// IN dbspace
if(next->Compare("IN", L"IN", 2) == true)
{
// Get database space name
Token *name = GetNextToken();
// TABLESPACE name in Oracle
if(_target == SQL_ORACLE)
Token::Change(next, "TABLESPACE", L"TABLESPACE", 10);
else
// DB2 also uses IN keyword to specify a tablespace
if(Target(SQL_DB2, SQL_INFORMIX) == false)
Token::Remove(next, name);
exists = true;
continue;
}
else
// LOCK MODE PAGE | ROW | TABLE
if(next->Compare("LOCK", L"LOCK", 4) == true)
{
Token *mode = GetNextWordToken("MODE", L"MODE", 4);
Token *type = GetNextToken(mode);
if(_target != SQL_INFORMIX && type != NULL)
Token::Remove(next, type);
exists = true;
continue;
}
else
// NEXT SIZE num
if(next->Compare("NEXT", L"NEXT", 4) == true)
{
Token *size = GetNextWordToken("SIZE", L"SIZE", 4);
Token *num = GetNextToken(size);
if(_target != SQL_INFORMIX && num != NULL)
Token::Remove(next, num);
exists = true;
continue;
}
// Not a storage clause
PushBack(next);
break;
}
return exists;
}