本文整理汇总了C++中string::CPtr::concat方法的典型用法代码示例。如果您正苦于以下问题:C++ CPtr::concat方法的具体用法?C++ CPtr::concat怎么用?C++ CPtr::concat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类string::CPtr
的用法示例。
在下文中一共展示了CPtr::concat方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
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")));
}
示例2: parse
JsObject::Ptr parse(String::CPtr urlStr) {
static const String::CPtr colon = String::create(":");
static const String::CPtr slash = String::create("/");
static const String::CPtr sharp = String::create("#");
static const String::CPtr question = String::create("?");
if (!urlStr) {
LIBJ_NULL_PTR(JsObject, nullp);
return nullp;
}
struct parsed_url* url = parse_url(urlStr->toStdString().c_str());
JsObject::Ptr obj = JsObject::create();
obj->put(HREF, urlStr);
if (url->scheme) {
obj->put(PROTOCOL, String::create(url->scheme)->toLowerCase());
}
LIBJ_NULL_CPTR(String, port);
if (url->port) {
port = String::create(url->port);
obj->put(PORT, port);
}
if (url->host) {
String::CPtr hostname = String::create(url->host)->toLowerCase();
obj->put(HOSTNAME, hostname);
if (port) {
obj->put(HOST, hostname->concat(colon)->concat(port));
} else {
obj->put(HOST, hostname);
}
}
LIBJ_NULL_CPTR(String, query);
if (url->query) {
query = String::create(url->query);
obj->put(QUERY, query);
}
if (url->path) {
String::CPtr pathname = slash->concat(String::create(url->path));
obj->put(PATHNAME, pathname);
if (query) {
obj->put(PATH, pathname->concat(question)->concat(query));
} else {
obj->put(PATH, pathname);
}
}
if (url->username && url->password) {
String::CPtr auth = String::create(url->username);
auth = auth->concat(colon);
auth = auth->concat(String::create(url->password));
obj->put(AUTH, auth);
}
if (url->fragment) {
String::CPtr hash = sharp->concat(String::create(url->fragment));
obj->put(HASH, hash);
}
parsed_url_free(url);
return obj;
}
示例3:
TEST(GTestStringBuffer, TestAppendManyTimes) {
const char a[] = "abcde";
const char u[] = {
0xe7, 0x8c, 0xab, 0xe3, 0x81, 0xa8, 0xe6, 0x9a,
0xae, 0xe3, 0x82, 0x89, 0xe3, 0x81, 0x97, 0xe3,
0x81, 0x9f, 0xe3, 0x81, 0x84, // 猫と暮らしたい
0
};
String::CPtr s1 = String::create(a);
String::CPtr s2 = String::create(u, String::UTF8);
String::CPtr exp = String::create("");
StringBuffer::Ptr sb = StringBuffer::create();
for (int i = 0; i < 100; i++) {
sb->append(s1);
sb->append(s2);
exp = exp->concat(s1)->concat(s2);
}
ASSERT_TRUE(sb->toString()->equals(exp));
}