Changeset 85345 in vbox for trunk/src/VBox/Runtime/common/string
- Timestamp:
- Jul 15, 2020 8:03:03 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/string/RTStrSplit.cpp
r85154 r85345 46 46 47 47 /* Determine the number of paths in buffer first. */ 48 size_t cch = cbStrings - 1; 49 char const *pszTmp = pcszStrings; 48 size_t cch = cbStrings - 1; 49 char const *pcszTmp = pcszStrings; 50 const char *pcszEnd = RTStrEnd(pcszTmp, RTSTR_MAX); 51 char const *pcszNext; 50 52 const size_t cchSep = strlen(pcszSeparator); 53 size_t cchNext; 51 54 while (cch > 0) 52 55 { 53 char const *pszNext = RTStrStr(pszTmp, pcszSeparator);54 if (!p szNext)56 pcszNext = RTStrStr(pcszTmp, pcszSeparator); 57 if (!pcszNext) 55 58 break; 56 c onst size_t cchNext = pszNext - pszTmp;59 cchNext = pcszNext - pcszTmp; 57 60 if (cchNext + cchSep > cch) 58 61 break; 59 pszTmp += cchNext + cchSep; 60 cch -= cchNext + cchSep; 62 pcszNext += cchSep; 63 pcszTmp += cchNext + cchSep; 64 cch -= cchNext + cchSep; 61 65 if (cchNext) 62 66 ++cStrings; 63 67 } 64 68 69 if (pcszTmp != pcszEnd) /* Do we need to take a trailing string without separator into account? */ 70 cStrings++; 71 65 72 if (!cStrings) 66 73 { 67 *pcStrings = 0; 74 *ppapszStrings = NULL; 75 *pcStrings = 0; 68 76 return VINF_SUCCESS; 69 77 } … … 76 84 77 85 cch = cbStrings - 1; 78 p szTmp = pcszStrings;86 pcszTmp = pcszStrings; 79 87 80 for (size_t i = 0; i < 3;)88 for (size_t i = 0; i < cStrings;) 81 89 { 82 char const *pszNext = RTStrStr(pszTmp, pcszSeparator); 83 if (!pszNext) 84 break; 85 const size_t cchNext = pszNext - pszTmp; 86 if (cchNext + cchSep > cch) 87 break; 90 pcszNext = RTStrStr(pcszTmp, pcszSeparator); 91 if (!pcszNext) 92 pcszNext = pcszEnd; 93 cchNext = pcszNext - pcszTmp; 88 94 if (cchNext) 89 95 { 90 papszStrings[i] = RTStrDupN(p szTmp, cchNext);96 papszStrings[i] = RTStrDupN(pcszTmp, cchNext); 91 97 if (!papszStrings[i]) 92 98 { … … 96 102 i++; 97 103 } 98 p szTmp += cchNext + cchSep;99 cch -= cchNext + cchSep;104 pcszTmp += cchNext + cchSep; 105 cch -= cchNext + cchSep; 100 106 } 101 107
Note:
See TracChangeset
for help on using the changeset viewer.