Changeset 16324 in vbox for trunk/src/VBox/Main/glue
- Timestamp:
- Jan 28, 2009 6:06:59 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.