本文整理汇总了C++中sid::String::toBinary方法的典型用法代码示例。如果您正苦于以下问题:C++ String::toBinary方法的具体用法?C++ String::toBinary怎么用?C++ String::toBinary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sid::String
的用法示例。
在下文中一共展示了String::toBinary方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkToBinary
void checkToBinary(const Sid::String& test, const char* expected, size_t expectedSize)
{
const char* origData = test.data();
char* res = new char[test.size()+1];
size_t size = test.toBinary(res);
CPPUNIT_ASSERT_PRINTF(size == expectedSize,
"toBinary() yielded a result that was too long, "
"expected %u, got %u\n",
expectedSize,
size);
CPPUNIT_ASSERT_PRINTF(!memcmp(expected, res, size),
"%s",
"toBinary() yielded unexpected result\n");
CPPUNIT_ASSERT_MESSAGE("toBinary() causes object to relinquish its reference!",
origData == test.data());
}
示例2: escapingAndUnescapingTest
void StringTestCase::escapingAndUnescapingTest()
{
checkEscaping(Sid::String(), Sid::String());
checkEscaping(Sid::String(4), "");
checkEscaping("", "");
checkEscaping(",", "\\,");
checkEscaping("\"", "\\\"");
checkEscaping("\\", "\\\\");
checkEscaping("foobar", "foobar");
checkEscaping("foo,bar", "foo\\,bar");
checkEscaping("foo\"bar", "foo\\\"bar");
checkEscaping("foo\\bar", "foo\\\\bar");
checkEscaping(",,", "\\,\\,");
checkEscaping("\"\"", "\\\"\\\"");
checkEscaping("\\\\", "\\\\\\\\");
checkUnescaping("\\", "");
checkUnescaping("foo\\bar", "foobar");
checkUnescaping("\\foobar", "foobar");
checkUnescaping("foobar\\", "foobar");
// .bwc. This code came from an #ifdef SE_STRING_TEST_PROGRAM block in
// skype_string.cpp.
int i;
Sid::String strings[] = {
"Hello World!",
"Hel,lo\\ World!",
"Hel\"lo Wo\\9rld!",
"Hel,lo Wo\\0rld!",
Sid::String()
};
for (i = 0; !strings[i].isNull(); i++) {
Sid::String escaped = strings[i].escape();
Sid::String unescaped = escaped.unescape();
CPPUNIT_ASSERT_PRINTF( !strcmp((const char*)strings[i], (const char*)unescaped),
"String Failed:\n%s\n%s\n%s\n\n",
(const char*)strings[i],
(const char*)escaped,
(const char*)unescaped);
}
// 0x5c = '\\', 0x30 = '0', 0x00 = 0, 0x22 = '"'
const char bins[] = {
'1', '2', '3', '4', '5', '6', '7', '8' ,
'1', '2', 0x5c, 0x30, '5', '6', '7', '8' ,
'1', '2', 0x5c, 0x30, 0x5c, 0x5c, 0x5c, '8' ,
'1', '2', 0x5c, 0x30, '5', '6', '7', '8' ,
'1', '2', 0x00, '4', '5', '6', '7', '8' ,
'1', 0x5c, 0x00, 0x5c, '5', '6', 0x5c, 0x5c ,
'1', 0x5c, 0x00, 0x00, '5', 0x00, 0x5c, '8' ,
0x00, '2', 0x5c, 0x30, '5', 0x22, 0x22, '8' ,
0x5c, '2', 0x5c, 0x30, '5', 0x22, 0x22, 0x00 ,
0x00, 0x00, 0x5c, 0x30, '5', 0x22, 0x22, 0x5c ,
'E'
};
size_t bins_len = 8;
for (i = 0; bins[i] != 'E'; i += bins_len) {
Sid::String escaped = Sid::String::from((char*)(bins + i), bins_len);
char *unescaped = (char *)malloc(escaped.length());
size_t unescaped_len = escaped.toBinary(unescaped);
//printf("%d, escaped.length()=%d unescaped_len=%d\n", i/bins_len, escaped.length(), unescaped_len);
CPPUNIT_ASSERT_PRINTF ( !memcmp((char*)(bins + i), unescaped, bins_len) && (unescaped_len == bins_len),
"Binary Failed: index %d\n",
i/bins_len);
//printf("%s\n", (const char*)escaped.getHexRepresentation());
free(unescaped);
}
{
Sid::String test("foo");
test.markAsBinary();
CPPUNIT_ASSERT_PRINTF(test.isBinary(),
"%s", "markAsBinary() seems "
"to have no effect.\n");
}
}