Changeset 30318 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Jun 21, 2010 7:49:28 AM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 62876
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/string/ministring.cpp
r28800 r30318 50 50 memcpy(m_psz + lenThis, that.m_psz, lenThat); 51 51 m_psz[lenThis + lenThat] = '\0'; 52 m_cbLength = cbBoth - 1; 53 } 54 return *this; 55 } 56 57 MiniString &MiniString::append(const char *pszThat) 58 { 59 size_t cchThat = strlen(pszThat); 60 if (cchThat) 61 { 62 size_t cchThis = length(); 63 size_t cbBoth = cchThis + cchThat + 1; 64 65 reserve(cbBoth); 66 // calls realloc(cbBoth) and sets m_cbAllocated; may throw bad_alloc. 67 #ifndef RT_EXCEPTIONS_ENABLED 68 AssertRelease(capacity() >= cbBoth); 69 #endif 70 71 memcpy(m_psz + cchThis, pszThat, cchThat); 72 m_psz[cbBoth - 1] = '\0'; 52 73 m_cbLength = cbBoth - 1; 53 74 } -
trunk/src/VBox/Runtime/testcase/tstUtf8.cpp
r28800 r30318 948 948 949 949 iprt::MiniString empty; 950 CHECK( (empty.length() == 0));951 CHECK( (empty.capacity() == 0));950 CHECK(empty.length() == 0); 951 CHECK(empty.capacity() == 0); 952 952 953 953 iprt::MiniString sixbytes("12345"); 954 CHECK( (sixbytes.length() == 5) ); 955 CHECK( (sixbytes.capacity() == 6) ); 956 957 sixbytes.append("678"); 958 CHECK( (sixbytes.length() == 8) ); 959 CHECK( (sixbytes.capacity() == 9) ); 954 CHECK(sixbytes.length() == 5); 955 CHECK(sixbytes.capacity() == 6); 956 957 sixbytes.append(iprt::MiniString("678")); 958 CHECK(sixbytes.length() == 8); 959 CHECK(sixbytes.capacity() == 9); 960 961 sixbytes.append("9a"); 962 CHECK(sixbytes.length() == 10); 963 CHECK(sixbytes.capacity() == 11); 960 964 961 965 char *psz = sixbytes.mutableRaw(); 962 // 12345678 966 // 123456789a 963 967 // ^ 964 968 // 0123456 965 969 psz[6] = '\0'; 966 970 sixbytes.jolt(); 967 CHECK( (sixbytes.length() == 6));968 CHECK( (sixbytes.capacity() == 7));971 CHECK(sixbytes.length() == 6); 972 CHECK(sixbytes.capacity() == 7); 969 973 970 974 iprt::MiniString morebytes("tobereplaced"); … … 972 976 morebytes.append(sixbytes); 973 977 974 CHECK_DUMP( (morebytes == "newstring 123456"), morebytes.c_str());978 CHECK_DUMP(morebytes == "newstring 123456", morebytes.c_str()); 975 979 976 980 iprt::MiniString third(morebytes); 977 981 third.reserve(100 * 1024); // 100 KB 978 CHECK_DUMP( (third == "newstring 123456"), morebytes.c_str() );979 CHECK( (third.capacity() == 100 * 1024));980 CHECK( (third.length() == morebytes.length()) );// must not have changed982 CHECK_DUMP(third == "newstring 123456", morebytes.c_str() ); 983 CHECK(third.capacity() == 100 * 1024); 984 CHECK(third.length() == morebytes.length()); // must not have changed 981 985 982 986 iprt::MiniString copy1(morebytes); 983 987 iprt::MiniString copy2 = morebytes; 984 CHECK( (copy1 == copy2));988 CHECK(copy1 == copy2); 985 989 986 990 copy1 = NULL; 987 CHECK( (copy1.length() == 0));991 CHECK(copy1.length() == 0); 988 992 989 993 copy1 = ""; 990 CHECK( (copy1.length() == 0) ); 991 992 CHECK( (iprt::MiniString("abc") < iprt::MiniString("def")) ); 993 CHECK( (iprt::MiniString("abc") != iprt::MiniString("def")) ); 994 CHECK_DUMP_I( (iprt::MiniString("def") > iprt::MiniString("abc")) ); 994 CHECK(copy1.length() == 0); 995 996 CHECK(iprt::MiniString("abc") < iprt::MiniString("def")); 997 CHECK(iprt::MiniString("abc") != iprt::MiniString("def")); 998 CHECK_DUMP_I(iprt::MiniString("def") > iprt::MiniString("abc")); 999 CHECK(iprt::MiniString("abc") == iprt::MiniString("abc")); 995 1000 996 1001 copy2.setNull(); 997 for (int i = 0; 998 i < 100; 999 ++i) 1002 for (int i = 0; i < 100; ++i) 1000 1003 { 1001 1004 copy2.reserve(50); // should be ignored after 50 loops 1002 1005 copy2.append("1"); 1003 1006 } 1004 CHECK( (copy2.length() == 100));1007 CHECK(copy2.length() == 100); 1005 1008 1006 1009 copy2.setNull(); 1007 for (int i = 0; 1008 i < 100; 1009 ++i) 1010 for (int i = 0; i < 100; ++i) 1010 1011 { 1011 1012 copy2.reserve(50); // should be ignored after 50 loops 1012 1013 copy2.append('1'); 1013 1014 } 1014 CHECK( (copy2.length() == 100));1015 CHECK(copy2.length() == 100); 1015 1016 1016 1017 #undef CHECK 1018 #undef CHECK_DUMP 1019 #undef CHECK_DUMP_I 1017 1020 } 1018 1021 … … 1099 1102 /* Test Latin1 -> Utf16 */ 1100 1103 const char *pszLat1 = "\x01\x20\x40\x80\x81"; 1101 RTTEST_CHECK(hTest, (RTLatin1CalcUtf16Len(pszLat1) == 5));1104 RTTEST_CHECK(hTest, RTLatin1CalcUtf16Len(pszLat1) == 5); 1102 1105 rc = RTLatin1CalcUtf16LenEx(pszLat1, 3, &cchActual); 1103 1106 RTTEST_CHECK_RC_OK(hTest, rc); 1104 1107 if (RT_SUCCESS(rc)) 1105 RTTEST_CHECK(hTest, (cchActual == 3));1108 RTTEST_CHECK(hTest, cchActual == 3); 1106 1109 rc = RTLatin1CalcUtf16LenEx(pszLat1, RTSTR_MAX, &cchActual); 1107 1110 RTTEST_CHECK_RC_OK(hTest, rc); 1108 1111 if (RT_SUCCESS(rc)) 1109 RTTEST_CHECK(hTest, (cchActual == 5));1112 RTTEST_CHECK(hTest, cchActual == 5); 1110 1113 RTUTF16 *pwc = NULL; 1111 1114 RTUTF16 wc[6];
Note:
See TracChangeset
for help on using the changeset viewer.