本文整理汇总了C++中ParamVector::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ ParamVector::clear方法的具体用法?C++ ParamVector::clear怎么用?C++ ParamVector::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParamVector
的用法示例。
在下文中一共展示了ParamVector::clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseCommandLine
//commandLine should contain path to n++ executable running
void parseCommandLine(TCHAR * commandLine, ParamVector & paramVector) {
//params.erase(params.begin());
//remove the first element, since thats the path the the executable (GetCommandLine does that)
TCHAR stopChar = TEXT(' ');
if (commandLine[0] == TEXT('\"')) {
stopChar = TEXT('\"');
++commandLine;
}
//while this is not really DBCS compliant, space and quote are in the lower 127 ASCII range
while(commandLine[0] && commandLine[0] != stopChar)
{
++commandLine;
}
// For unknown reason, the following command :
// c:\NppDir>notepad++
// (without quote) will give string "notepad++\0notepad++\0"
// To avoid the unexpected behaviour we check the end of string before increasing the pointer
if (commandLine[0] != '\0')
++commandLine; //advance past stopChar
//kill remaining spaces
while(commandLine[0] == TEXT(' '))
++commandLine;
bool isFile = checkSingleFile(commandLine); //if the commandline specifies only a file, open it as such
if (isFile) {
paramVector.push_back(commandLine);
return;
}
bool isInFile = false;
bool isInWhiteSpace = true;
paramVector.clear();
size_t commandLength = lstrlen(commandLine);
for (size_t i = 0; i < commandLength; ++i)
{
switch(commandLine[i]) {
case '\"': { //quoted filename, ignore any following whitespace
if (!isInFile) { //" will always be treated as start or end of param, in case the user forgot to add an space
paramVector.push_back(commandLine+i+1); //add next param(since zero terminated generic_string original, no overflow of +1)
}
isInFile = !isInFile;
isInWhiteSpace = false;
//because we dont want to leave in any quotes in the filename, remove them now (with zero terminator)
commandLine[i] = 0;
break; }
case '\t': //also treat tab as whitespace
case ' ': {
isInWhiteSpace = true;
if (!isInFile)
commandLine[i] = 0; //zap spaces into zero terminators, unless its part of a filename
break; }
default: { //default TCHAR, if beginning of word, add it
if (!isInFile && isInWhiteSpace) {
paramVector.push_back(commandLine+i); //add next param
isInWhiteSpace = false;
}
break; }
}
}
//the commandline generic_string is now a list of zero terminated strings concatenated, and the vector contains all the substrings
}