Changeset 21358 in vbox for trunk/include
- Timestamp:
- Jul 7, 2009 4:19:32 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 49707
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/ministring_cpp.h
r21352 r21358 43 43 * Semantics are like in std::string, except it can do a lot less. 44 44 * 45 * Much of the code in here used to be in Utf8Str so that Utf8Str can now46 * derive from ministring and only contain code that is COM-specific, such47 * as com::Bstr conversions. Compared to the old Utf8Str though, ministring45 * Much of the code in here used to be in com::Utf8Str so that com::Utf8Str 46 * can now derive from ministring and only contain code that is COM-specific, 47 * such as com::Bstr conversions. Compared to the old Utf8Str though, ministring 48 48 * always knows the length of its member string and the size of the buffer 49 49 * so it can use memcpy() instead of strdup(). … … 53 53 { 54 54 public: 55 /** 56 * Creates an empty string that has no memory allocated. 57 */ 55 58 ministring() 56 59 : m_psz(NULL), … … 60 63 } 61 64 65 /** 66 * Creates a copy of another ministring. This allocates 67 * s.length() + 1 bytes for the new instance. 68 * @param s 69 */ 62 70 ministring(const ministring &s) 63 71 { … … 65 73 } 66 74 75 /** 76 * Creates a copy of another ministring. This allocates 77 * strlen(pcsz) + 1 bytes for the new instance. 78 * @param pcsz 79 */ 67 80 ministring(const char *pcsz) 68 81 { … … 70 83 } 71 84 85 /** 86 * Destructor. 87 */ 72 88 virtual ~ministring() 73 89 { … … 75 91 } 76 92 93 /** 94 * Returns the length of the member string. This is always cached 95 * so calling this is cheap and requires no strlen() invocation. 96 * @return 97 */ 77 98 size_t length() const 78 99 { … … 81 102 82 103 /** 83 * Returns the n o.of bytes allocated in the internal string buffer,84 * which is at least m_cbLength + 1 if m_cbLength !=0.104 * Returns the number of bytes allocated in the internal string buffer, 105 * which is at least length() + 1 if length() > 0. 85 106 * @return 86 107 */ … … 93 114 * Requests that the contained memory buffer have at least cb bytes allocated. 94 115 * This may expand or shrink the string's storage, but will never truncate the 95 * contained string. 116 * contained string. In other words, cb will be ignored if it's smaller than 117 * length() + 1. 96 118 * @param cb new minimum size of member memory buffer 97 119 */ … … 107 129 } 108 130 131 /** 132 * Deallocates all memory. 133 */ 109 134 inline void setNull() 110 135 { … … 146 171 } 147 172 173 /** 174 * Assigns a copy of pcsz to "this". 175 * @param pcsz 176 * @return 177 */ 148 178 ministring& operator=(const char *pcsz) 149 179 { … … 156 186 } 157 187 188 /** 189 * Assigns a copy of s to "this". 190 * @param s 191 * @return 192 */ 158 193 ministring& operator=(const ministring &s) 159 194 { … … 166 201 } 167 202 203 /** 204 * Appends a copy of @a that to "this". 205 * @param that 206 */ 168 207 void append(const ministring &that) 169 208 { … … 184 223 } 185 224 225 /** 226 * Returns the contained string as a C-style const char* pointer. 227 * @return 228 */ 186 229 inline const char* c_str() const 187 230 { … … 189 232 } 190 233 234 /** 235 * Like c_str(), for compatibility with lots of VirtualBox Main code. 236 * @return 237 */ 191 238 inline const char* raw() const 192 239 { … … 200 247 } 201 248 249 /** 250 * Returns true if the member string has no length. This states nothing about 251 * how much memory might be allocated. 252 * @return 253 */ 202 254 bool isEmpty() const 203 255 { … … 205 257 } 206 258 259 /** 260 * Returns true if no memory is currently allocated. 261 * @return 262 */ 207 263 bool isNull() const 208 264 { … … 216 272 }; 217 273 274 /** 275 * Compares the member string to pcsz. 276 * @param pcsz 277 * @param cs Whether comparison should be case-sensitive. 278 * @return 279 */ 218 280 int compare(const char *pcsz, CaseSensitivity cs = CaseSensitive) const 219 281 { … … 265 327 266 328 /** 329 * Protected internal helper. 267 330 * copyFrom() unconditionally sets the members to a copy of the 268 331 * given other strings and makes no assumptions about previous … … 278 341 void copyFrom(const ministring &s) 279 342 { 280 m_cbLength = s.m_cbLength; 281 m_cbAllocated = m_cbLength + 1; 282 m_psz = (char*)RTMemAlloc(m_cbAllocated); 283 memcpy(m_psz, s.m_psz, m_cbAllocated); // include 0 terminator 284 } 285 286 /** 343 if ((m_cbLength = s.m_cbLength)) 344 { 345 m_cbAllocated = m_cbLength + 1; 346 m_psz = (char*)RTMemAlloc(m_cbAllocated); 347 memcpy(m_psz, s.m_psz, m_cbAllocated); // include 0 terminator 348 } 349 else 350 { 351 m_cbAllocated = 0; 352 m_psz = NULL; 353 } 354 } 355 356 /** 357 * Protected internal helper. 287 358 * See copyFrom() above. 288 359 *
Note:
See TracChangeset
for help on using the changeset viewer.