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

Method GetToken

src/tier1/utlbuffer.cpp:1105–1144  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Advance the get index until after the particular string is found Do not eat whitespace before starting. Return false if it failed -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

1103// Do not eat whitespace before starting. Return false if it failed
1104//-----------------------------------------------------------------------------
1105bool CUtlBuffer::GetToken( const char *pToken )
1106{
1107 Assert( pToken );
1108
1109 // Look for the token
1110 int nLen = V_strlen( pToken );
1111
1112 int nSizeToCheck = SizeAllocated() - TellGet();
1113
1114 int nGet = TellGet();
1115 do
1116 {
1117 int nMaxSize = TellMaxPut() - TellGet();
1118 if ( nMaxSize < nSizeToCheck )
1119 {
1120 nSizeToCheck = nMaxSize;
1121 }
1122 if ( nLen > nSizeToCheck )
1123 break;
1124
1125 if ( !CheckPeekGet( 0, nSizeToCheck ) )
1126 break;
1127
1128 const char *pBufStart = (const char*)PeekGet();
1129 const char *pFoundEnd = V_strnistr( pBufStart, pToken, nSizeToCheck );
1130 if ( pFoundEnd )
1131 {
1132 size_t nOffset = (size_t)pFoundEnd - (size_t)pBufStart;
1133 SeekGet( CUtlBuffer::SEEK_CURRENT, static_cast<int>( nOffset + nLen ) );
1134 return true;
1135 }
1136
1137 SeekGet( CUtlBuffer::SEEK_CURRENT, nSizeToCheck - nLen + 1);
1138 nSizeToCheck = SizeAllocated() - nLen + 1;
1139
1140 } while ( true );
1141
1142 SeekGet( CUtlBuffer::SEEK_HEAD, nGet );
1143 return false;
1144}
1145
1146
1147//-----------------------------------------------------------------------------

Callers

nothing calls this directly

Calls 2

V_strlenFunction · 0.85
V_strnistrFunction · 0.85

Tested by

no test coverage detected