2019-12-19 03:24:12 +00:00
|
|
|
#ifndef cwText_H
|
|
|
|
#define cwText_H
|
|
|
|
|
|
|
|
|
|
|
|
namespace cw
|
|
|
|
{
|
2020-03-23 14:42:16 +00:00
|
|
|
// Return 0 if s is null.
|
2019-12-19 03:24:12 +00:00
|
|
|
unsigned textLength( const char* s );
|
2023-12-03 16:21:57 +00:00
|
|
|
|
2023-12-06 20:22:41 +00:00
|
|
|
// If dst is non-null then dst is always 0-terminated.
|
|
|
|
// If src will be truncated if srcN > dstN-1.
|
|
|
|
// If dst is null then null is returned
|
|
|
|
// if src is null then dst[0] = 0.
|
|
|
|
// if srcN is 0 then textLength(src) is used for srcN
|
|
|
|
const char* textCopy( char* dst, unsigned dstN, const char* src, unsigned srcN=0 );
|
|
|
|
|
2023-12-03 16:21:57 +00:00
|
|
|
void textToLower( char* s );
|
|
|
|
void textToUpper( char* s );
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2023-07-26 00:20:45 +00:00
|
|
|
// Note: if both s0 and s1 are nullptr then a match is indicated
|
2019-12-19 03:24:12 +00:00
|
|
|
int textCompare( const char* s0, const char* s1 );
|
2019-12-24 15:05:24 +00:00
|
|
|
int textCompare( const char* s0, const char* s1, unsigned n);
|
2021-11-06 02:22:30 +00:00
|
|
|
|
|
|
|
inline bool textIsEqual( const char* s0, const char* s1 ) { return textCompare(s0,s1) == 0; }
|
|
|
|
inline bool textIsEqual( const char* s0, const char* s1, unsigned n ) { return textCompare(s0,s1,n) == 0; }
|
2020-03-23 14:42:16 +00:00
|
|
|
|
2021-11-06 02:22:30 +00:00
|
|
|
inline bool textIsNotEqual( const char* s0, const char* s1 ) { return !textIsEqual(s0,s1); }
|
|
|
|
inline bool textIsNotEqual( const char* s0, const char* s1, unsigned n ) { return !textIsEqual(s0,s1,n); }
|
|
|
|
|
2020-03-23 14:42:16 +00:00
|
|
|
// Return a pointer to the next white space char
|
|
|
|
// or nullptr if 's' is null are there are no whitespace char's.
|
|
|
|
const char* nextWhiteChar( const char* s );
|
|
|
|
|
|
|
|
|
|
|
|
// Return a pointer to the next white space char,
|
|
|
|
// a pointer to the EOS if there are no white space char's,
|
|
|
|
// or nullptr if 's' is null.
|
|
|
|
const char* nextWhiteCharEOS( const char* s );
|
|
|
|
|
|
|
|
// Return a pointer to the next non-white space char
|
|
|
|
// or nullptr if 's' is null are there are no non-whitespace char's.
|
|
|
|
const char* nextNonWhiteChar( const char* s );
|
|
|
|
|
|
|
|
// Return a pointer to the next non-white space char,
|
|
|
|
// a pointer to the EOS if there are no non-white space char's,
|
|
|
|
// or nullptr if 's' is null.
|
|
|
|
const char* nextNonWhiteCharEOS( const char* s );
|
|
|
|
|
2023-11-19 20:03:42 +00:00
|
|
|
// Return a pointer to the first occurrence of 'c' in s[] or nullptr
|
|
|
|
// if 'c' does not occur in s[]
|
|
|
|
const char* firstMatchChar( const char* s, char c );
|
|
|
|
// Find the last occurrent of 'c' in s[].
|
|
|
|
const char* lastMatchChar( const char* s, char c );
|
2023-07-26 00:20:45 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2020-08-20 00:12:19 +00:00
|
|
|
// Join s0 and s1 to form one long string. Release the returned string with mem::free()
|
|
|
|
char* textJoin( const char* s0, const char* s1 );
|
2020-03-23 14:42:16 +00:00
|
|
|
|
2020-08-20 00:12:19 +00:00
|
|
|
// Realloc s0 and append s1.
|
|
|
|
char* textAppend( char* s0, const char* s1 );
|
|
|
|
|
2020-03-23 14:42:16 +00:00
|
|
|
unsigned toText( char* buf, unsigned bufN, bool v );
|
|
|
|
unsigned toText( char* buf, unsigned bufN, unsigned char v );
|
|
|
|
unsigned toText( char* buf, unsigned bufN, char v );
|
|
|
|
unsigned toText( char* buf, unsigned bufN, unsigned short v );
|
|
|
|
unsigned toText( char* buf, unsigned bufN, short v );
|
|
|
|
unsigned toText( char* buf, unsigned bufN, unsigned int v );
|
|
|
|
unsigned toText( char* buf, unsigned bufN, int v );
|
2020-03-24 12:53:00 +00:00
|
|
|
unsigned toText( char* buf, unsigned bufN, unsigned long long v );
|
|
|
|
unsigned toText( char* buf, unsigned bufN, long long v );
|
2020-03-23 14:42:16 +00:00
|
|
|
unsigned toText( char* buf, unsigned bufN, float v );
|
|
|
|
unsigned toText( char* buf, unsigned bufN, double v );
|
|
|
|
unsigned toText( char* buf, unsigned bufN, const char* v );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-12-19 03:24:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|