本文整理汇总了C++中StringVec::add方法的典型用法代码示例。如果您正苦于以下问题:C++ StringVec::add方法的具体用法?C++ StringVec::add怎么用?C++ StringVec::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringVec
的用法示例。
在下文中一共展示了StringVec::add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doEnv
//
// env [--expandEnv]
//
bool MiscDbugCmd::doEnv(const CmdLine& req)
{
wchar_t* envW = GetEnvironmentStringsW();
StringVec env;
String optK("expandEnv");
bool expandEnv = Bool(req.opt(optK), false /*defaultV*/);
DelimitedTxt txt(EQUALS_SIGN);
String k;
String kv;
String v;
for (const wchar_t* w = envW; *w;)
{
kv = w;
txt.setTxt(kv, false /*makeCopy*/);
(txt.next(k, true /*doTrimLine*/) && getenv(k, v, expandEnv))?
env.add(k + EQUALS_SIGN + v):
env.add(kv);
size_t n = wcslen(w);
w += n + 1;
}
FreeEnvironmentStringsW(envW);
env.sort();
String rsp(env.stringify(NEW_LINE));
respond(req, rsp);
bool cmdIsValid = true;
return cmdIsValid;
}
示例2:
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);
}