本文整理汇总了C++中string::CPtr::equals方法的典型用法代码示例。如果您正苦于以下问题:C++ CPtr::equals方法的具体用法?C++ CPtr::equals怎么用?C++ CPtr::equals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类string::CPtr
的用法示例。
在下文中一共展示了CPtr::equals方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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:
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")));
}
示例3:
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")));
}
示例4: normalize
String::CPtr normalize(String::CPtr path) {
LIBJ_STATIC_SYMBOL_DEF(symCurrent, ".");
LIBJ_STATIC_SYMBOL_DEF(symParent, "..");
LIBJ_STATIC_SYMBOL_DEF(symNull, "null");
if (!path) return symNull;
Boolean absolute = false;
Boolean endsWithSep = false;
typedef TypedJsArray<String::CPtr> StringArray;
StringArray::Ptr dirs = StringArray::create();
Size len = path->length();
for (Size i = 0; i < len;) {
Size idx = indexOfSep(path, i);
if (idx == 0) {
absolute = true;
} else if (idx != i) {
String::CPtr dir;
if (idx == NO_POS) {
dir = path->substring(i);
} else {
dir = path->substring(i, idx);
}
if (dir->equals(symParent)) {
Size numDirs = dirs->size();
if (numDirs > 0 &&
!dirs->getTyped(numDirs - 1)->equals(symParent)) {
dirs->removeTyped(numDirs - 1);
} else {
dirs->addTyped(dir);
}
} else if (!dir->equals(symCurrent)) {
dirs->addTyped(dir);
}
}
if (idx == NO_POS) {
endsWithSep = false;
i = len;
} else {
endsWithSep = true;
i = idx + 1;
}
}
StringBuilder::Ptr normal = StringBuilder::create();
if (absolute)
normal->appendChar(SEP);
Size numDirs = dirs->size();
for (Size i = 0; i < numDirs; i++) {
if (i) normal->appendChar(SEP);
normal->appendStr(dirs->getTyped(i));
}
if (numDirs > 0 && endsWithSep)
normal->appendChar(SEP);
if (normal->length() == 0) {
return symCurrent;
} else {
return normal->toString();
}
}
示例5:
TEST(GTestQueryString, TestStringify) {
JsObject::Ptr obj = JsObject::create();
String::CPtr query = querystring::stringify(obj);
ASSERT_TRUE(query->equals(String::create()));
obj = JsObject::create();
obj->put(String::create("a"), String::create("b"));
query = querystring::stringify(obj);
ASSERT_TRUE(query->equals(String::create("a=b")));
obj = JsObject::create();
obj->put(String::create("a"), String::create("b"));
obj->put(String::create("x"), 1);
query = querystring::stringify(obj);
ASSERT_TRUE(query->equals(String::create("a=b&x=1")));
obj = JsObject::create();
obj->put(String::create("a"), JsObject::create());
query = querystring::stringify(obj);
ASSERT_TRUE(query->equals(String::create("a=")));
obj = JsObject::create();
obj->put(String::create("a"), JsArray::create());
query = querystring::stringify(obj);
ASSERT_TRUE(query->equals(String::create()));
obj = JsObject::create();
obj->put(String::create("a"), Object::null());
query = querystring::stringify(obj);
ASSERT_TRUE(query->equals(String::create("a=")));
obj = JsObject::create();
obj->put(String::create("a"), UNDEFINED);
query = querystring::stringify(obj);
ASSERT_TRUE(query->equals(String::create("a=")));
obj = JsObject::create();
obj->put(String::create(), String::create());
query = querystring::stringify(obj);
ASSERT_TRUE(query->equals(String::create("=")));
obj = JsObject::create();
obj->put(Object::null(), Object::null());
query = querystring::stringify(obj);
ASSERT_TRUE(query->equals(String::create("null=")));
obj = JsObject::create();
JsArray::Ptr ary = JsArray::create();
ary->add(String::create("xyz"));
ary->add(123);
obj->put(UNDEFINED, ary);
query = querystring::stringify(obj);
ASSERT_TRUE(query->equals(
String::create("undefined=xyz&undefined=123")));
obj = JsObject::create();
obj->put(String::create(" "), String::create(" "));
query = querystring::stringify(obj);
ASSERT_TRUE(query->equals(String::create("%20=%20")));
}