本文整理汇总了C++中string::CPtr类的典型用法代码示例。如果您正苦于以下问题:C++ CPtr类的具体用法?C++ CPtr怎么用?C++ CPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST(GTestXmlDom, TestElement) {
Document::CPtr doc = Document::parse(sample);
ASSERT_TRUE(!doc->asAttr());
ASSERT_TRUE(!doc->asElement());
ASSERT_TRUE(!!doc->asDocument());
Node::CPtr node = doc->firstChild();
ASSERT_TRUE(!node->asAttr());
ASSERT_TRUE(!!node->asElement());
ASSERT_TRUE(!node->asDocument());
Element::CPtr element = node->asElement();
String::CPtr tag = element->tagName();
String::CPtr attrVal1 = element->getAttribute(String::create("name"));
String::CPtr attrVal2 = element->getAttribute(String::create("foo"));
String::CPtr attrVal3 = element->getAttribute(String::null());
ASSERT_TRUE(tag->equals(String::create("team")));
ASSERT_TRUE(attrVal1->equals(String::create("foo")));
ASSERT_TRUE(attrVal2->equals(String::create()));
ASSERT_TRUE(!attrVal3);
ASSERT_TRUE(element->hasAttribute(String::create("name")));
ASSERT_FALSE(element->hasAttribute(String::create("foo")));
ASSERT_FALSE(element->hasAttribute(String::null()));
Attr::CPtr attr1 = element->getAttributeNode(String::create("name"));
Attr::CPtr attr2 = element->getAttributeNode(String::create("foo"));
Attr::CPtr attr3 = element->getAttributeNode(String::null());
ASSERT_TRUE(!!attr1);
ASSERT_TRUE(!attr2);
ASSERT_TRUE(!attr3);
}
示例2: resolve
String::CPtr resolve(JsArray::CPtr paths) {
const Size kMax = 8192;
char dir[kMax];
char* r = getcwd(dir, kMax);
if (!r) return String::null();
if (!paths) return String::create(dir);
StringBuilder::Ptr resolved = StringBuilder::create();
resolved->appendStr(dir);
Size len = paths->length();
for (Size i = 0; i < len; i++) {
String::CPtr path = paths->getCPtr<String>(i);
if (path) {
if (isSep(path->charAt(0))) {
resolved = StringBuilder::create();
#ifdef LIBJ_PF_WINDOWS
// append the drive letter
resolved->appendChar(dir[0]);
resolved->appendChar(dir[1]);
} else if (isAlpha(path->charAt(0)) && path->charAt(1) == ':') {
resolved = StringBuilder::create();
#endif
} else if (!path->isEmpty()) {
resolved->appendChar(SEP);
}
resolved->appendStr(path);
}
}
return trimSeps(normalize(resolved->toString()));
}
示例3: percentDecode
String::CPtr percentDecode(String::CPtr str, String::Encoding enc) {
if (!str || str->isEmpty())
return String::create();
Size len = str->length() + 1;
char* decoded = new char[len];
Size size = percentDecode(decoded, len, str->toStdString().c_str());
String::CPtr res;
switch (enc) {
case String::UTF8:
res = String::create(decoded, enc, size);
break;
case String::UTF16:
case String::UTF16BE:
case String::UTF16LE:
res = String::create(decoded, enc, size >> 1);
break;
case String::UTF32:
case String::UTF32BE:
case String::UTF32LE:
res = String::create(decoded, enc, size >> 2);
break;
default:
assert(false);
res = String::null();
}
delete[] decoded;
return res;
}
示例4: log
Boolean log(const Value& val) {
String::CPtr s = String::valueOf(val);
if (!s)
return false;
std::cout << s->toStdString() << std::endl;
return true;
}
示例5: indexOfSep
static inline Size indexOfSep(String::CPtr str, Size from) {
assert(str);
Size len = str->length();
for (Size i = from; i < len; i++) {
if (isSep(str->charAt(i))) return i;
}
return NO_POS;
}
示例6:
TEST(GTestJsClosure, TestClosure2) {
String::CPtr abc = String::create("abc");
String::CPtr xyz = String::create("xyz");
JsClosure::Ptr concat = JsClosure::create(
[abc, xyz] (JsArray::Ptr args) -> Value {
return abc->concat(xyz);
});
ASSERT_TRUE(concat->call().equals(String::create("abcxyz")));
}
示例7: error
Boolean error(const Value& val) {
if (val.isUndefined() || !isPrintable(LEVEL_ERROR))
return false;
String::CPtr s = toString(val);
if (s) {
error(s->toStdString().c_str());
return true;
} else {
return false;
}
}
示例8: warn
Boolean warn(const Value& val) {
if (val.isUndefined() || !isPrintable(LEVEL_WARNING))
return false;
String::CPtr s = toString(val);
if (s) {
warn(s->toStdString().c_str());
return true;
} else {
return false;
}
}
示例9: log
Boolean log(const Value& val) {
if (val.isUndefined() || !isPrintable(LEVEL_NORMAL))
return false;
String::CPtr s = toString(val);
if (s) {
log(s->toStdString().c_str());
return true;
} else {
return false;
}
}
示例10: extname
String::CPtr extname(String::CPtr path) {
if (!path) return String::create();
String::CPtr base = basename(path);
if (base->charAt(0) == '.') return String::create();
Size lastIndex = base->lastIndexOf('.');
if (lastIndex == NO_POS) {
return String::create();
} else {
return base->substring(lastIndex);
}
}
示例11:
TEST(GTestValue, TestTo10) {
Value v = String::create("abc");
String::CPtr s;
ASSERT_TRUE(to<String::CPtr>(v, &s));
ASSERT_TRUE(s->equals(String::create("abc")));
Immutable::CPtr i1;
ASSERT_FALSE(to<Immutable::CPtr>(v, &i1));
Immutable::CPtr i2 = String::create("123");
v = i2;
Immutable::CPtr i3;
ASSERT_TRUE(to<Immutable::CPtr>(v, &i3));
ASSERT_TRUE(i3->equals(String::create("123")));
}
示例12:
TEST(GTestStringBuffer, TestToStdString) {
const char u[] = {
0xe3, 0x81, 0x82,
0xe3, 0x81, 0x84,
0xe3, 0x81, 0x86,
0
};
String::CPtr s = String::create(u, String::UTF8);
StringBuffer::Ptr sb = StringBuffer::create(s);
ASSERT_EQ(s->toStdString(String::UTF8), sb->toStdString());
ASSERT_EQ(s->toStdString(String::UTF16), sb->toStdString(String::UTF16));
ASSERT_EQ(s->toStdString(String::UTF32), sb->toStdString(String::UTF32));
}
示例13:
TEST(GTestJsRegExp, TestExec) {
JsRegExp::Ptr re = JsRegExp::create(String::create("a+(b*)(c)"));
JsArray::Ptr a = re->exec(String::create("xaacz"));
ASSERT_EQ(3, a->length());
ASSERT_TRUE(toCPtr<String>(a->get(0))->equals(String::create("aac")));
ASSERT_TRUE(a->get(1).isUndefined());
ASSERT_TRUE(toCPtr<String>(a->get(2))->equals(String::create("c")));
Int index = -1;
to<Int>(a->getProperty(String::create("index")), &index);
ASSERT_EQ(1, index);
String::CPtr input =
toCPtr<String>(a->getProperty(String::create("input")));
ASSERT_TRUE(input->equals(String::create("xaacz")));
ASSERT_FALSE(re->exec(String::create("bc")));
}
示例14: lastIndexOfSep
static inline Size lastIndexOfSep(String::CPtr str, Size from = NO_POS) {
assert(str);
Size len = str->length();
if (!len) return NO_POS;
if (from >= len) from = len - 1;
Size i = from;
while (1) {
if (isSep(str->charAt(i))) return i;
if (i) {
i--;
} else {
break;
}
}
return NO_POS;
}
示例15: trimSeps
static inline String::CPtr trimSeps(String::CPtr str) {
assert(str);
Size len = str->length();
if (!len) return str;
Size i = len - 1;
while (1) {
if (!isSep(str->charAt(i))) {
return str->substring(0, i + 1);
}
if (i) {
i--;
} else {
break;
}
}
return str->substring(0, 1);
}