⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 string.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        const char*  tmp2 = (const char *)temp2;        PEGASUS_TEST_ASSERT(utf16string == utf8string);        PEGASUS_TEST_ASSERT(utf16string == utf16merge);        PEGASUS_TEST_ASSERT(utf16string == utf16chr);        PEGASUS_TEST_ASSERT(utf8string  == utf16chr);        PEGASUS_TEST_ASSERT(memcmp(utf8string.getChar16Data(),utf16string.getChar16Data(),sizeof(utf16chr)) == 0);        PEGASUS_TEST_ASSERT(strcmp(utf8string.getCString(),utf8chr) == 0);        PEGASUS_TEST_ASSERT(strcmp(utf16string.getCString(),utf8chr) == 0);        PEGASUS_TEST_ASSERT(strcmp(tmp,utf8chr) == 0);        PEGASUS_TEST_ASSERT(strcmp(tmp2,utf8chr) == 0);        Uint32 count = 0;        Uint32 size = sizeof(utf8chr);        while(count<size)        {                PEGASUS_TEST_ASSERT(isUTF8(&utf8chr[count]) == true);                UTF8_NEXT(utf8chr,count);        }        // utf8 string with mutliple byte characters        char utf8bad[] =         {            '\xFF','\xFF', '\xFF', '\0', '\0', '\0'        };        count = 0;        size = 3;        while(count<size)        {            PEGASUS_TEST_ASSERT(isUTF8(&utf8bad[count]) == false);            UTF8_NEXT(utf8bad,count);        }        Char16 utf16Chars[] =        {        0x6A19, 0x6E96, 0x842C, 0x570B, 0x78BC,        0x042E, 0x043D, 0x0438, 0x043A, 0x043E, 0x0434,        0x110B, 0x1172, 0x1102, 0x1165, 0x110F, 0x1169, 0x11AE,        0x10E3, 0x10DC, 0x10D8, 0x10D9, 0x10DD, 0x10D3, 0x10D8,        0xdbc0, 0xdc01,        0x05D9, 0x05D5, 0x05E0, 0x05D9, 0x05E7, 0x05D0, 0x05B8, 0x05D3,        0x064A, 0x0648, 0x0646, 0x0650, 0x0643, 0x0648, 0x062F,        0x092F, 0x0942, 0x0928, 0x093F, 0x0915, 0x094B, 0x0921,        0x016A, 0x006E, 0x012D, 0x0063, 0x014D, 0x0064, 0x0065, 0x033D,        0x00E0, 0x248B, 0x0061, 0x2173, 0x0062, 0x1EA6, 0xFF21, 0x00AA, 0x0325, 0x2173, 0x249C, 0x0063,        0x02C8, 0x006A, 0x0075, 0x006E, 0x026A, 0x02CC, 0x006B, 0x006F, 0x02D0, 0x0064,        0x30E6, 0x30CB, 0x30B3, 0x30FC, 0x30C9,        0xFF95, 0xFF86, 0xFF7A, 0xFF70, 0xFF84, 0xFF9E,        0xC720, 0xB2C8, 0xCF5B, 0x7D71, 0x4E00, 0x78BC,        0xdbc0, 0xdc01,        0x00};        String ugly(utf16Chars);        PEGASUS_TEST_ASSERT(ugly == utf16Chars);        //        // Test passing bad utf-8 into String        //        // A utf-8 sequence with a byte zeroed out in a bad spot        char utf8bad1[]    = {                              '\xCE', '\x99', '\xCE', '\xBF', '\xCF', '\x8D',                              '\xCE', '\xBD', '\xCE', '\0', '\xCE', '\xBA',                              '\xCE', '\xBF', '\xCE', '\xBD', '\xCF', '\x84',                              '\0'                            }; // utf8 string with mutliple byte characters             // Test String(char *)        try        {          // the first terminator causes invalid utf-8          String tmp(utf8bad1);          PEGASUS_TEST_ASSERT(false);        }        catch (Exception &)        {          // expect an error        }        // Test String(char *, Uint32)        try        {          // bogus utf-8 char in the middle          String tmp(utf8bad1, sizeof(utf8bad1)-1);          PEGASUS_TEST_ASSERT(false);        }        catch (Exception &)        {          // expect an error        }        // Test String(char *, Uint32)        try        {          // good, but the last utf-8 char extends past the last byte          String tmp(utf8chr, sizeof(utf8chr) - 2);          PEGASUS_TEST_ASSERT(false);        }        catch (Exception &)        {          // expect an error        }        // Test String::assign(char *)        String assigntest(utf8chr);  // good so far        try        {          // the first terminator causes invalid utf-8          assigntest.assign(utf8bad1);  // bad          PEGASUS_TEST_ASSERT(false);        }        catch (Exception &)        {          // expect an error        }        // Test String::assign(char *, Uint32)        try        {          // bogus utf-8 char in the middle          assigntest.assign(utf8bad1, sizeof(utf8bad1) - 1);  // bad          PEGASUS_TEST_ASSERT(false);        }        catch (Exception &)        {          // expect an error        }        // Test String::assign(char *, Uint32)        try        {          // good, but the last utf-8 char extends past the end          assigntest.assign(utf8chr, sizeof(utf8chr) - 2);  // bad          PEGASUS_TEST_ASSERT(false);        }        catch (Exception &)        {          // expect an error        }        //        // Test passing in good utf-8 with an embedded terminator        //        // A utf-8 sequence with a byte zeroed out in an ok spot        char utf8good1[]    = {                              '\xCE', '\x99', '\xCE', '\xBF', '\xCF', '\x8D',                              '\xCE', '\xBD', 'A', '\0', '\xCE', '\xBA',                              '\xCE', '\xBF', '\xCE', '\xBD', '\xCF', '\x84',                              '\0'                            }; // utf8 string with mutliple byte characters             // Test String(char *)        try        {          // terminator after 5 chars          String tmp(utf8good1);          PEGASUS_TEST_ASSERT (tmp.size() == 5);         }        catch (Exception &)        {          // didn't see that one coming          PEGASUS_TEST_ASSERT(false);        }        // Test String(char *, Uint32)        try        {          // embedded terminator counts as 1 char          String tmp(utf8good1, sizeof(utf8good1) - 1);          PEGASUS_TEST_ASSERT (tmp.size() == 10);         }        catch (Exception &)        {          // didn't see that one coming          PEGASUS_TEST_ASSERT(false);        }        assigntest.clear();        // Test String::assign(char *)        try        {          // terminator after 5 chars          assigntest.assign(utf8good1);          PEGASUS_TEST_ASSERT (assigntest.size() == 5);         }        catch (Exception &)        {          // didn't see that one coming          PEGASUS_TEST_ASSERT(false);        }        assigntest.clear();        // Test String::assign(char *, Uint32)        try        {          // embedded terminator counts as 1 char          assigntest.assign(utf8good1, sizeof(utf8good1) - 1);          PEGASUS_TEST_ASSERT (assigntest.size() == 10);         }        catch (Exception &)        {          // didn't see that one coming          PEGASUS_TEST_ASSERT(false);        }        //        // Casing tests        //        String little("the quick brown fox jumped over the lazy dog");        String    big("THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG");        String tmpBig = big;        String tmpLittle = little;        tmpBig.toLower();        PEGASUS_TEST_ASSERT(tmpBig == little);        tmpBig.toUpper();        PEGASUS_TEST_ASSERT(tmpBig == big);    }#if 0    // The match code has been removed from the String class    // Test the string match functions    {        String abc = "abc";        String ABC = "ABC";        PEGASUS_TEST_ASSERT(String::match(abc, "abc"));        PEGASUS_TEST_ASSERT(String::match(ABC, "ABC"));        PEGASUS_TEST_ASSERT(!String::match(abc, "ABC"));        PEGASUS_TEST_ASSERT(!String::match(ABC, "abc"));        PEGASUS_TEST_ASSERT(String::matchNoCase(abc, "abc"));        PEGASUS_TEST_ASSERT(String::matchNoCase(ABC, "abc"));        PEGASUS_TEST_ASSERT(String::matchNoCase(abc, "ABC"));        PEGASUS_TEST_ASSERT(String::matchNoCase(ABC, "ABc"));        PEGASUS_TEST_ASSERT(String::match(abc, "???"));        PEGASUS_TEST_ASSERT(String::match(ABC, "???"));        PEGASUS_TEST_ASSERT(String::match(abc, "*"));        PEGASUS_TEST_ASSERT(String::match(ABC, "*"));        PEGASUS_TEST_ASSERT(String::match(abc, "?bc"));        PEGASUS_TEST_ASSERT(String::match(abc, "?b?"));        PEGASUS_TEST_ASSERT(String::match(abc, "??c"));        PEGASUS_TEST_ASSERT(String::matchNoCase(ABC, "?bc"));        PEGASUS_TEST_ASSERT(String::matchNoCase(ABC, "?b?"));        PEGASUS_TEST_ASSERT(String::matchNoCase(ABC, "??c"));        PEGASUS_TEST_ASSERT(String::match(abc, "*bc"));        PEGASUS_TEST_ASSERT(String::match(abc, "a*c"));        PEGASUS_TEST_ASSERT(String::match(abc, "ab*"));        PEGASUS_TEST_ASSERT(String::match(abc, "a*"));        // ATTN-RK-P3-20020603: This match code is broken        //PEGASUS_TEST_ASSERT(String::match(abc, "[axy]bc"));        PEGASUS_TEST_ASSERT(!String::match(abc, "[xyz]bc"));        PEGASUS_TEST_ASSERT(!String::match(abc, "def"));        PEGASUS_TEST_ASSERT(!String::match(abc, "[de]bc"));        // ATTN-RK-P3-20020603: This match code is broken        //PEGASUS_TEST_ASSERT(String::match(abc, "a[a-c]c"));        PEGASUS_TEST_ASSERT(!String::match(abc, "a[d-x]c"));        // ATTN-RK-P3-20020603: This match code does not yet handle escape chars        //PEGASUS_TEST_ASSERT(String::match("*test", "\\*test"));        PEGASUS_TEST_ASSERT(String::match("abcdef123", "*[0-9]"));        PEGASUS_TEST_ASSERT(String::match("This is a test", "*is*"));        PEGASUS_TEST_ASSERT(String::matchNoCase("This is a test", "*IS*"));        PEGASUS_TEST_ASSERT(String::match("Hello", "Hello"));        PEGASUS_TEST_ASSERT(String::matchNoCase("HELLO", "hello"));        PEGASUS_TEST_ASSERT(String::match("This is a test", "This is *"));        PEGASUS_TEST_ASSERT(String::match("This is a test", "* is a test"));        PEGASUS_TEST_ASSERT(!String::match("Hello", "Goodbye"));        String tPattern = "When in the * of human*e??nts it be?ome[sS] [0-9] nec*";        try        {            String x(reinterpret_cast<const char *>(0));            cerr << "Error: Exception not thrown on NULL passed to constructor(const char *)" << endl;        }        catch ( const NullPointer & )        {            // This is the exception that should be thrown.        }        catch ( ... )        {            cerr << "Error: Wrong exception thrown on NULL passed to constructor(const char *)" << endl;        }        try        {            String x(reinterpret_cast<const Char16 *>(0));            cerr << "Error: Exception not thrown on NULL passed to constructor(const Char16 *)" << endl;        }        catch ( const NullPointer & )        {            // This is the exception that should be thrown.        }        catch ( ... )        {            cerr << "Error: Wrong exception thrown on NULL passed to constructor(const Char16 *)" << endl;        }        try        {            String x;            x.assign(reinterpret_cast<const char *>(0));            cerr << "Error: Exception not thrown on NULL passed to assign(const char *)" << endl;        }        catch ( const NullPointer & )        {            // This is the exception that should be thrown.        }        catch ( ... )        {            cerr << "Error: Wrong exception thrown on NULL passed to assign(const char *)" << endl;        }        try        {            String x;            x.assign(reinterpret_cast<const Char16 *>(0));            cerr << "Error: Exception not thrown on NULL passed to assign(const Char16 *)" << endl;        }        catch ( const NullPointer & )        {            // This is the exception that should be thrown.        }        catch ( ... )        {            cerr << "Error: Wrong exception thrown on NULL passed to assign(const Char16 *)" << endl;        }        try        {            String x;            x.append(reinterpret_cast<const char *>(0));            cerr << "Error: Exception not thrown on NULL passed to append(const char *)" << endl;        }        catch ( const NullPointer & )        {            // This is the exception that should be thrown.        }        catch ( ... )        {            cerr << "Error: Wrong exception thrown on NULL passed to append(const char *)" << endl;        }        try        {            String x;            x.append(reinterpret_cast<const Char16 *>(0));            cerr << "Error: Exception not thrown on NULL passed to append(const Char16 *)" << endl;        }        catch ( const NullPointer & )        {            // This is the exception that should be thrown.        }        catch ( ... )        {            cerr << "Error: Wrong exception thrown on NULL passed to append(const Char16 *)" << endl;        }        // ATTN-RK-P3-20020603: This match code is broken        //PEGASUS_TEST_ASSERT(String::match(        //    "When in the course of human events it becomes 0 necessary",        //    tPattern));        //PEGASUS_TEST_ASSERT(String::match(        //    "When in the xyz of human events it becomes 9 necessary",        //    tPattern));        //PEGASUS_TEST_ASSERT(String::match(        //    "When in the  of human events it becomes 3 necessary",        //    tPattern));    }#endif    // string()    {	String s;	PEGASUS_TEST_ASSERT(s.size() == 0);	PEGASUS_TEST_ASSERT(s[0] == '\0');    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -