Changeset 33862 in vbox
- Timestamp:
- Nov 8, 2010 5:07:49 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
include/iprt/cpp/ministring.h (modified) (5 diffs)
-
src/VBox/Main/ExtPackUtil.cpp (modified) (1 diff)
-
src/VBox/Runtime/testcase/tstIprtMiniString.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cpp/ministring.h
r33818 r33862 102 102 * Create a partial copy of another MiniString. 103 103 * 104 * @param a_rSrc The source string. 105 * @param a_offSrc The byte offset into the source string. 104 106 * @param a_cchSrc The max number of chars (encoded UTF-8 bytes) 105 107 * to copy from the source string. 106 * @param a_rSrc The source string. 107 */ 108 MiniString(size_t a_cchSrc, const MiniString &a_rSrc) 109 { 110 Assert(a_cchSrc <= a_rSrc.m_cch); 111 copyFromN(a_rSrc.m_psz, RT_MIN(a_cchSrc, a_rSrc.m_cch)); 108 */ 109 MiniString(const MiniString &a_rSrc, size_t a_offSrc, size_t a_cchSrc = npos) 110 { 111 if (a_offSrc < a_rSrc.m_cch) 112 copyFromN(&a_rSrc.m_psz[a_offSrc], RT_MIN(a_cchSrc, a_rSrc.m_cch - a_offSrc)); 113 else 114 { 115 m_psz = NULL; 116 m_cch = 0; 117 m_cbAllocated = 0; 118 } 112 119 } 113 120 … … 115 122 * Create a partial copy of a C string. 116 123 * 124 * @param a_pszSrc The source string (UTF-8). 117 125 * @param a_cchSrc The max number of chars (encoded UTF-8 bytes) 118 * to copy from the source string. 119 * @param a_pszSrc The source string (UTF-8). 120 */ 121 MiniString(size_t a_cchSrc, const char *a_pszSrc) 126 * to copy from the source string. This must not 127 * be '0' as the compiler could easily mistake 128 * that for the va_list constructor. 129 */ 130 MiniString(const char *a_pszSrc, size_t a_cchSrc) 122 131 { 123 132 size_t cchMax = a_pszSrc ? RTStrNLen(a_pszSrc, a_cchSrc) : 0; 124 Assert(a_cchSrc <= cchMax);125 133 copyFromN(a_pszSrc, RT_MIN(a_cchSrc, cchMax)); 134 } 135 136 /** 137 * Create a string containing @a a_cTimes repetitions of the character @a 138 * a_ch. 139 * 140 * @param a_cTimes The number of times the character is repeated. 141 * @param a_ch The character to fill the string with. 142 */ 143 MiniString(size_t a_cTimes, char a_ch) 144 : m_psz(NULL), 145 m_cch(0), 146 m_cbAllocated(0) 147 { 148 Assert((unsigned)a_ch < 0x80); 149 if (a_cTimes) 150 { 151 reserve(a_cTimes + 1); 152 memset(m_psz, a_ch, a_cTimes); 153 m_psz[a_cTimes] = '\0'; 154 m_cch = a_cTimes; 155 } 126 156 } 127 157 … … 134 164 * specified by the format string. 135 165 * @sa printfV 166 * @remarks Not part of std::string. 136 167 */ 137 168 MiniString(const char *a_pszFormat, va_list a_va) … … 139 170 m_cch(0), 140 171 m_cbAllocated(0) 141 142 172 { 143 173 printfV(a_pszFormat, a_va); … … 783 813 m_cch = cchSrc; 784 814 m_cbAllocated = cchSrc + 1; 785 memcpy(m_psz, pcszSrc, cchSrc + 1); 815 memcpy(m_psz, pcszSrc, cchSrc); 816 m_psz[cchSrc] = '\0'; 786 817 } 787 818 else -
trunk/src/VBox/Main/ExtPackUtil.cpp
r33806 r33862 180 180 * Make a duplicate of the name and return it. 181 181 */ 182 iprt::MiniString *pStrRet = new iprt::MiniString( off, pszSrc);182 iprt::MiniString *pStrRet = new iprt::MiniString(pszSrc, off); 183 183 Assert(VBoxExtPackIsValidName(pStrRet->c_str())); 184 184 return pStrRet; -
trunk/src/VBox/Runtime/testcase/tstIprtMiniString.cpp
r33819 r33862 39 39 static void test1Hlp1(const char *pszExpect, const char *pszFormat, ...) 40 40 { 41 #if 0 41 42 va_list va; 42 43 va_start(va, pszFormat); … … 44 45 va_end(va); 45 46 RTTESTI_CHECK_MSG(strTst.equals(pszExpect), ("strTst='%s' expected='%s'\n", strTst.c_str(), pszExpect)); 47 #endif 46 48 } 47 49 … … 61 63 if (!(expr)) \ 62 64 RTTestFailed(hTest, "%d: FAILED %s, got \"%d\"", __LINE__, #expr, expr); \ 65 } while (0) 66 #define CHECK_EQUAL(Str, szExpect) \ 67 do { \ 68 if (!(Str).equals(szExpect)) \ 69 RTTestIFailed("line %u: expected \"%s\" got \"%s\"", __LINE__, szExpect, (Str).c_str()); \ 63 70 } while (0) 64 71 … … 167 174 test1Hlp1("foobar", "%s", "foobar"); 168 175 176 /* substring constructors */ 177 iprt::MiniString SubStr1("", (size_t)0); 178 CHECK_EQUAL(SubStr1, ""); 179 180 iprt::MiniString SubStr2("abcdef", 2); 181 CHECK_EQUAL(SubStr2, "ab"); 182 183 iprt::MiniString SubStr3("abcdef", 1); 184 CHECK_EQUAL(SubStr3, "a"); 185 186 iprt::MiniString SubStr4("abcdef", 6); 187 CHECK_EQUAL(SubStr4, "abcdef"); 188 189 iprt::MiniString SubStr5("abcdef", 7); 190 CHECK_EQUAL(SubStr5, "abcdef"); 191 192 193 iprt::MiniString SubStrBase("abcdef"); 194 195 iprt::MiniString SubStr10(SubStrBase, 0); 196 CHECK_EQUAL(SubStr10, "abcdef"); 197 198 iprt::MiniString SubStr11(SubStrBase, 1); 199 CHECK_EQUAL(SubStr11, "bcdef"); 200 201 iprt::MiniString SubStr12(SubStrBase, 1, 1); 202 CHECK_EQUAL(SubStr12, "b"); 203 204 iprt::MiniString SubStr13(SubStrBase, 2, 3); 205 CHECK_EQUAL(SubStr13, "cde"); 206 207 iprt::MiniString SubStr14(SubStrBase, 2, 4); 208 CHECK_EQUAL(SubStr14, "cdef"); 209 210 iprt::MiniString SubStr15(SubStrBase, 2, 5); 211 CHECK_EQUAL(SubStr15, "cdef"); 212 213 169 214 /* special constructor and assignment arguments */ 170 215 iprt::MiniString StrCtor1(""); … … 211 256 #undef CHECK_DUMP 212 257 #undef CHECK_DUMP_I 258 #undef CHECK_EQUAL 213 259 } 214 260
Note:
See TracChangeset
for help on using the changeset viewer.

