Changeset 16324 in vbox
- Timestamp:
- Jan 28, 2009 6:06:59 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/string.h
r15051 r16324 442 442 const char *raw() const { return str; } 443 443 444 /** The same as operator const char *(), but for situations where the compiler 445 cannot typecast implicitly (for example, in printf() argument list). */ 446 const char *c_str() const { return str; } 447 444 448 /** 445 449 * Returns a non-const raw pointer that allows to modify the string directly. … … 495 499 return *this; 496 500 } 501 502 static const size_t npos; 503 504 Utf8Str substr(size_t pos = 0, size_t n = npos) const; 497 505 498 506 /** -
trunk/src/VBox/Main/glue/string.cpp
r14948 r16324 35 35 /* static */ 36 36 const Utf8Str Utf8Str::Null; /* default ctor is OK */ 37 38 const size_t Utf8Str::npos = (size_t)-1; 39 40 Utf8Str Utf8Str::substr(size_t pos /*= 0*/, size_t n /*= npos*/) const 41 { 42 Utf8Str ret; 43 44 if (n) 45 { 46 const char *psz = c_str(); 47 RTUNICP cp; 48 49 // walk the UTF-8 characters until where the caller wants to start 50 size_t i = pos; 51 while (i--) 52 RTStrGetCpEx(&psz, &cp); 53 54 const char *pFirst = psz; 55 56 if (n == npos) 57 // all the rest: 58 ret = pFirst; 59 else 60 { 61 i = n; 62 while (i--) 63 RTStrGetCpEx(&psz, &cp); 64 65 size_t len = psz - pFirst; 66 char *psz = (char*)RTMemAlloc(len + 1); 67 memcpy(psz, pFirst, len); 68 psz[len] = '\0'; 69 ret = psz; 70 RTMemFree(psz); 71 } 72 } 73 74 return ret; 75 } 37 76 38 77 struct FormatData … … 99 138 } 100 139 140 101 141 } /* namespace com */
Note:
See TracChangeset
for help on using the changeset viewer.