Changeset 16369 in vbox
- Timestamp:
- Jan 29, 2009 2:26:18 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
include/VBox/com/string.h (modified) (1 diff)
-
src/VBox/Main/glue/string.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/string.h
r16326 r16369 507 507 * as UTF-8 codepoints instead of bytes. With the default parameters "0" 508 508 * and "npos", this always copies the entire string. 509 * @param pos Index of first codepoint sto copy from "this", counting from 0.509 * @param pos Index of first codepoint to copy from "this", counting from 0. 510 510 * @param n Number of codepoints to copy, starting with the one at "pos". 511 511 */ -
trunk/src/VBox/Main/glue/string.cpp
r16324 r16369 44 44 if (n) 45 45 { 46 const char *psz = c_str(); 47 RTUNICP cp; 46 const char *psz; 48 47 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); 48 if ((psz = c_str())) 49 { 50 RTUNICP cp; 53 51 54 const char *pFirst = psz; 52 // walk the UTF-8 characters until where the caller wants to start 53 size_t i = pos; 54 while (*psz && i--) 55 if (!(RT_SUCCESS(RTStrGetCpEx(&psz, &cp)))) 56 return ret; // return empty string on bad encoding 55 57 56 if (n == npos) 57 // all the rest: 58 ret = pFirst; 59 else 60 { 61 i = n; 62 while (i--) 63 RTStrGetCpEx(&psz, &cp); 58 const char *pFirst = psz; 64 59 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); 60 if (n == npos) 61 // all the rest: 62 ret = pFirst; 63 else 64 { 65 i = n; 66 while (*psz && i--) 67 if (!(RT_SUCCESS(RTStrGetCpEx(&psz, &cp)))) 68 return ret; // return empty string on bad encoding 69 70 size_t len = psz - pFirst; 71 char *psz = (char*)RTMemAlloc(len + 1); 72 memcpy(psz, pFirst, len); 73 psz[len] = '\0'; 74 ret = psz; 75 RTMemFree(psz); 76 } 71 77 } 72 78 }
Note:
See TracChangeset
for help on using the changeset viewer.

