diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /tracker/AdminServer/TokenLine.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'tracker/AdminServer/TokenLine.cpp')
| -rw-r--r-- | tracker/AdminServer/TokenLine.cpp | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/tracker/AdminServer/TokenLine.cpp b/tracker/AdminServer/TokenLine.cpp new file mode 100644 index 0000000..d4df390 --- /dev/null +++ b/tracker/AdminServer/TokenLine.cpp @@ -0,0 +1,150 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +/* +** The copyright to the contents herein is the property of Valve, L.L.C. +** The contents may be used and/or copied only with the written permission of +** Valve, L.L.C., or in accordance with the terms and conditions stipulated in +** the agreement/contract under which the contents have been supplied. +** +******************************************************************************* +** +** Contents: +** +** TokenLine.cpp: implementation of the TokenLine class. +** +******************************************************************************/ + +#include "TokenLine.h" +#include <string.h> + + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + + +TokenLine::~TokenLine() +{ + +} + + +bool TokenLine::SetLine(const char * newLine) +{ + m_tokenNumber = 0; + + if (!newLine || ( strlen(newLine) >= (MAX_LINE_CHARS-1) ) ) + { + memset( m_fullLine, 0, MAX_LINE_CHARS ); + memset( m_tokenBuffer, 0, MAX_LINE_CHARS ); + return false; + } + + strncpy( m_fullLine, newLine, MAX_LINE_CHARS-1 ); + m_fullLine[ MAX_LINE_CHARS-1 ] = '\0'; + + strncpy( m_tokenBuffer, newLine, MAX_LINE_CHARS-1 ); + m_tokenBuffer[ MAX_LINE_CHARS-1 ] = '\0'; + + // parse tokens + char * charPointer = m_tokenBuffer; + + while (*charPointer && (m_tokenNumber < MAX_LINE_TOKENS)) + { + while (*charPointer && ((*charPointer <= 32) || (*charPointer > 126))) + charPointer++; + + if (*charPointer) + { + m_token[m_tokenNumber] = charPointer; + + // special treatment for quotes + if (*charPointer == '\"') + { + charPointer++; + m_token[m_tokenNumber] = charPointer; + while (*charPointer && (*charPointer != '\"') ) + charPointer++; + + } + else + { + m_token[m_tokenNumber] = charPointer; + while (*charPointer && ((*charPointer > 32) && (*charPointer <= 126))) + charPointer++; + } + + m_tokenNumber++; + + if (*charPointer) + { + *charPointer=0; + charPointer++; + } + } + } + + return (m_tokenNumber != MAX_LINE_TOKENS); +} + +char * TokenLine::GetLine() +{ + return m_fullLine; +} + +char * TokenLine::GetToken(int i) +{ + if (i >= m_tokenNumber) + return NULL; + return m_token[i]; + +} + +// if the given parm is not present return NULL +// otherwise return the address of the following token, or an empty string +char* TokenLine::CheckToken(char * parm) +{ + for (int i = 0 ; i < m_tokenNumber; i ++) + { + if (!m_token[i]) + continue; + if ( !strcmp (parm,m_token[i]) ) + { + char * ret = m_token[i+1]; + // if this token doesn't exist, since index i was the last + // return an empty string + if ( (i+1) == m_tokenNumber ) ret = ""; + return ret; + } + + } + + return NULL; +} + +int TokenLine::CountToken() +{ + int c = 0; + for (int i = 0 ; i < m_tokenNumber; i ++) + { + if (m_token[i]) + c++; + } + return c; +} + +char* TokenLine::GetRestOfLine(int i) +{ + if (i >= m_tokenNumber) + return NULL; + return m_fullLine + (m_token[i] - m_tokenBuffer); +} + +TokenLine::TokenLine(char * string) +{ + SetLine(string); +} + +TokenLine::TokenLine() +{ + +} |