Changeset 16369 in vbox for trunk/src/VBox/Main/glue
- Timestamp:
- Jan 29, 2009 2:26:18 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.