#include <string.h>
#include <ctype.h>
#include <wctype.h>
#include <wchar.h>
#include <stdarg.h>
#include "ctl/cstring.h"
#include "ctl/mstring.h"
#include "ctl/fstring.h"
#include "ctl/gstring.h"
Go to the source code of this file.
Defines | |
#define | chconst(tchar, ch) ppConcat(chconst_,tchar)(ch) |
Make the "correct" kind of character constant by template tchar. | |
#define | szconst(tchar, sz) ppConcat(szconst_,tchar)(sz) |
Make the "correct" kind of string constant by template tchar. | |
#define | szconvert(tchardst, tcharsrc) (ch) ppConcat3(szconvert_,tchardst,tcharsrc) |
Convert from wchar_t<->char. | |
#define | szstrfmt(tchar) ppConcat(szstrfmt_,tchar) |
The 'standard' format is for ls when receiving wchar_t strings, and s when receiving char strings. | |
#define | ctl_chsize(tchar, length) (ppCtypeSelect(tchar,(size_t)(length),(length)*sizeof(tchar))) |
Calculate size of a string in bytes, based on character template. | |
#define | ctl_chlength(tchar, size) (ppCtypeSelect(tchar,(size_t)(size),(size)/sizeof(tchar))) |
Calculate length of a string in characters from its memory size, based on character template. | |
#define | ppCtypeSelect(tchar, xchar, xwchar_t) ppConcat(_ppCtypeSelect_,tchar)(xchar,xwchar_t) |
Make selection logic for character type handler a little more compact. | |
#define | chssize(tchar, length) (ppCtypeSelect(tchar,(size_t)(length),(length)*2)) |
Work out a string's serial size from its length. | |
#define | chslength(tchar, size) (ppCtypeSelect(tchar,(size_t)(size),(size)/2)) |
Work out a string's length from its serial size. | |
#define | cmemcpy(tchar, sDst, sSrc, count) memcpy( (sDst),(sSrc),ctl_chsize(tchar,count) ) |
Copy part of a string, ignoring NUL terminator. | |
#define | cmemmove(tchar, sDst, sSrc, count) memmove( (sDst),(sSrc),ctl_chsize(tchar,count) ) |
Copy part of a string, ignoring NUL terminator, may be overlapped. | |
Functions | |
char * | strnlabel (char *buff, const char *src, size_t buffSize) |
Make an input string of unknown content into a 'good' C label Whether it conflicts with another label, well that's your problem. | |
char * | strnupper (char *buff, const char *src, size_t buffSize) |
Make an input string upper-case. | |
char * | strnlower (char *buff, const char *src, size_t buffSize) |
Make an input string lower-case. | |
wchar_t * | wcsnlabel (wchar_t *buff, const wchar_t *src, size_t buffSize) |
Make an input string of unknown content into a 'good' C label Whether it conflicts with another label, well that's your problem. | |
wchar_t * | wcsnupper (wchar_t *buff, const wchar_t *src, size_t buffSize) |
Make an input string upper-case. | |
wchar_t * | wcsnlower (wchar_t *buff, const wchar_t *src, size_t buffSize) |
Make an input string lower-case. |
Currently these only support wchar_t or char. The wchar_t is for assumed to be wide (unicode) characters, and if it isn't defined for your target, just stick to char, or define all of the relevant translations and extensions, then plug them in as your own lib.
Definition in file ctlstring.h.
char* strnlabel | ( | char * | buff, | |
const char * | src, | |||
size_t | buffSize | |||
) |
Make an input string of unknown content into a 'good' C label Whether it conflicts with another label, well that's your problem.
buff | Buffer to accept 'fixed' string | |
src | Original string to copy/translate | |
buffSize | Count of characters reserved in buff, and/or size of src |
Definition at line 67 of file ctlstring.c.
00068 { 00069 char* ret = buff; 00070 if( !isalpha(*src) ) 00071 { 00072 /* Firse char must be alphabetic */ 00073 *buff++ = '_'; 00074 buffSize--; 00075 } 00076 while( *src && buffSize-- ) 00077 { 00078 if( isspace(*src) ) 00079 { 00080 /* Eat embedded spaces */ 00081 src++; 00082 } 00083 else if( !isalnum(*src) ) 00084 { 00085 /* Translate non-alphanumeric characters (including '_') into '_' */ 00086 *buff++ = '_'; 00087 src++; 00088 } 00089 else 00090 { 00091 *buff++ = *src++; 00092 } 00093 } 00094 if( buffSize >= 0 ) 00095 *buff = 0; 00096 return ret; 00097 }
char* strnlower | ( | char * | buff, | |
const char * | src, | |||
size_t | buffSize | |||
) |
Make an input string lower-case.
buff | Buffer to accept 'fixed' string | |
src | Original string to copy/translate | |
buffSize | Count of characters reserved in buff, and/or size of src |
Definition at line 123 of file ctlstring.c.
00124 { 00125 char* ret = buff; 00126 while( *src && buffSize-- ) 00127 *buff++ = (char)tolower(*src++); 00128 if( buffSize >= 0 ) 00129 *buff = 0; 00130 return ret; 00131 }
char* strnupper | ( | char * | buff, | |
const char * | src, | |||
size_t | buffSize | |||
) |
Make an input string upper-case.
buff | Buffer to accept 'fixed' string | |
src | Original string to copy/translate | |
buffSize | Count of characters reserved in buff, and/or size of src |
Definition at line 106 of file ctlstring.c.
00107 { 00108 char* ret = buff; 00109 while( *src && buffSize-- ) 00110 *buff++ = (char)toupper(*src++); 00111 if( buffSize >= 0 ) 00112 *buff = 0; 00113 return ret; 00114 }
wchar_t* wcsnlabel | ( | wchar_t * | buff, | |
const wchar_t * | src, | |||
size_t | buffSize | |||
) |
Make an input string of unknown content into a 'good' C label Whether it conflicts with another label, well that's your problem.
buff | Buffer to accept 'fixed' string | |
src | Original string to copy/translate | |
buffSize | Count of characters reserved in buff, and/or size of src |
Definition at line 141 of file ctlstring.c.
00142 { 00143 wchar_t* ret = buff; 00144 if( !cisalpha(wchar_t)(*src) ) 00145 { 00146 /* Firse char must be alphabetic */ 00147 *buff++ = '_'; 00148 buffSize--; 00149 } 00150 while( *src && buffSize-- ) 00151 { 00152 if( cisspace(wchar_t)(*src) ) 00153 { 00154 /* Eat embedded spaces */ 00155 src++; 00156 } 00157 if( !cisalnum(wchar_t)(*src) ) 00158 { 00159 /* Translate non-alphanumeric characters (including '_') into '_' */ 00160 *buff++ = '_'; 00161 src++; 00162 } 00163 else 00164 { 00165 *buff++ = *src++; 00166 } 00167 } 00168 if( buffSize >= 0 ) 00169 *buff = 0; 00170 return ret; 00171 }
wchar_t* wcsnlower | ( | wchar_t * | buff, | |
const wchar_t * | src, | |||
size_t | buffSize | |||
) |
Make an input string lower-case.
buff | Buffer to accept 'fixed' string | |
src | Original string to copy/translate | |
buffSize | Count of characters reserved in buff, and/or size of src |
Definition at line 197 of file ctlstring.c.
00198 { 00199 wchar_t* ret = buff; 00200 while( *src && buffSize-- ) 00201 *buff++ = ctolower(wchar_t)(*src++); 00202 if( buffSize >= 0 ) 00203 *buff = 0; 00204 return ret; 00205 }
wchar_t* wcsnupper | ( | wchar_t * | buff, | |
const wchar_t * | src, | |||
size_t | buffSize | |||
) |
Make an input string upper-case.
buff | Buffer to accept 'fixed' string | |
src | Original string to copy/translate | |
buffSize | Count of characters reserved in buff, and/or size of src |
Definition at line 180 of file ctlstring.c.
00181 { 00182 wchar_t* ret = buff; 00183 while( *src && buffSize-- ) 00184 *buff++ = ctoupper(wchar_t)(*src++); 00185 if( buffSize >= 0 ) 00186 *buff = 0; 00187 return ret; 00188 }