cwText.h/cpp : Added isInteger(), isReal(), isIdentifier().
This commit is contained in:
parent
7201b63412
commit
7e6ab875c9
38
cwText.cpp
38
cwText.cpp
@ -82,6 +82,44 @@ const char* cw::nextNonWhiteChar( const char* s )
|
||||
const char* cw::nextNonWhiteCharEOS( const char* s )
|
||||
{ return _nextNonWhiteChar(s,true); }
|
||||
|
||||
bool cw::isInteger( const char* s )
|
||||
{
|
||||
for(; *s; ++s)
|
||||
if(!isdigit(*s))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cw::isReal( const char* s)
|
||||
{
|
||||
unsigned decN = 0;
|
||||
for(; *s; ++s)
|
||||
if( *s == '.' )
|
||||
{
|
||||
if( ++decN > 1)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!isdigit(*s))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cw::isIdentifier( const char* s )
|
||||
{
|
||||
if( !isalpha(*s) && *s != '_' )
|
||||
return false;
|
||||
|
||||
for(++s; *s; ++s)
|
||||
if( !isalnum(*s) && *s != '_' )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
char* cw::textJoin( const char* s0, const char* s1 )
|
||||
{
|
||||
|
7
cwText.h
7
cwText.h
@ -7,7 +7,7 @@ namespace cw
|
||||
// Return 0 if s is null.
|
||||
unsigned textLength( const char* s );
|
||||
|
||||
// if both s0 and s1 are nullptr then a match is indicated
|
||||
// Note: if both s0 and s1 are nullptr then a match is indicated
|
||||
int textCompare( const char* s0, const char* s1 );
|
||||
int textCompare( const char* s0, const char* s1, unsigned n);
|
||||
|
||||
@ -36,6 +36,11 @@ namespace cw
|
||||
// or nullptr if 's' is null.
|
||||
const char* nextNonWhiteCharEOS( const char* s );
|
||||
|
||||
|
||||
bool isInteger( const char* ); // text contains only [0-9]
|
||||
bool isReal( const char* ); // text contains only [0-9] with one decimal place
|
||||
bool isIdentifier( const char* ); // text is a legal id [0-9,A-Z,a-z,_] w/o leading number
|
||||
|
||||
// Join s0 and s1 to form one long string. Release the returned string with mem::free()
|
||||
char* textJoin( const char* s0, const char* s1 );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user