本文整理汇总了C++中String::ExtractToken方法的典型用法代码示例。如果您正苦于以下问题:C++ String::ExtractToken方法的具体用法?C++ String::ExtractToken怎么用?C++ String::ExtractToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String::ExtractToken方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadHeader
//-----------------------------------------------------------------------------
// TemplateFileParsor::ReadHeader
//-----------------------------------------------------------------------------
void TemplateFileParsor::ReadHeader(const string &strTemplateName, String *pstrParams)
{
// Build template lines list
ifstream fs(PSZ(strTemplateName));
int iLine = 0;
while( !fs.eof() )
{
iLine++;
fs.getline(g_acScratchBuf, g_iScratchLen);
String strLine = g_acScratchBuf;
strLine.Trim();
if( !strLine.StartWith("#") )
// End of header reached
return;
// Header parsing
// Search for lines begining with "# @param..."
strLine.erase(0, 1);
strLine.Trim();
if( strLine.StartWith("@param") )
{
strLine.erase(0, strlen("@param"));
strLine.Trim();
// Get name
String strName;
strLine.ExtractToken(' ', &strName);
strName.Trim();
strLine.Trim();
// Pass type;
String strTmp;
strLine.ExtractToken(' ', &strTmp);
strLine.Trim();
// Pass description
strLine.ExtractToken('\'', '\'', &strTmp);
strLine.Trim();
*pstrParams += strName + string("=") + strLine + string(",");
}
}
}
示例2: ProcessCmdLineStr
void ParameterSearchBinaryCombo::ProcessCmdLineStr (String cmdLine)
{
char* arguments[60];
int argCount = 0;
arguments[0] = strdup ("ParameterSearchBinaryCombo");
argCount++;
while (!cmdLine.Empty ())
{
String parmField = cmdLine.ExtractToken (" ");
arguments[argCount] = strdup (parmField.Str ());
argCount++;
}
ParseCommandLine (argCount, arguments);
} /* CommandLineStr */
示例3: ParseExpression
//-----------------------------------------------------------------------------
// TemplateFileParsor::ParseExpression
//-----------------------------------------------------------------------------
ExpressionPtr TemplateFileParsor::ParseExpression(const String &_strExpr)
{
// Very basic math expression parsor:
// - can only parse expression like 'a + b - c * d / e' without parenthesis
// - spaces characters must enclose operators
ExpressionPtr ptrExpression = new Expression();
String strExpr = _strExpr;
Expression::Operation opPrevious = Expression::CharToOp('N');
uint uiStartSearch = 0;
while( !strExpr.empty() )
{
int iOpPos = strExpr.find_first_of("+-/*", uiStartSearch);
if( string::npos != iOpPos )
{
String strMatching = strExpr.substr(iOpPos-1,3);
// Operator must be enclosed by spaces characters
if( strMatching.Match(" * ") )
{
char cOp = strExpr[iOpPos];
String strToken;
// Extract first operand
strExpr.ExtractToken(cOp, &strToken);
strToken.Trim();
ptrExpression->AddFragment(new Expression::Fragment(new Expression::Constant(strToken), opPrevious));
opPrevious = Expression::CharToOp(cOp);
}
else
{ // Look forward
uiStartSearch = iOpPos + 1;
}
}
else
{
strExpr.Trim();
ptrExpression->AddFragment(new Expression::Fragment(new Expression::Constant(strExpr), opPrevious));
break;
}
}
return ptrExpression;
}
示例4: AddParameters
//-----------------------------------------------------------------------------
// ExtractorApp::AddParameters
//-----------------------------------------------------------------------------
void ExtractorApp::AddParameters(const String &strParamList)
{
String strList = strParamList;
String strParamDef, strParamName, strParamSubtitution;
while( !strList.empty() )
{
strList.ExtractToken(',', &strParamDef);
if( strParamDef.find('=') != string::npos )
{
strParamDef.ExtractToken('=', &strParamName);
strParamSubtitution = strParamDef;
}
else
{
strParamName = strParamDef;
strParamSubtitution = "<defined>";
}
// Add paramater only if not always defined
if( !m_dictParam.HasKey(strParamName) )
m_dictParam.insert(StringDict::value_type(strParamName, strParamSubtitution));
}
}
示例5: log
ParameterJob::ParameterJob (RunLog& _log,
String _desc
):
log (_log)
{
accuracy = 0;
startTime = 0;
_desc.TrimLeft ();
curStatus = _desc.ExtractChar ();
if ((curStatus == '0') ||
(curStatus == '1') ||
(curStatus == '2') ||
(curStatus == '3')
)
{
// We Are Ok
}
else
{
log.Level (-1) << endl
<< "ParameterJob: We have an invalid Cur Status."
<< endl;
osWaitForEnter ();
}
{
String processsNumField = _desc.ExtractToken (" ,\t");
processNum = atoi (processsNumField.Str ());
}
{
String jobIdField = _desc.ExtractToken (" ,\t");
jobId = atoi (jobIdField.Str ());
}
{
String cParmStr = _desc.ExtractToken (" ,\t");
cParm = atoi (cParmStr.Str ());
}
{
String gammaParmStr = _desc.ExtractToken (" ,\t");
gammaParm = atof (gammaParmStr.Str ());
}
{
String aParmStr = _desc.ExtractToken (" ,\t");
aParm = atoi (aParmStr.Str ());
}
{
String accuracyField = _desc.ExtractToken (" ,\t");
accuracy = atof (accuracyField.Str ());
}
}
示例6: log
ParameterProcess::ParameterProcess (RunLog& _log,
ImageClassList& imageClasses,
String _desc
):
log (_log)
{
highestAccuracy = (FFLOAT)0.0;
startTime = 0;
_desc.TrimLeft ();
curStatus = _desc.ExtractChar ();
if ((curStatus == '0') ||
(curStatus == '1') ||
(curStatus == '2')
)
{
// We Are Ok
}
else
{
log.Level (-1) << endl
<< "ParameterProcess: We have an invalid Cur Status[" << curStatus << "]."
<< endl;
exit (-1);
}
{
String processsNumField = _desc.ExtractToken (" ,\t");
processNum = atoi (processsNumField.Str ());
}
{
String jobIdField = _desc.ExtractToken (" ,\t");
jobId = atoi (jobIdField.Str ());
}
{
// Lets get the two Classes that we are running for
String class0Name = _desc.ExtractToken (" ,\t");
String class1Name = _desc.ExtractToken (" ,\t");
if (class0Name == "NoName")
{
class0 = class1 = NULL;
}
else
{
class0 = imageClasses.LookUpByName (class0Name);
class1 = imageClasses.LookUpByName (class1Name);
if (!class0)
{
cerr << endl
<< "*** ERROR *** ParameterProcess, Invalid Class0[" << class0Name << "]." << endl
<< endl;
exit (-1);
}
if (!class1)
{
cerr << endl
<< "*** ERROR *** ParameterProcess, Invalid Class0[" << class1Name << "]." << endl
<< endl;
exit (-1);
}
}
}
{
String cParmStr = _desc.ExtractToken (" ,\t");
cParm = atoi (cParmStr.Str ());
}
{
String gammaParmStr = _desc.ExtractToken (" ,\t");
gammaParm = atof (gammaParmStr.Str ());
}
{
String aParmStr = _desc.ExtractToken (" ,\t");
aParm = atoi (aParmStr.Str ());
}
{
String highestAccuracyField = _desc.ExtractToken (" ,\t");
highestAccuracy = (FFLOAT)atof (highestAccuracyField.Str ());
}
}
示例7: LoadCurrentStatusFile
void ParameterSearchBinaryCombo::LoadCurrentStatusFile ()
{
log.Level (10) << "ParameterSearchBinaryCombo::LoadCurrentStatusFile - Loading current Status File." << endl;
char buff[10240];
statusFile = fopen (statusFileName, "r");
if (!statusFile)
{
log.Level (-1) << endl
<< "ParameterSearchBinaryCombo::LoadCurrentStatusFile - *** ERROR *** Can not open Status File["
<< statusFileName << "]."
<< endl;
EndBlock ();
exit (1);
osWaitForEnter ();
}
{
fgets (buff, sizeof (buff), statusFile);
String cmdLine (buff);
cmdLine.TrimRight ();
ProcessCmdLineStr (cmdLine);
}
{
// If images are not loadted then we need 2 load trhem now.
if (images.QueueSize () < 1)
{
ReadProblem ();
}
}
{
fgets (buff, sizeof (buff), statusFile);
String buffStr (buff);
numOfProcesses = buffStr.ExtractTokenInt (" ,\n\t");
highestAccuracySoFar = buffStr.ExtractTokenDouble (" ,\n\t");
}
{
// Get Master Class List
delete masterClassList;
fgets (buff, sizeof (buff), statusFile);
String buffStr (buff);
numOfClasses = buffStr.ExtractTokenInt (" ,\n\t");
masterClassList = new ImageClassPtr[numOfClasses];
for (int idx = 0; idx < numOfClasses; idx++)
{
String className = buffStr.ExtractToken (" ,\n\t");
masterClassList[idx] = imageClasses.LookUpByName (className);
if (!masterClassList[idx])
{
cerr << endl
<< "*** ERROR ***, Class[" << className << "] is not one of the classes in the data file." << endl
<< endl;
exit (-1);
}
}
}
{
// Lets get next Class IDX's to perform
fgets (buff, sizeof (buff), statusFile);
String buffStr (buff);
nextClass0IDX = buffStr.ExtractTokenInt (" ,\n\t");
nextClass1IDX = buffStr.ExtractTokenInt (" ,\n\t");
}
if (processes)
{
delete processes;
processes = NULL;
}
processes = new ParameterProcessList (true);
for (int processLineNum = 0; processLineNum < numOfProcesses; processLineNum++)
{
fgets (buff, sizeof (buff), statusFile);
String buffStr (buff);
processes->PushOnBack (new ParameterProcess (log, imageClasses, buffStr));
}
fclose (statusFile);
statusFile = NULL;
return;
} /* LoadCurrentStatusFile */
示例8: ParsePrintData
//-----------------------------------------------------------------------------
// TemplateFileParsor::ParsePrintData
//-----------------------------------------------------------------------------
void TemplateFileParsor::ParsePrintData(String *pstrLine, int iLine)
{
pstrLine->Trim();
String strToPrint;
int iRc = pstrLine->ExtractToken('"', '"', &strToPrint);
CTemplateProcessor VarProc(CTemplateProcessor::EMPTY_STRING);
if( m_pVarEval )
VarProc.AddEvaluator(m_pVarEval);
CEnvVariableEvaluator EnvVar;
VarProc.AddEvaluator(&EnvVar);
// Variable substitution in quoted strings !!
VarProc.Process(&strToPrint);
uint uiPos = 0;
// looking for new line characters.
for( uiPos = strToPrint.find("\\n"); uiPos != String::npos; uiPos = strToPrint.find("\\n"))
strToPrint.replace(uiPos, 2, "\n");
// looking for carriage return characters.
for( uiPos = strToPrint.find("\\r"); uiPos != String::npos; uiPos = strToPrint.find("\\r"))
strToPrint.replace(uiPos, 2, "\r");
// looking for tab characters.
for( uiPos = strToPrint.find("\\t"); uiPos != String::npos; uiPos = strToPrint.find("\\t"))
strToPrint.replace(uiPos, 2, "\t");
if( 1 == iRc )
{
while( !strToPrint.empty() )
{
String strTxt, strTmp;
// Search for next format directive
bool bParse = true;
while( bParse )
{
iRc = strToPrint.ExtractToken('%', &strTmp);
// Skip directive indicator if it's a '%%' pair
if( strToPrint.StartWith('%') )
{
strTmp += '%';
strToPrint.erase(0, 1);
}
else
bParse = false;
strTxt += strTmp;
}
if( !strTxt.empty() )
{
// Text to print before format directive
TemplateTokenPtr ptrToken(new TemplateToken);
ptrToken->m_iTemplateLine = iLine;
ptrToken->m_TokenType = TemplateToken::PRINT_TEXT;
ptrToken->m_strData = strTxt;
ptrToken->m_Format.Set("%s");
m_vecToken.push_back(ptrToken);
}
if( 1 == iRc )
{
// A format directive was found
SuppressComments(pstrLine);
String strArgument;
int iRc2 = pstrLine->ExtractToken(',', &strArgument);
if( 0 == iRc2 )
{
cerr << "Error: Argument missing at line " << iLine << " in file " << m_strCurrentTemplateFile << "." << endl;
exit(1);
}
// Remove blanks
strArgument.Trim();
// Check argument type
if( strArgument.Match("[nxs:*<*>]*") )
{
// This is a array type argument
// Erase '[' and ']' enclosers
strArgument.erase(0, 1); // '['
uint uiMatchingPos = strArgument.find(']');
strArgument.erase(uiMatchingPos, 1); // ']'
// Insert a loop/end-loop couple
TemplateTokenPtr ptrLoopToken(new TemplateToken);
ptrLoopToken->m_iTemplateLine = iLine;
ptrLoopToken->m_TokenType = TemplateToken::LOOP_OVER;
ptrLoopToken->m_strParam1 = "loopvar";
// Extract loop part of the argument
String strLastPart;
int iLastPart = strArgument.rfind('>');
strLastPart = strArgument.substr(iLastPart+1);
ptrLoopToken->m_strParam2 = strArgument.substr(0, iLastPart+1);
ptrLoopToken->m_iEndBlockPos = m_vecToken.size() + 1;
// Add 'loop' Token
m_vecToken.push_back(ptrLoopToken);
//.........这里部分代码省略.........