MCPcopy Create free account
hub / github.com/ValveSoftware/GameNetworkingSockets / V_SplitString2

Function V_SplitString2

src/vstdlib/strtools.cpp:369–412  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

367}
368
369void V_SplitString2( const char *pString, const char * const *pSeparators, int nSeparators, CUtlVector<char*> &outStrings, bool bIncludeEmptyStrings )
370{
371 outStrings.Purge();
372 const char *pCurPos = pString;
373 for (;;)
374 {
375 int iFirstSeparator = -1;
376 const char *pFirstSeparator = 0;
377 for ( int i=0; i < nSeparators; i++ )
378 {
379 const char *pTest = V_stristr( pCurPos, pSeparators[i] );
380 if ( pTest && (!pFirstSeparator || pTest < pFirstSeparator) )
381 {
382 iFirstSeparator = i;
383 pFirstSeparator = pTest;
384 }
385 }
386
387 if ( pFirstSeparator )
388 {
389 // Split on this separator and continue on.
390 int separatorLen = (int)strlen( pSeparators[iFirstSeparator] );
391 if ( pFirstSeparator > pCurPos || ( pFirstSeparator == pCurPos && bIncludeEmptyStrings ) )
392 {
393 outStrings.AddToTail( AllocString( pCurPos, pFirstSeparator-pCurPos ) );
394 }
395
396 pCurPos = pFirstSeparator + separatorLen;
397 }
398 else
399 {
400 // Copy the rest of the string, if there's anything there
401 if ( pCurPos[0] != 0 )
402 {
403 outStrings.AddToTail( AllocString( pCurPos, -1 ) );
404 }
405 else if (bIncludeEmptyStrings && pCurPos > pString)
406 {
407 outStrings.AddToTail( AllocString( "" , 1 ));
408 }
409 return;
410 }
411 }
412}
413
414void V_AllocAndSplitString( const char *pString, const char *pSeparator, CUtlVector<char*> &outStrings, bool bIncludeEmptyStrings )
415{

Callers 1

V_AllocAndSplitStringFunction · 0.85

Calls 4

V_stristrFunction · 0.85
AllocStringFunction · 0.85
PurgeMethod · 0.45
AddToTailMethod · 0.45

Tested by

no test coverage detected