Added Text Hex Testing/Conversion

This commit is contained in:
mpohoreski 2006-02-28 16:36:51 +00:00
parent 8c35d2592c
commit 9812789706
1 changed files with 131 additions and 78 deletions

View File

@ -55,6 +55,7 @@ inline const char* SkipEOL ( const char *pSrc )
return pSrc;
}
*/
inline const char* EatEOL ( const char *pSrc )
{
if (pSrc)
@ -67,6 +68,7 @@ inline const char* EatEOL ( const char *pSrc )
}
return pSrc;
}
inline const char* SkipWhiteSpace ( const char *pSrc )
{
while (pSrc && ((*pSrc == CHAR_SPACE) || (*pSrc == CHAR_TAB)))
@ -75,6 +77,7 @@ inline const char* SkipWhiteSpace ( const char *pSrc )
}
return pSrc;
}
inline const char* SkipWhiteSpaceReverse ( const char *pSrc, const char *pStart )
{
while (pSrc && ((*pSrc == CHAR_SPACE) || (*pSrc == CHAR_TAB)) && (pSrc > pStart))
@ -84,7 +87,6 @@ inline const char* SkipWhiteSpaceReverse ( const char *pSrc, const char *pS
return pSrc;
}
inline const char* SkipUntilChar ( const char *pSrc, const char nDelim )
{
while (pSrc && (*pSrc))
@ -95,6 +97,7 @@ inline const char* SkipUntilChar ( const char *pSrc, const char nDe
}
return pSrc;
}
inline const char* SkipUntilEOL ( const char *pSrc )
{
// EOL delims: NULL, LF, CR
@ -136,6 +139,7 @@ inline const char* SkipUntilToken ( const char *pSrc, const TokenTab
}
return pSrc;
}
inline const char* SkipUntilWhiteSpace ( const char *pSrc )
{
while (pSrc && (*pSrc))
@ -181,4 +185,53 @@ inline const char* SkipUntilWhiteSpaceReverse ( const char *pSrc, const char *pS
// 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