本文整理汇总了C++中StringVec类的典型用法代码示例。如果您正苦于以下问题:C++ StringVec类的具体用法?C++ StringVec怎么用?C++ StringVec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StringVec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseIntegerVec
bool parseIntegerVec(std::string str, IntegerVec& intVector)
{
StringVec strVector = explodeString(str, ";");
IntegerVec tmpIntVector;
for(StringVec::iterator it = strVector.begin(); it != strVector.end(); ++it)
{
tmpIntVector = vectorAtoi(explodeString((*it), "-"));
if(!tmpIntVector[0] && it->substr(0, 1) != "0")
continue;
intVector.push_back(tmpIntVector[0]);
if(tmpIntVector.size() > 1)
{
while(tmpIntVector[0] < tmpIntVector[1])
intVector.push_back(++tmpIntVector[0]);
}
}
return true;
}
示例2: Split
//---------------------------------------------------------------------------------------------------------------------
// This is basically like the Perl split() function. It splits str into substrings by cutting it at each delimiter.
// The result is stored in vec.
//---------------------------------------------------------------------------------------------------------------------
void Split(const string& str, StringVec& vec, char delimiter)
{
vec.clear();
size_t strLen = str.size();
if (strLen == 0)
return;
size_t startIndex = 0;
size_t indexOfDel = str.find_first_of(delimiter, startIndex);
while (indexOfDel != string::npos)
{
vec.push_back(str.substr(startIndex, indexOfDel - startIndex));
startIndex = indexOfDel + 1;
if (startIndex >= strLen)
break;
indexOfDel = str.find_first_of(delimiter, startIndex);
}
if (startIndex < strLen)
vec.push_back(str.substr(startIndex));
}
示例3: expandRecursivePath
static String expandRecursivePath(const String& path, const String& prefix, const VariableCollectionHierarchy& vch) {
// Check if recursive expansion is necessary
if (!strEndsWith(path, "/**"))
return addPrefixQuoted(path, prefix, vch);
// Remove the pesky /** ending
String fixedPath = path.substr(0, path.length() - 3);
// Expand the path and get an absolute project path
String expandedPath = vch.expand(fixedPath);
String projectPath = vch.getValue("PROJECT_DIR");
// Make an absolute path
String absPath = joinPaths(projectPath, expandedPath);
// Get a list of subdirectories to ignore
StringVec ignoreList;
vch.getValue("EXCLUDED_RECURSIVE_SEARCH_PATH_SUBDIRECTORIES", ignoreList);
// Get recursive paths
StringVec dirVec;
getRecursiveDirList(absPath, dirVec, ignoreList);
// Sort the paths such that they are in breadth-first, alphabetic order
std::sort(dirVec.begin(), dirVec.end(), compare_nocase_breadth_first);
// Substitute back the original form of the path (which likely contains variables)
String ret;
for (unsigned i = 0; i < dirVec.size(); i++) {
dirVec[i].replace(0, absPath.length(), fixedPath);
ret += addPrefixQuoted(dirVec[i], prefix, vch);
}
// Check that the recursive expansion succeeded
if (dirVec.empty()) {
SBLog::info() << "Failed recursive expansion of \"" << absPath << "\". Path does not exist." << std::endl;
return "";
} else {
return ret;
}
}
示例4: proc_tags
const std::tuple<bool, std::string, StringVec> proc_tags(const std::string& tags) {
bool suggest = false;
std::string errtype;
StringVec gentags;
for(auto& tag : split(tags)) {
std::match_results<const char*> result;
std::regex_match(tag.c_str(), result, CG_SKIP_TAG);
if (result.empty()) {
gentags.push_back(tag);
}
else if(result[2].length() != 0) {
if(tag == CG_SUGGEST_TAG) {
suggest = true;
}
else {
errtype = result[2];
}
}
}
return std::make_tuple(suggest, errtype, gentags);
}
示例5: Tokenize
/** check whether a file exists */
bool ParameterNBest::FilesExist(const string ¶mName, size_t tokenizeIndex,std::vector<std::string> const& extensions)
{
typedef std::vector<std::string> StringVec;
StringVec::const_iterator iter;
PARAM_MAP::const_iterator iterParam = m_setting.find(paramName);
if (iterParam == m_setting.end())
{ // no param. therefore nothing to check
return true;
}
const StringVec &pathVec = (*iterParam).second;
for (iter = pathVec.begin() ; iter != pathVec.end() ; ++iter)
{
StringVec vec = Tokenize(*iter);
if (tokenizeIndex >= vec.size())
{
stringstream errorMsg("");
errorMsg << "Expected at least " << (tokenizeIndex+1) << " tokens per emtry in '"
<< paramName << "', but only found "
<< vec.size();
UserMessage::Add(errorMsg.str());
return false;
}
const string &pathStr = vec[tokenizeIndex];
bool fileFound=0;
for(size_t i=0;i<extensions.size() && !fileFound;++i)
{
fileFound|=FileExists(pathStr + extensions[i]);
}
if(!fileFound)
{
stringstream errorMsg("");
errorMsg << "File " << pathStr << " does not exist";
UserMessage::Add(errorMsg.str());
return false;
}
}
return true;
}
示例6: parseVocationString
std::string parseVocationString(StringVec vocStringVec)
{
std::string str = "";
if(!vocStringVec.empty())
{
for(StringVec::iterator it = vocStringVec.begin(); it != vocStringVec.end(); ++it)
{
if((*it) != vocStringVec.front())
{
if((*it) != vocStringVec.back())
str += ", ";
else
str += " and ";
}
str += (*it);
str += "s";
}
}
return str;
}
示例7: explodeString
StringVec explodeString(const std::string& string, const std::string& separator, bool trim/* = true*/, uint16_t limit/* = 0*/)
{
StringVec returnVector;
size_t start = 0, end = 0;
uint16_t i = 1;
while((end = string.find(separator, start)) != std::string::npos)
{
std::string t = string.substr(start, end - start);
if(trim)
trimString(t);
returnVector.push_back(t);
start = end + separator.size();
++i;
if(limit > 0 && i > limit)
break;
}
returnVector.push_back(string.substr(start));
return returnVector;
}
示例8: ban
void Spectators::ban(StringVec _bans)
{
StringVec::const_iterator it;
for(DataList::iterator bit = bans.begin(); bit != bans.end(); )
{
it = std::find(_bans.begin(), _bans.end(), bit->first);
if(it == _bans.end())
bans.erase(bit++);
else
++bit;
}
for(it = _bans.begin(); it != _bans.end(); ++it)
{
for(SpectatorList::const_iterator sit = spectators.begin(); sit != spectators.end(); ++sit)
{
if(asLowerCaseString(sit->second.first) != *it)
continue;
bans[*it] = sit->first->getIP();
sit->first->disconnect();
}
}
}
示例9: replaceWlArgs
// "Expand" -Wl and -Xlinker tokens
// This is OK to do since we're interested in a small subset of flags.
// Preserving correctness is not important.
static void replaceWlArgs(const StringVec& inArgs, StringVec& outArgs) {
for (auto arg : inArgs) {
if (strBeginsWith(arg, "-Wl,")) {
StringVec tokens;
tokenize(arg, tokens, ",", "", "", "", "");
outArgs.insert(outArgs.end(), tokens.begin() + 1, tokens.end());
} else if (arg != "-Xlinker") {
outArgs.push_back(arg);
}
}
}
示例10: getMountInfo
MountInfoVec getMountInfo()
{
int exitCode;
StringVec tcOutput = splitToLines(executeCommand("truecrypt", "-l", exitCode));
if(exitCode != 0)
{
if(tcOutput.size() > 0)
{
throw std::runtime_error(tcOutput[0]);
}
else
{
throw std::runtime_error("unknown error while querying mounted images");
}
}
StringVec mntOutput = splitToLines(executeCommand("mount", exitCode));
MountInfoVec info;
for(StringVec::const_iterator tcIt = tcOutput.begin(); tcIt != tcOutput.end(); ++tcIt)
{
StringVec tcWords = splitToWords(*tcIt);
std::string device = tcWords[0];
std::string image = tcWords[1];
for(StringVec::const_iterator mntIt = mntOutput.begin(); mntIt != mntOutput.end(); ++mntIt)
{
StringVec mntWords = splitToWords(*mntIt);
std::string mntDev = mntWords[0];
std::string mntPoint = mntWords[2];
if(mntDev == device)
{
info.push_back(MountInfo(image, mntPoint));
break;
}
}
}
return info;
}
示例11: EVAL
malValuePtr EVAL(malValuePtr ast, malEnvPtr env)
{
if (!env) {
env = replEnv;
}
while (1) {
const malList* list = DYNAMIC_CAST(malList, ast);
if (!list || (list->count() == 0)) {
return ast->eval(env);
}
ast = macroExpand(ast, env);
list = DYNAMIC_CAST(malList, ast);
if (!list || (list->count() == 0)) {
return ast->eval(env);
}
// From here on down we are evaluating a non-empty list.
// First handle the special forms.
if (const malSymbol* symbol = DYNAMIC_CAST(malSymbol, list->item(0))) {
String special = symbol->value();
int argCount = list->count() - 1;
if (special == "def!") {
checkArgsIs("def!", 2, argCount);
const malSymbol* id = VALUE_CAST(malSymbol, list->item(1));
return env->set(id->value(), EVAL(list->item(2), env));
}
if (special == "defmacro!") {
checkArgsIs("defmacro!", 2, argCount);
const malSymbol* id = VALUE_CAST(malSymbol, list->item(1));
malValuePtr body = EVAL(list->item(2), env);
const malLambda* lambda = VALUE_CAST(malLambda, body);
return env->set(id->value(), mal::macro(*lambda));
}
if (special == "do") {
checkArgsAtLeast("do", 1, argCount);
for (int i = 1; i < argCount; i++) {
EVAL(list->item(i), env);
}
ast = list->item(argCount);
continue; // TCO
}
if (special == "fn*") {
checkArgsIs("fn*", 2, argCount);
const malSequence* bindings =
VALUE_CAST(malSequence, list->item(1));
StringVec params;
for (int i = 0; i < bindings->count(); i++) {
const malSymbol* sym =
VALUE_CAST(malSymbol, bindings->item(i));
params.push_back(sym->value());
}
return mal::lambda(params, list->item(2), env);
}
if (special == "if") {
checkArgsBetween("if", 2, 3, argCount);
bool isTrue = EVAL(list->item(1), env)->isTrue();
if (!isTrue && (argCount == 2)) {
return mal::nilValue();
}
ast = list->item(isTrue ? 2 : 3);
continue; // TCO
}
if (special == "let*") {
checkArgsIs("let*", 2, argCount);
const malSequence* bindings =
VALUE_CAST(malSequence, list->item(1));
int count = checkArgsEven("let*", bindings->count());
malEnvPtr inner(new malEnv(env));
for (int i = 0; i < count; i += 2) {
const malSymbol* var =
VALUE_CAST(malSymbol, bindings->item(i));
inner->set(var->value(), EVAL(bindings->item(i+1), inner));
}
ast = list->item(2);
env = inner;
continue; // TCO
}
if (special == "macroexpand") {
checkArgsIs("macroexpand", 1, argCount);
return macroExpand(list->item(1), env);
}
if (special == "quasiquote") {
checkArgsIs("quasiquote", 1, argCount);
ast = quasiquote(list->item(1));
continue; // TCO
}
//.........这里部分代码省略.........
示例12: sb_dirname
void SBSourcesBuildPhase::writeVCProjectFiles(VCProject& proj) const
{
// We don't support source compilation when building bundles
TargetProductType productType = m_parentTarget.getProductType();
if (productType == TargetBundle)
{
if (!m_phase->getBuildFileList().empty()) {
SBLog::warning() << "Ignoring all source files in \"" << m_parentTarget.getName() << "\" bundle target." << std::endl;
}
return;
}
SBBuildPhase::writeVSFileDescriptions(proj, "Text");
String xcProjectDir = m_parentTarget.getProject().getProjectDir();
String vsProjectDir = sb_dirname(proj.getPath());
StringSet prefixHeaders;
for (auto bs : m_parentTarget.getBuildSettings()) {
VCProjectConfiguration* config = proj.addConfiguration(bs.first);
// Prefix header (recalculate relative path)
String prefixHeader = bs.second->getValue("GCC_PREFIX_HEADER");
if (!prefixHeader.empty()) {
String absHeaderPath = m_parentTarget.makeAbsolutePath(prefixHeader);
String relHeaderPath = m_parentTarget.makeRelativePath(prefixHeader, vsProjectDir);;
relHeaderPath = winPath(relHeaderPath);
config->setItemDefinition("ClangCompile", "PrefixHeader", relHeaderPath);
// Add plist file to project (only once)
if (prefixHeaders.find(absHeaderPath) == prefixHeaders.end()) {
addRelativeFilePathToVS("ClInclude", absHeaderPath, "", proj, *bs.second);
prefixHeaders.insert(absHeaderPath);
}
}
// Preprocessor definitions
StringVec preprocessorTokens;
bs.second->getValue("GCC_PREPROCESSOR_DEFINITIONS", preprocessorTokens);
String preprocessorDefs = joinStrings(preprocessorTokens, ";");
if (!preprocessorDefs.empty()) {
config->setItemDefinition("ClangCompile", "PreprocessorDefinitions", preprocessorDefs);
}
// Optimization level
String optimizationLevel = bs.second->getValue("GCC_OPTIMIZATION_LEVEL");
if (!optimizationLevel.empty()) {
String vsOptimizationLevel;
if (optimizationLevel == "s") {
vsOptimizationLevel = "MinSpace";
} else if (optimizationLevel == "0") {
vsOptimizationLevel = "Disabled";
} else {
vsOptimizationLevel = "MaxSpeed";
}
config->setItemDefinition("ClangCompile", "OptimizationLevel", vsOptimizationLevel);
}
// ARC
String enableARC = bs.second->getValue("CLANG_ENABLE_OBJC_ARC");
if (enableARC == "YES") {
config->setItemDefinition("ClangCompile", "ObjectiveCARC", "true");
}
// Modules
String enableModules = bs.second->getValue("CLANG_ENABLE_MODULES");
if (enableModules == "YES") {
config->setItemDefinition("ClangCompile", "ObjectiveCModules", "true");
}
// Header search paths (make them relative)
StringVec includePaths;
bs.second->getValue("HEADER_SEARCH_PATHS", includePaths);
for (auto &cur : includePaths) {
cur = m_parentTarget.makeRelativePath(cur, vsProjectDir);
cur = winPath(cur);
}
includePaths.insert(includePaths.begin(), "$(SolutionPublicHeadersDir)");
config->setItemDefinition("ClangCompile", "IncludePaths", joinStrings(includePaths, ";"));
// User header search paths (make them relative)
StringVec userIncludePaths;
bs.second->getValue("USER_HEADER_SEARCH_PATHS", userIncludePaths);
for (auto &cur : userIncludePaths) {
cur = m_parentTarget.makeRelativePath(cur, vsProjectDir);
cur = winPath(cur);
}
if (!userIncludePaths.empty()) {
config->setItemDefinition("ClangCompile", "UserIncludePaths", joinStrings(userIncludePaths, ";"));
}
// Exclude search path subdirectories
StringVec excludeSubDirectories;
bs.second->getValue("EXCLUDED_RECURSIVE_SEARCH_PATH_SUBDIRECTORIES", excludeSubDirectories);
if (!excludeSubDirectories.empty()) {
config->setItemDefinition("ClangCompile", "ExcludedSearchPathSubdirectories", joinStrings(excludeSubDirectories, ";"));
}
// Header map
if (bs.second->getValue("USE_HEADERMAP") == "YES") {
if (bs.second->getValue("ALWAYS_SEARCH_USER_PATHS") == "YES") {
//.........这里部分代码省略.........
示例13: INSTANCE_METHOD_INJECTION_BUILTIN
Variant c_DebuggerClient::t_processcmd(CVarRef cmdName, CVarRef args) {
INSTANCE_METHOD_INJECTION_BUILTIN(DebuggerClient, DebuggerClient::processcmd);
if (!m_client ||
m_client->getClientState() < DebuggerClient::StateReadyForCommand) {
raise_warning("client is not initialized");
return null;
}
if (m_client->getClientState() != DebuggerClient::StateReadyForCommand) {
raise_warning("client is not ready to take command");
return null;
}
if (!cmdName.isString()) {
raise_warning("cmdName must be string");
return null;
}
if (!args.isNull() && !args.isArray()) {
raise_warning("args must be null or array");
return null;
}
static const char *s_allowedCmds[] = {
"break", "continue", "down", "exception", "frame", "global",
"help", "info", "konstant", "next", "out", "print", "quit", "step",
"up", "variable", "where", "bt", "set", "inst", "=", "@", NULL
};
bool allowed = false;
for (int i = 0; ; i++) {
const char *cmd = s_allowedCmds[i];
if (cmd == NULL) {
break;
}
if (cmdName.same(cmd)) {
allowed = true;
break;
}
}
if (!allowed) {
raise_warning("unsupported command %s", cmdName.toString().data());
return null;
}
m_client->setCommand(cmdName.toString().data());
StringVec *clientArgs = m_client->args();
clientArgs->clear();
if (!args.isNull()) {
for (ArrayIter iter(args.toArray()); iter; ++iter) {
CStrRef arg = iter.second().toString();
clientArgs->push_back(std::string(arg.data(), arg.size()));
}
}
try {
if (!m_client->process()) {
raise_warning("command \"%s\" not found", cmdName.toString().data());
}
} catch (DebuggerConsoleExitException &e) {
// Flow-control command goes here
Logger::Info("wait for debugger client to stop");
m_client->setTakingInterrupt();
m_client->setClientState(DebuggerClient::StateBusy);
DebuggerCommandPtr cmd = m_client->waitForNextInterrupt();
if (!cmd) {
raise_warning("not getting a command");
} else if (cmd->is(DebuggerCommand::KindOfInterrupt)) {
CmdInterruptPtr cmdInterrupt = dynamic_pointer_cast<CmdInterrupt>(cmd);
cmdInterrupt->onClientD(m_client);
} else {
// Previous pending commands
cmd->handleReply(m_client);
cmd->setClientOutput(m_client);
}
Logger::Info("debugger client ready for command");
} catch (DebuggerClientExitException &e) {
const std::string& nameStr = m_client->getNameApi();
Logger::Info("client %s disconnected", nameStr.c_str());
s_dbgCltMap.erase(nameStr);
delete m_client;
m_client = NULL;
return true;
} catch (DebuggerProtocolException &e) {
raise_warning("DebuggerProtocolException");
return null;
}
return m_client->getOutputArray();
}
示例14: parseVocationNode
bool parseVocationNode(xmlNodePtr vocationNode, VocationMap& vocationMap, StringVec& vocStringVec, std::string& errorStr)
{
if(xmlStrcmp(vocationNode->name,(const xmlChar*)"vocation"))
return true;
int32_t vocationId = -1;
std::string strValue, tmpStrValue;
if(readXMLString(vocationNode, "name", strValue))
{
vocationId = Vocations::getInstance()->getVocationId(strValue);
if(vocationId != -1)
{
vocationMap[vocationId] = true;
int32_t promotedVocation = Vocations::getInstance()->getPromotedVocation(vocationId);
if(promotedVocation != -1)
vocationMap[promotedVocation] = true;
}
else
{
errorStr = "Wrong vocation name: " + strValue;
return false;
}
}
else if(readXMLString(vocationNode, "id", strValue))
{
IntegerVec intVector;
if(!parseIntegerVec(strValue, intVector))
{
errorStr = "Invalid vocation id - '" + strValue + "'";
return false;
}
size_t size = intVector.size();
for(size_t i = 0; i < size; ++i)
{
Vocation* vocation = Vocations::getInstance()->getVocation(intVector[i]);
if(vocation && vocation->getName() != "")
{
vocationId = vocation->getId();
strValue = vocation->getName();
vocationMap[vocationId] = true;
int32_t promotedVocation = Vocations::getInstance()->getPromotedVocation(vocationId);
if(promotedVocation != -1)
vocationMap[promotedVocation] = true;
}
else
{
std::stringstream ss;
ss << "Wrong vocation id: " << intVector[i];
errorStr = ss.str();
return false;
}
}
}
if(vocationId != -1 && (!readXMLString(vocationNode, "showInDescription", tmpStrValue) || booleanString(tmpStrValue)))
vocStringVec.push_back(asLowerCaseString(strValue));
return true;
}
示例15:
void MacAddrSuite::testVec00()
{
bool ok = true;
MacAddr macAddr;
MacAddrVec vec0;
String mac;
StringVec macs;
for (unsigned int i = 0; i < NUM_SAMPLES; ++i)
{
const sample_t& r = SAMPLE[i];
if (r.isValid)
{
macAddr = r.addr;
unsigned int foundAt = vec0.numItems();
if ((!vec0.add(macAddr)) || (vec0.findIndex(macAddr) != foundAt))
{
ok = false;
break;
}
mac = macAddr;
macs.add(mac);
}
}
CPPUNIT_ASSERT(ok);
MacAddrVec vec1(vec0);
ok = (vec1 == vec0);
CPPUNIT_ASSERT(ok);
vec1.reset();
ok = (vec1 != vec0) && (vec1.numItems() == 0);
CPPUNIT_ASSERT(ok);
ok = vec1.reset(macs) && (vec1 == vec0);
CPPUNIT_ASSERT(ok);
mac = "not-a-mac";
macs.add(mac);
ok = (!vec1.reset(macs)) && (vec1 == vec0);
CPPUNIT_ASSERT(ok);
bool reverseOrder = false;
vec0.sort(reverseOrder);
ok = vec1.find(vec0.peek(0));
CPPUNIT_ASSERT(ok);
for (size_t i = 1, numItems = vec0.numItems(); i < numItems; ++i)
{
if ((!vec1.find(vec0.peek(i))) || (vec0.peek(i - 1) > vec0.peek(i)))
{
ok = false;
break;
}
}
CPPUNIT_ASSERT(ok);
reverseOrder = true;
vec0.sort(reverseOrder);
ok = vec1.find(vec0.peek(0));
CPPUNIT_ASSERT(ok);
for (size_t i = 1, numItems = vec0.numItems(); i < numItems; ++i)
{
if ((!vec1.find(vec0.peek(i))) || (vec0.peek(i - 1) < vec0.peek(i)))
{
ok = false;
break;
}
}
CPPUNIT_ASSERT(ok);
}