Changeset 24656 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Nov 14, 2009 10:36:32 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/string/ministring.cpp
r23223 r24656 36 36 using namespace iprt; 37 37 38 const size_t MiniString::npos = (size_t)-1; 39 40 /** 41 * Appends a copy of @a that to "this". 42 * @param that 43 */ 44 MiniString& MiniString::append(const MiniString &that) 38 const size_t MiniString::npos = ~(size_t)0; 39 40 MiniString &MiniString::append(const MiniString &that) 45 41 { 46 42 size_t lenThat = that.length(); … … 51 47 52 48 reserve(cbBoth); 53 // calls realloc(cbBoth) and sets m_cbAllocated 49 // calls realloc(cbBoth) and sets m_cbAllocated; may throw bad_alloc. 50 #ifndef RT_EXCEPTIONS_ENABLED 51 AssertRelease(capacity() >= cbBoth); 52 #endif 54 53 55 54 memcpy(m_psz + lenThis, that.m_psz, lenThat); … … 60 59 } 61 60 62 /**63 * Appends the given character to "this".64 * @param c65 * @return66 */67 61 MiniString& MiniString::append(char c) 68 62 { … … 71 65 // allocate in chunks of 20 in case this gets called several times 72 66 if (m_cbLength + 1 >= m_cbAllocated) 67 { 73 68 reserve(m_cbLength + 10); 74 // calls realloc() and sets m_cbAllocated 69 // calls realloc(cbBoth) and sets m_cbAllocated; may throw bad_alloc. 70 #ifndef RT_EXCEPTIONS_ENABLED 71 AssertRelease(capacity() >= m_cbLength + 1); 72 #endif 73 } 75 74 76 75 m_psz[m_cbLength] = c; … … 81 80 } 82 81 83 size_t MiniString::find(const char *pcszFind, 84 size_t pos /*= 0*/) 82 size_t MiniString::find(const char *pcszFind, size_t pos /*= 0*/) 85 83 const 86 84 { … … 128 126 129 127 size_t cbCopy = psz - pFirst; 130 ret.reserve(cbCopy + 1); 128 ret.reserve(cbCopy + 1); // may throw bad_alloc 129 #ifndef RT_EXCEPTIONS_ENABLED 130 AssertRelease(capacity() >= cbCopy + 1); 131 #endif 131 132 memcpy(ret.m_psz, pFirst, cbCopy); 132 133 ret.m_cbLength = cbCopy; … … 148 149 if (l1 < l2) 149 150 return false; 151 /** @todo r=bird: If l2 is 0, then m_psz can be NULL and we will crash. See 152 * also handling of l2 == in startsWith. */ 150 153 151 154 size_t l = l1 - l2; … … 160 163 size_t l1 = length(); 161 164 size_t l2 = that.length(); 162 if (l1 == 0 || l2 == 0) 165 if (l1 == 0 || l2 == 0) /** @todo r=bird: this differs from endsWith, and I think other IPRT code. If l2 == 0, it matches anything. */ 163 166 return false; 164 167 … … 174 177 bool MiniString::contains(const MiniString &that, CaseSensitivity cs /*= CaseSensitive*/) const 175 178 { 179 /** @todo r-bird: Not checking for NULL strings like startsWith does (and 180 * endsWith only does half way). */ 176 181 if (cs == CaseSensitive) 177 182 return ::RTStrStr(m_psz, that.m_psz) != NULL;
Note:
See TracChangeset
for help on using the changeset viewer.