本文整理汇总了C++中Tokens类的典型用法代码示例。如果您正苦于以下问题:C++ Tokens类的具体用法?C++ Tokens怎么用?C++ Tokens使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tokens类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: get_tokens
Tokens get_tokens( const String& s ) {
Tokens res;
char prev = ' ';
String tmp;
for ( auto c : s ) {
if ( prev != ' ' && prev != c ) {
res.push_back(tmp);
prev = c;
tmp = "";
tmp += c;
} else {
prev = c;
tmp += c;
}
}
if ( tmp != "" )
res.push_back(tmp);
return res;
}
开发者ID:sh19910711,项目名称:codeforces-solutions,代码行数:19,代码来源:main.cpp
示例2: StrSplit
Tokens StrSplit(const std::string& src, const std::string& sep)
{
Tokens r;
std::string s;
for (char i : src)
{
if (sep.find(i) != std::string::npos)
{
if (s.length()) r.push_back(s);
s.clear();
}
else
{
s += i;
}
}
if (s.length()) r.push_back(s);
return r;
}
开发者ID:lduguid,项目名称:mangos-tbc,代码行数:19,代码来源:Util.cpp
示例3: StrSplit
Tokens StrSplit(const std::string& src, const std::string& sep)
{
Tokens r;
std::string s;
for (std::string::const_iterator i = src.begin(); i != src.end(); ++i)
{
if (sep.find(*i) != std::string::npos)
{
if (s.length()) r.push_back(s);
s = "";
}
else
{
s += *i;
}
}
if (s.length()) r.push_back(s);
return r;
}
开发者ID:AtVirus,项目名称:server,代码行数:19,代码来源:Util.cpp
示例4: AddChildren
static void AddChildren(Tokens& tok, TreeNode* parent)
{
TreeNode* cur = 0;
while (tok.Good())
{
std::string str;
tok >> str;
if (!tok.Good() || str.at(0) == '}')
return;
if (str.at(0) == '{')
{
if (!cur)
cur = parent->AddChild(TreeNode::strdup(""));
AddChildren(tok, cur);
continue;
}
cur = parent->AddChild(TreeNode::strdup(str));
}
}
开发者ID:altimosk,项目名称:testgeom,代码行数:20,代码来源:gentree.cpp
示例5: parseDump
//static
void Command::parseDump( Tokens& tokens, bool helpMode, Command*& result )
{
if (tokens.size() < 3 && !helpMode) THROW( CWDB_ERR_PARSER, "Bad syntax: missing options in \"dump\" command" );
switch( checkAngen( tokens, 1) ) {
case ANGEN_COLLECTION: result = new DumpCollectionCommand; break;
default: THROW( CWDB_ERR_PARSER, "Bad syntax: unrecognized option in \"dump\" command" );
}
if (result != 0 && !helpMode) result->parse( tokens );
}
开发者ID:michael-popov,项目名称:clockworkdb,代码行数:12,代码来源:parser.cpp
示例6: textCursor
void Editor::autoComplete(const QString& item)
{
if (!m_isAutoCompletionEnabled || item.isEmpty())
return;
const int currentPosition = textCursor().position();
const QString subtext = text().left(currentPosition);
const Tokens tokens = m_evaluator->scan(subtext);
if (!tokens.valid() || tokens.count() < 1)
return;
const Token lastToken = tokens.at(tokens.count() - 1);
if (!lastToken.isIdentifier())
return;
const QStringList str = item.split(':');
blockSignals(true);
QTextCursor cursor = textCursor();
cursor.setPosition(lastToken.pos());
cursor.setPosition(lastToken.pos() + lastToken.text().length(), QTextCursor::KeepAnchor);
setTextCursor(cursor);
insert(str.at(0));
blockSignals(false);
cursor = textCursor();
bool hasParensAlready;
if ((hasParensAlready = cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor))) {
QString nextChar = cursor.selectedText();
hasParensAlready = (nextChar == "(");
}
bool shouldAutoInsertParens = (FunctionRepo::instance()->find(str.at(0))
|| m_evaluator->hasUserFunction(str.at(0)))
&& !hasParensAlready;
if (shouldAutoInsertParens) {
insert(QString::fromLatin1("()"));
cursor = textCursor();
cursor.movePosition(QTextCursor::PreviousCharacter);
setTextCursor(cursor);
}
}
开发者ID:0pq76r,项目名称:SpeedCrunch,代码行数:41,代码来源:editor.cpp
示例7: parse
void RenameMetricCommand::parse(Tokens& tokens)
{
if (tokens.size() != 5) THROW("Invalid RENAME METRIC command");
if (tokens[2].m_angen != ANGEN_IDENT) THROW("Expected existing metric name");
m_oldName = tokens[2].m_val.m_str;
if (!checkString(tokens[3], "to")) THROW("Expected key word TO");
if (tokens[4].m_angen != ANGEN_IDENT) THROW("Expected new metric name");
m_newName = tokens[4].m_val.m_str;
}
开发者ID:michael-popov,项目名称:clockworkdb,代码行数:12,代码来源:cmd_metrics.cpp
示例8: parse
void RenameDataspaceCommand::parse(Tokens& tokens)
{
if (tokens.size() != 5) THROW("Invalid RENAME DATASPACE command");
if (tokens[2].m_angen != ANGEN_IDENT) THROW("Expected existing dataspace name");
m_oldName = tokens[2].m_val.m_str;
if (!checkString(tokens[3], "to")) THROW("Expected key word TO");
if (tokens[4].m_angen != ANGEN_IDENT) THROW("Expected new dataspace name");
m_newName = tokens[4].m_val.m_str;
}
开发者ID:michael-popov,项目名称:clockworkdb,代码行数:12,代码来源:cmd_dataspaces.cpp
示例9: tokenize
StringUtils::Tokens StringUtils::tokenize(const std::string& str, const std::string& delimiters)
{
Tokens tokens;
std::string::size_type delimPos = 0, tokenPos = 0, pos = 0;
if(str.length()<1) return tokens;
while(1)
{
delimPos = str.find_first_of(delimiters, pos);
tokenPos = str.find_first_not_of(delimiters, pos);
if (tokenPos != std::string::npos && str[tokenPos]=='\"')
{
delimPos = str.find_first_of("\"", tokenPos+1);
pos++;
}
if(std::string::npos != delimPos)
{
if(std::string::npos != tokenPos)
{
if(tokenPos<delimPos)
{
std::string token = str.substr(pos,delimPos-pos);
if (token.length()) tokens.push_back(token);
}
}
pos = delimPos+1;
}
else
{
if(std::string::npos != tokenPos)
{
std::string token = str.substr(pos);
if (token.length()) tokens.push_back(token);
}
break;
}
}
return tokens;
}
开发者ID:wangfeilong321,项目名称:MuseOpenIG,代码行数:40,代码来源:stringutils.cpp
示例10: main
int main()
{
Code code("//bla bli blo\nflap");
CodeRange cr(code);
Tokens tokens;
tokens.push_back(Token::Ptr(new Symbol(reduce(cr, 1))));
tokens.push_back(Token::Ptr(new Symbol(reduce(cr, 1))));
tokens.push_back(Token::Ptr(new Name(reduce(cr, 3))));
tokens.push_back(Token::Ptr(new Whitespace(reduce(cr, 1))));
tokens.push_back(Token::Ptr(new Name(reduce(cr, 3))));
tokens.push_back(Token::Ptr(new Whitespace(reduce(cr, 1))));
tokens.push_back(Token::Ptr(new Name(reduce(cr, 3))));
tokens.push_back(Token::Ptr(new Newline(reduce(cr, 1))));
tokens.push_back(Token::Ptr(new Name(reduce(cr, 4))));
TokenRange tr(tokens);
auto comment = Comment::construct(tr);
return 0;
}
开发者ID:RoboBuddie,项目名称:gubg,代码行数:18,代码来源:Composite.cpp
示例11: spansToTokens
inline void spansToTokens(std::string const& str, TokenSpans const& spans, Tokens &tokens) {
if (str.empty()) return;
char const* s = &str[0];
unsigned i = 0, n = spans.size();
tokens.resize(n);
for (; i < n; ++i) {
TokenSpan const& span = spans[i];
assert(span.first < str.size());
assert(span.second <= str.size());
tokens[i].assign(s + span.first, s + span.second);
}
}
开发者ID:graehl,项目名称:hyp,代码行数:13,代码来源:Span.hpp
示例12: StrSplit
void RealmList::UpdateRealm( uint32 ID, const std::string& name, const std::string& address, uint32 port, uint8 icon, RealmFlags realmflags, uint8 timezone, AccountTypes allowedSecurityLevel, float popu, const char* builds)
{
// Create new if not exist or update existed
Realm& realm = m_realms[name];
realm.m_ID = ID;
realm.icon = icon;
realm.realmflags = realmflags;
realm.timezone = timezone;
realm.allowedSecurityLevel = allowedSecurityLevel;
realm.populationLevel = popu;
Tokens tokens = StrSplit(builds, " ");
Tokens::iterator iter;
for (iter = tokens.begin(); iter != tokens.end(); ++iter)
{
uint32 build = atol((*iter).c_str());
realm.realmbuilds.insert(build);
}
uint16 first_build = !realm.realmbuilds.empty() ? *realm.realmbuilds.begin() : 0;
realm.realmBuildInfo.build = first_build;
realm.realmBuildInfo.major_version = 0;
realm.realmBuildInfo.minor_version = 0;
realm.realmBuildInfo.bugfix_version = 0;
realm.realmBuildInfo.hotfix_version = ' ';
if (first_build)
if (RealmBuildInfo const* bInfo = FindBuildInfo(first_build))
if (bInfo->build == first_build)
realm.realmBuildInfo = *bInfo;
// Append port to IP address.
std::ostringstream ss;
ss << address << ":" << port;
realm.address = ss.str();
}
开发者ID:Dekadencee,项目名称:OregonCore,代码行数:39,代码来源:RealmList.cpp
示例13: parseDrop
//static
void Command::parseDrop( Tokens& tokens, bool helpMode, Command*& result )
{
if (tokens.size() < 3 && !helpMode) THROW( CWDB_ERR_PARSER, "Bad syntax: missing options in \"drop\" command" );
switch( checkAngen( tokens, 1) ) {
case ANGEN_DATASPACE: result = new DropDataspaceCommand; break;
case ANGEN_COLLECTION: result = new DropCollectionCommand; break;
case ANGEN_METRIC: result = new DropMetricCommand; break;
default: THROW( CWDB_ERR_PARSER, "Bad syntax: unrecongized option in \"drop\" command" );
}
if (result != 0 && !helpMode) result->parse( tokens );
}
开发者ID:michael-popov,项目名称:clockworkdb,代码行数:14,代码来源:parser.cpp
示例14: autoCalcSelection
void Editor::autoCalcSelection()
{
if (!m_isAutoCalcEnabled)
return;
const QString str = m_evaluator->autoFix(textCursor().selectedText());
if (str.isEmpty())
return;
// Very short (just one token) and still no calculation, then skip.
if (!m_isAnsAvailable) {
const Tokens tokens = m_evaluator->scan(text());
if (tokens.count() < 2)
return;
}
// Too short even after autofix? Don't bother either.
const Tokens tokens = m_evaluator->scan(str);
if (tokens.count() < 2)
return;
// Same reason as above, do not update "ans".
m_evaluator->setExpression(str);
const HNumber num = m_evaluator->evalNoAssign();
if (m_evaluator->error().isEmpty()) {
if (num.isNan() && m_evaluator->isUserFunctionAssign()) {
// Result is not always available when assigning a user function.
const QString message = tr("Selection result: n/a");
emit autoCalcEnabled(message);
} else {
const QString message = tr("Selection result: <b>%1</b>").arg(NumberFormatter::format(num));
emit autoCalcEnabled(message);
}
} else
emit autoCalcEnabled(m_evaluator->error());
}
开发者ID:0pq76r,项目名称:SpeedCrunch,代码行数:37,代码来源:editor.cpp
示例15: tokenize
void Sentence::tokenize()
{
Tokens tokens;
::tokenize(sent_,tokens);
int i,n = tokens.size();
Syllable sy;
sy.span = 1;
sy.sent_ = this;
sy.start = 0;
for (i = 0;i < n;i ++) {
if (tokens[i].is_token) {
/*
char *viet_token = viet_to_viscii(tokens[i].value.c_str());
if (!viet_token) {
sy.id = get_sarch()[tokens[i].value];
sy.cid = get_sarch()[string("6")+tokens[i].value];
syllables.push_back(sy);
} else {
*/
const char *viet_token = tokens[i].value.c_str();
int jj,nn = strlen(viet_token);
for (jj = 0;jj < nn;jj ++)
if (viet_isalpha((unsigned char)viet_token[jj]) || viet_isdigit((unsigned char)viet_token[jj])) {
string s = viet_token;
sy.id = get_ngram()[s];
sy.cid = get_ngram()[get_std_syllable(s)];
syllables.push_back(sy);
break;
}
/*}*/
}
sy.start += tokens[i].value.size();
}
}
开发者ID:pclouds,项目名称:vspell,代码行数:37,代码来源:sentence.cpp
示例16: InitDelayThread
bool DatabasePostgre::Initialize(const char *infoString)
{
if(!Database::Initialize(infoString))
return false;
tranThread = NULL;
InitDelayThread();
Tokens tokens = StrSplit(infoString, ";");
Tokens::iterator iter;
std::string host, port_or_socket_dir, user, password, database;
iter = tokens.begin();
if(iter != tokens.end())
host = *iter++;
if(iter != tokens.end())
port_or_socket_dir = *iter++;
if(iter != tokens.end())
user = *iter++;
if(iter != tokens.end())
password = *iter++;
if(iter != tokens.end())
database = *iter++;
if (host == ".")
mPGconn = PQsetdbLogin(NULL, port_or_socket_dir == "." ? NULL : port_or_socket_dir.c_str(), NULL, NULL, database.c_str(), user.c_str(), password.c_str());
else
mPGconn = PQsetdbLogin(host.c_str(), port_or_socket_dir.c_str(), NULL, NULL, database.c_str(), user.c_str(), password.c_str());
/* check to see that the backend connection was successfully made */
if (PQstatus(mPGconn) != CONNECTION_OK)
{
sLog.outError( "Could not connect to Postgre database at %s: %s",
host.c_str(), PQerrorMessage(mPGconn));
PQfinish(mPGconn);
mPGconn = NULL;
return false;
}
else
{
sLog.outDetail( "Connected to Postgre database at %s",
host.c_str());
sLog.outString( "PostgreSQL server ver: %d",PQserverVersion(mPGconn));
return true;
}
}
开发者ID:Scergo,项目名称:zero,代码行数:51,代码来源:DatabasePostgre.cpp
示例17: tokenize
int ClangFunctionHintModel::activeArgument(const QString &prefix) const
{
int argnr = 0;
int parcount = 0;
SimpleLexer tokenize;
Tokens tokens = tokenize(prefix);
for (int i = 0; i < tokens.count(); ++i) {
const CPlusPlus::Token &tk = tokens.at(i);
if (tk.is(T_LPAREN))
++parcount;
else if (tk.is(T_RPAREN))
--parcount;
else if (! parcount && tk.is(T_COMMA))
++argnr;
}
if (parcount < 0)
return -1;
if (argnr != m_currentArg)
m_currentArg = argnr;
return argnr;
}
开发者ID:AltarBeastiful,项目名称:qt-creator,代码行数:24,代码来源:clangcompletion.cpp
示例18: parseDescr
//static
void Command::parseDescr( Tokens& tokens, bool helpMode, Command*& result )
{
if (tokens.size() == 1) {
result = new DescrCommand();
return;
}
switch( checkAngen( tokens, 1) ) {
case ANGEN_DATASPACE: result = new DescrDataspaceCommand; break;
case ANGEN_COLLECTION: result = new DescrCollectionCommand; break;
case ANGEN_METRIC: result = new DescrMetricCommand; break;
default: THROW( CWDB_ERR_PARSER, "Bad syntax: unrecognized option in \"descr\" command" );
}
if (result != 0 && !helpMode) result->parse( tokens );
}
开发者ID:michael-popov,项目名称:clockworkdb,代码行数:17,代码来源:parser.cpp
示例19: help
void CommandLineEngine::help(Print * printer, Tokens & tk, FunctionFlags ff)
{
if (!printer)
return;
UserFunctions::iterator it;
String arg;
if( tk.next(arg) )
{
if( arg.equalsIgnoreCase("help") )
{
printer->println("Type help without any arguments to learn more.");
return;
}
else if( arg.equalsIgnoreCase("set") )
{
set(printer, tk, FF_HelpText);
return;
}
it = findFunction(arg);
if( it == mUserFunctions.end() )
{
printer->print("Unable to locate the function: ");
printer->println(arg);
return;
}
// Call the function and tell it to display its help text
it->func(printer, tk, FF_HelpText);
return;
}
else
{
printer->println("Function Name: help");
printer->println("Type help <function name> to learn more about that function.");
printer->println("The following functions are defined:");
printer->println("help");
printer->println("set");
// List all the functions
for( it = mUserFunctions.begin(); it != mUserFunctions.end(); ++it)
{
printer->println(it->name);
}
}
}
开发者ID:Costallat,项目名称:spark-telnet-server-lib,代码行数:47,代码来源:CommandLineEngine.cpp
示例20: GenerateResearchSites
void Player::_LoadArchaeology(QueryResult* result)
{
for (uint8 i = 0; i < MAX_RESEARCH_SITES; ++i)
_digSites[i].count = 0;
if (!sWorld.getConfig(CONFIG_BOOL_ARCHAEOLOGY_ENABLED))
{
delete result;
return;
}
if (!result)
{
GenerateResearchSites();
GenerateResearchProjects();
return;
}
Field* fields = result->Fetch();
// Loading current zones
Tokens tokens = Tokens(fields[0].GetCppString(), ' ');
if (tokens.size() != 0 && tokens.size() <= MAX_RESEARCH_SITES)
{
_researchSites.clear();
for (uint8 i = 0; i < tokens.size(); ++i)
_researchSites.insert(uint32(atoi(tokens[i])));
}
else
GenerateResearchSites();
// Loading current zone info
tokens = Tokens(fields[1].GetCppString(), ' ');
if (tokens.size() == MAX_RESEARCH_SITES)
{
for (uint8 i = 0; i < MAX_RESEARCH_SITES; ++i)
_digSites[i].count = uint32(atoi(tokens[i]));
}
// Loading current projects
tokens = Tokens(fields[2].GetCppString(), ' ');
if (tokens.size() == MAX_RESEARCH_PROJECTS)
{
for (uint8 i = 0; i < MAX_RESEARCH_PROJECTS; ++i)
if (ResearchProjectEntry const* entry = sResearchProjectStore.LookupEntry(atoi(tokens[i])))
if (entry->IsVaid())
ReplaceResearchProject(0, entry->ID);
}
else
GenerateResearchProjects();
delete result;
}
开发者ID:Jojo2323,项目名称:mangos3,代码行数:54,代码来源:Archaeology.cpp
注:本文中的Tokens类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论