Split some of Debugger_parser.h into Util_Text.h (now Util_MemoryTextFile.cpp isn't dependent on any Debugger headers

This commit is contained in:
tomcw 2014-08-13 22:03:33 +01:00
parent 6a26a95487
commit 6ce0f6c77f
4 changed files with 195 additions and 202 deletions

View File

@ -354,6 +354,10 @@
RelativePath=".\source\Util_MemoryTextFile.h"
>
</File>
<File
RelativePath=".\source\Util_Text.h"
>
</File>
</Filter>
<Filter
Name="Uthernet"

View File

@ -1,13 +1,27 @@
#ifndef DEBUGGER_PARSER_H
#define DEBUGGER_PARSER_H
#define CHAR_LF '\x0D'
#define CHAR_CR '\x0A'
#define CHAR_SPACE ' '
#define CHAR_TAB '\t'
#define CHAR_QUOTE_DOUBLE '"'
#define CHAR_QUOTE_SINGLE '\''
#define CHAR_ESCAPE '\x1B'
#include "..\Util_Text.h"
const char * ParserFindToken( const char *pSrc, const TokenTable_t *aTokens, const int nTokens, ArgToken_e * pToken_ );
const TCHAR * FindTokenOrAlphaNumeric ( const TCHAR *pSrc, const TokenTable_t *aTokens, const int nTokens, ArgToken_e * pToken_ );
int RemoveWhiteSpaceReverse( char *pSrc );
void TextConvertTabsToSpaces( TCHAR *pDeTabified_, LPCTSTR pText, const int nDstSize, int nTabStop = 0 );
inline const char* SkipUntilToken( const char *pSrc, const TokenTable_t *aTokens, const int nTokens, ArgToken_e *pToken_ )
{
if ( pToken_)
*pToken_ = NO_TOKEN;
while (pSrc && (*pSrc))
{
if (ParserFindToken( pSrc, aTokens, nTokens, pToken_ ))
return pSrc;
pSrc++;
}
return pSrc;
}
// Globals __________________________________________________________________
@ -43,198 +57,4 @@
void ArgsRawParse ( void );
int ArgsCook ( const int nArgs ); // const int bProcessMask );
// Token
const char * ParserFindToken( const char *pSrc, const TokenTable_t *aTokens, const int nTokens, ArgToken_e * pToken_ );
// Text Util
/*
inline const char* SkipEOL ( const char *pSrc )
{
while (pSrc && ((*pSrc == CHAR_LF) || (*pSrc == CHAR_CR)))
if (pSrc)
{
pSrc++;
}
return pSrc;
}
*/
inline const char* EatEOL ( const char *pSrc )
{
if (pSrc)
{
if (*pSrc == CHAR_LF)
pSrc++;
if (*pSrc == CHAR_CR)
pSrc++;
}
return pSrc;
}
inline const char* SkipWhiteSpace ( const char *pSrc )
{
while (pSrc && ((*pSrc == CHAR_SPACE) || (*pSrc == CHAR_TAB)))
{
pSrc++;
}
return pSrc;
}
inline const char* SkipWhiteSpaceReverse ( const char *pSrc, const char *pStart )
{
while (pSrc && ((*pSrc == CHAR_SPACE) || (*pSrc == CHAR_TAB)) && (pSrc > pStart))
{
pSrc--;
}
return pSrc;
}
inline const char* SkipUntilChar ( const char *pSrc, const char nDelim )
{
while (pSrc && (*pSrc))
{
if (*pSrc == nDelim)
break;
pSrc++;
}
return pSrc;
}
inline const char* SkipUntilEOL ( const char *pSrc )
{
// EOL delims: NULL, LF, CR
while (pSrc && (*pSrc))
{
if ((*pSrc == CHAR_LF) || (*pSrc == CHAR_CR))
{
break;
}
pSrc++;
}
return pSrc;
}
inline const char* SkipUntilTab ( const char *pSrc)
{
while (pSrc && (*pSrc))
{
if (*pSrc == CHAR_TAB)
{
break;
}
pSrc++;
}
return pSrc;
}
inline const char* SkipUntilToken ( const char *pSrc, const TokenTable_t *aTokens, const int nTokens, ArgToken_e *pToken_ )
{
if ( pToken_)
*pToken_ = NO_TOKEN;
while (pSrc && (*pSrc))
{
if (ParserFindToken( pSrc, aTokens, nTokens, pToken_ ))
return pSrc;
pSrc++;
}
return pSrc;
}
inline const char* SkipUntilWhiteSpace ( const char *pSrc )
{
while (pSrc && (*pSrc))
{
if ((*pSrc == CHAR_SPACE) || (*pSrc == CHAR_TAB))
{
break;
}
pSrc++;
}
return pSrc;
}
inline const char* SkipUntilWhiteSpaceReverse ( const char *pSrc, const char *pStart )
{
while (pSrc && (pSrc > pStart))
{
if ((*pSrc == CHAR_SPACE) || (*pSrc == CHAR_TAB))
{
break;
}
pSrc--;
}
return pSrc;
}
/*
const TCHAR* SkipEOL ( const TCHAR *pSrc );
const TCHAR* SkipWhiteSpace ( const TCHAR *pSrc );
const TCHAR* SkipWhiteSpaceReverse ( const TCHAR *pSrc, const TCHAR *pStart );
const TCHAR* SkipUntilChar ( const TCHAR *pSrc, const TCHAR nDelim );
const TCHAR* SkipUntilEOL ( const TCHAR *pSrc );
const TCHAR* SkipUntilToken ( const TCHAR *pSrc, const TokenTable_t *aTokens, const int nTokens, ArgToken_e *pToken_ );
const TCHAR* SkipUntilWhiteSpace ( const TCHAR *pSrc );
const TCHAR* SkipUntilWhiteSpaceReverse ( const TCHAR *pSrc, const TCHAR *pStart );
const TCHAR* SkipUntilTab ( const TCHAR *pSrc);
*/
const TCHAR * FindTokenOrAlphaNumeric ( const TCHAR *pSrc, const TokenTable_t *aTokens, const int nTokens, ArgToken_e * pToken_ );
// TextRemoveWhiteSpaceReverse
int RemoveWhiteSpaceReverse ( char *pSrc );
// TextExpandTabsToSpaces
void TextConvertTabsToSpaces( TCHAR *pDeTabified_, LPCTSTR pText, const int nDstSize, int nTabStop = 0 );
/** Assumes text are valid hex digits!
//=========================================================================== */
inline BYTE TextConvert2CharsToByte ( char *pText )
{
BYTE n = ((pText[0] <= '@') ? (pText[0] - '0') : (pText[0] - 'A' + 10)) << 4;
n += ((pText[1] <= '@') ? (pText[1] - '0') : (pText[1] - 'A' + 10)) << 0;
return n;
}
//===========================================================================
inline bool TextIsHexChar( char nChar )
{
if ((nChar >= '0') && (nChar <= '9'))
return true;
if ((nChar >= 'A') && (nChar <= 'F'))
return true;
if ((nChar >= 'a') && (nChar <= 'f'))
return true;
return false;
}
//===========================================================================
inline bool TextIsHexByte( char *pText )
{
if (TextIsHexChar( pText[0] ) &&
TextIsHexChar( pText[1] ))
return true;
return false;
}
//===========================================================================
inline bool TextIsHexString ( LPCSTR pText )
{
while (*pText)
{
if (! TextIsHexChar( *pText ))
return false;
pText++;
}
return true;
}
#endif

View File

@ -22,8 +22,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "StdAfx.h"
#include <vector>
using namespace std;
#include "Debugger\Debug.h" // Debugger_Parser.h: SkipUntilEOL(), EatEOL(), CHAR_CR, CHAR_LF
#include "Util_Text.h"
#include "Util_MemoryTextFile.h"
// MemoryTextFile _________________________________________________________________________________

166
source/Util_Text.h Normal file
View File

@ -0,0 +1,166 @@
#define CHAR_LF '\x0D'
#define CHAR_CR '\x0A'
#define CHAR_SPACE ' '
#define CHAR_TAB '\t'
#define CHAR_QUOTE_DOUBLE '"'
#define CHAR_QUOTE_SINGLE '\''
#define CHAR_ESCAPE '\x1B'
// Text Util
/*
inline const char* SkipEOL ( const char *pSrc )
{
while (pSrc && ((*pSrc == CHAR_LF) || (*pSrc == CHAR_CR)))
if (pSrc)
{
pSrc++;
}
return pSrc;
}
*/
inline const char* EatEOL ( const char *pSrc )
{
if (pSrc)
{
if (*pSrc == CHAR_LF)
pSrc++;
if (*pSrc == CHAR_CR)
pSrc++;
}
return pSrc;
}
inline const char* SkipWhiteSpace ( const char *pSrc )
{
while (pSrc && ((*pSrc == CHAR_SPACE) || (*pSrc == CHAR_TAB)))
{
pSrc++;
}
return pSrc;
}
inline const char* SkipWhiteSpaceReverse ( const char *pSrc, const char *pStart )
{
while (pSrc && ((*pSrc == CHAR_SPACE) || (*pSrc == CHAR_TAB)) && (pSrc > pStart))
{
pSrc--;
}
return pSrc;
}
inline const char* SkipUntilChar ( const char *pSrc, const char nDelim )
{
while (pSrc && (*pSrc))
{
if (*pSrc == nDelim)
break;
pSrc++;
}
return pSrc;
}
inline const char* SkipUntilEOL ( const char *pSrc )
{
// EOL delims: NULL, LF, CR
while (pSrc && (*pSrc))
{
if ((*pSrc == CHAR_LF) || (*pSrc == CHAR_CR))
{
break;
}
pSrc++;
}
return pSrc;
}
inline const char* SkipUntilTab ( const char *pSrc)
{
while (pSrc && (*pSrc))
{
if (*pSrc == CHAR_TAB)
{
break;
}
pSrc++;
}
return pSrc;
}
inline const char* SkipUntilWhiteSpace ( const char *pSrc )
{
while (pSrc && (*pSrc))
{
if ((*pSrc == CHAR_SPACE) || (*pSrc == CHAR_TAB))
{
break;
}
pSrc++;
}
return pSrc;
}
inline const char* SkipUntilWhiteSpaceReverse ( const char *pSrc, const char *pStart )
{
while (pSrc && (pSrc > pStart))
{
if ((*pSrc == CHAR_SPACE) || (*pSrc == CHAR_TAB))
{
break;
}
pSrc--;
}
return pSrc;
}
/** Assumes text are valid hex digits!
//=========================================================================== */
inline BYTE TextConvert2CharsToByte ( char *pText )
{
BYTE n = ((pText[0] <= '@') ? (pText[0] - '0') : (pText[0] - 'A' + 10)) << 4;
n += ((pText[1] <= '@') ? (pText[1] - '0') : (pText[1] - 'A' + 10)) << 0;
return n;
}
//===========================================================================
inline bool TextIsHexChar( char nChar )
{
if ((nChar >= '0') && (nChar <= '9'))
return true;
if ((nChar >= 'A') && (nChar <= 'F'))
return true;
if ((nChar >= 'a') && (nChar <= 'f'))
return true;
return false;
}
//===========================================================================
inline bool TextIsHexByte( char *pText )
{
if (TextIsHexChar( pText[0] ) &&
TextIsHexChar( pText[1] ))
return true;
return false;
}
//===========================================================================
inline bool TextIsHexString ( LPCSTR pText )
{
while (*pText)
{
if (! TextIsHexChar( *pText ))
return false;
pText++;
}
return true;
}