本文整理汇总了C++中token::data方法的典型用法代码示例。如果您正苦于以下问题:C++ token::data方法的具体用法?C++ token::data怎么用?C++ token::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类token
的用法示例。
在下文中一共展示了token::data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runtime_error
static inline token hash(token const& pw, token const& salt)
{
token result;
if(::libscrypt_scrypt(
pw.data(), pw.size(),
salt.data(), salt.size(),
SCRYPT_N, SCRYPT_r, SCRYPT_p,
result.data(), result.size()
) == -1)
throw std::runtime_error("Incapable of hashing token");
return result;
}
示例2: calcLex
//this function finds the next token and outputs it
token calcLex()
{
curToken.clearData();
char currentChar;
while(1) //infinite loop, breaks through a return statement
{
//get the next char!
currentChar = filestream.get();
//used to ignore whitespace as a token
while( currentChar == ' ' || currentChar == '\t' || currentChar == '\n')
{
currentChar = filestream.get();
};
//if the current char is the end of a file, it returns the end of file symbol
if(currentChar == EOF)
{
curToken.type(endOfFileSym);
return curToken;
}
//this is the comment logic: if the next chars are /*...
if(followingChars("/*", currentChar, curToken))
{
//then while it isn't ending the line, or finding the end of comment sentinel...
while(currentChar != '\n' && !followingChars("*/", currentChar, curToken))
{
//move onto the next character
currentChar = filestream.get();
}
//move to the next character after the comment or line has ended
//hop back up to the top of the while loop
continue;
}
//if the chars ":=" are found, return the assignment symbol
if(followingChars(":=", currentChar, curToken))
{
curToken.type(assignSym);
curToken.data(":=");
return curToken;
}
//if the chars "read" are found, return the read symbol
if(followingChars("read", currentChar, curToken))
{
curToken.type(readSym);
curToken.data("read");
return curToken;
}
//if the chars "write" are found, return the write symbol
if(followingChars("write", currentChar, curToken))
{
curToken.type(writeSym);
curToken.data("write");
return curToken;
}
//if this is put above the followingChars, it adds a duplicate letter.
curToken.appendChar(currentChar);
//checks for identifier strings only starting with letters and underscores
if( isalpha(currentChar) || (currentChar == '_') )
{
while( isalnum(currentChar = filestream.get()) || (currentChar == '_'))
{
curToken.appendChar(currentChar);
}
//once the currentChar falls off the end of the identifier string, it must hop back to read the next one
filestream.unget();
//returns the identifier int
curToken.type(identifier);
return curToken;
}
//if the current char is a number
if(isdigit(currentChar))
{
while ( isdigit(currentChar = filestream.get()) || currentChar == '.')
{
if (currentChar == '.')
{
curToken.appendChar(currentChar);
currentChar = filestream.get();
if (!isdigit(currentChar))
{
curToken.type(numConstError);
return curToken;
}
while (isdigit(currentChar))
{
curToken.appendChar(currentChar);
currentChar = filestream.get();
}
filestream.unget();
curToken.type(numConst);
return curToken;
}
curToken.appendChar(currentChar);
//.........这里部分代码省略.........