ctlstring.c File Reference

A place to manufacture string templates and related functions/data. More...

#include "ctl/ctldef.h"

Include dependency graph for ctlstring.c:

Go to the source code of this file.

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.


Detailed Description

A place to manufacture string templates and related functions/data.

Author:
David Mace 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.c.


Function Documentation

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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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 }


Generated on Fri Jan 2 15:28:35 2009 for Squat by  doxygen 1.5.6