Changeset 36508 in vbox for trunk/src/VBox/Runtime/common/string
- Timestamp:
- Apr 1, 2011 3:03:59 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/string/ministring.cpp
r36501 r36508 8 8 9 9 /* 10 * Copyright (C) 2007-201 0Oracle Corporation10 * Copyright (C) 2007-2011 Oracle Corporation 11 11 * 12 12 * This file is part of VirtualBox Open Source Edition (OSE), as … … 200 200 } 201 201 202 size_t MiniString::find(const char *pcszFind, size_t pos /*= 0*/) 203 const 202 size_t MiniString::find(const char *pcszFind, size_t pos /*= 0*/) const 204 203 { 205 204 const char *pszThis, *p; … … 224 223 } 225 224 226 MiniString MiniString::substrCP(size_t pos /*= 0*/, size_t n /*= npos*/) 227 const 225 MiniString MiniString::substrCP(size_t pos /*= 0*/, size_t n /*= npos*/) const 228 226 { 229 227 MiniString ret; … … 288 286 if (cs == CaseSensitive) 289 287 return ::RTStrCmp(&m_psz[l], that.m_psz) == 0; 290 else 291 return ::RTStrICmp(&m_psz[l], that.m_psz) == 0; 288 return ::RTStrICmp(&m_psz[l], that.m_psz) == 0; 292 289 } 293 290 … … 304 301 if (cs == CaseSensitive) 305 302 return ::RTStrNCmp(m_psz, that.m_psz, l2) == 0; 306 else 307 return ::RTStrNICmp(m_psz, that.m_psz, l2) == 0; 303 return ::RTStrNICmp(m_psz, that.m_psz, l2) == 0; 308 304 } 309 305 … … 314 310 if (cs == CaseSensitive) 315 311 return ::RTStrStr(m_psz, that.m_psz) != NULL; 316 else 317 return ::RTStrIStr(m_psz, that.m_psz) != NULL; 312 return ::RTStrIStr(m_psz, that.m_psz) != NULL; 318 313 } 319 314 … … 332 327 } 333 328 334 iprt::list<iprt::MiniString, iprt::MiniString*> MiniString::split(const iprt::MiniString &strSep, SplitMode mode /* = RemoveEmptyParts */) 335 { 336 iprt::list<iprt::MiniString> res; 329 iprt::list<iprt::MiniString, iprt::MiniString *> 330 MiniString::split(const iprt::MiniString &a_rstrSep, SplitMode mode /* = RemoveEmptyParts */) 331 { 332 iprt::list<iprt::MiniString> strRet; 337 333 if (!m_psz) 338 return res;339 if ( strSep.isEmpty())340 { 341 res.append(iprt::MiniString(m_psz));342 return res;343 } 344 345 size_t cch= m_cch;346 char *pszTmp = m_psz;347 while (cch > 0)348 { 349 char *pszNext = strstr(pszTmp,strSep.c_str());334 return strRet; 335 if (a_rstrSep.isEmpty()) 336 { 337 strRet.append(iprt::MiniString(m_psz)); 338 return strRet; 339 } 340 341 size_t cch = m_cch; 342 char const *pszTmp = m_psz; 343 while (cch > 0) 344 { 345 char const *pszNext = strstr(pszTmp, a_rstrSep.c_str()); 350 346 if (!pszNext) 347 { 348 strRet.append(iprt::MiniString(pszTmp, cch)); 351 349 break; 352 size_t chNext = pszNext - pszTmp; 353 if ( chNext > 0 350 } 351 size_t cchNext = pszNext - pszTmp; 352 if ( cchNext > 0 354 353 || mode == KeepEmptyParts) 355 res.append(iprt::MiniString(pszTmp, chNext)); 356 pszTmp += chNext + strSep.length(); 357 cch -= chNext + strSep.length(); 358 } 359 /* Some characters left at the end? */ 360 if (cch > 0) 361 res.append(iprt::MiniString(pszTmp, cch)); 362 363 return res; 354 strRet.append(iprt::MiniString(pszTmp, cchNext)); 355 pszTmp += cchNext + a_rstrSep.length(); 356 cch -= cchNext + a_rstrSep.length(); 357 } 358 359 return strRet; 364 360 } 365 361 366 362 /* static */ 367 iprt::MiniString MiniString::join(const iprt::list<iprt::MiniString, iprt::MiniString*> &list, const iprt::MiniString &strSep /* = "" */) 368 { 369 MiniString res; 370 if (list.size() > 1) 371 { 372 for(size_t i = 0; i < list.size() - 1; ++i) 373 res += list.at(i) + strSep; 374 res += list.last(); 375 } 376 377 return res; 378 } 379 380 const iprt::MiniString operator+(const iprt::MiniString &one, const iprt::MiniString &other) 381 { 382 iprt::MiniString res(one); 383 384 return res += other; 385 } 386 387 const iprt::MiniString operator+(const iprt::MiniString &one, const char *pcszOther) 388 { 389 iprt::MiniString res(one); 390 391 return res += pcszOther; 392 } 393 394 const iprt::MiniString operator+(const char *pcszOne, const iprt::MiniString &other) 395 { 396 iprt::MiniString res(pcszOne); 397 398 return res += other; 399 } 400 363 iprt::MiniString 364 MiniString::join(const iprt::list<iprt::MiniString, iprt::MiniString*> &a_rList, 365 const iprt::MiniString &a_rstrSep /* = "" */) 366 { 367 MiniString strRet; 368 if (a_rList.size() > 1) 369 { 370 for (size_t i = 0; i < a_rList.size() - 1; ++i) 371 strRet += a_rList.at(i) + a_rstrSep; 372 strRet += a_rList.last(); 373 } 374 375 return strRet; 376 } 377 378 const iprt::MiniString operator+(const iprt::MiniString &a_rStr1, const iprt::MiniString &a_rStr2) 379 { 380 iprt::MiniString strRet(a_rStr1); 381 strRet += a_rStr2; 382 return strRet; 383 } 384 385 const iprt::MiniString operator+(const iprt::MiniString &a_rStr1, const char *a_pszStr2) 386 { 387 iprt::MiniString strRet(a_rStr1); 388 strRet += a_pszStr2; 389 return strRet; 390 } 391 392 const iprt::MiniString operator+(const char *a_psz1, const iprt::MiniString &a_rStr2) 393 { 394 iprt::MiniString strRet(a_psz1); 395 strRet += a_rStr2; 396 return strRet; 397 } 398
Note:
See TracChangeset
for help on using the changeset viewer.