57 char*
ztrcpy(
size_t size,
char * dest,
const char * src ) {
58 if ( dest==NULL || size==0 ) {
return dest; }
59 else if ( size==1 ) { *dest=0;
return dest; }
65 if ( 0 == (*copy = *src) ) {
break; }
95 char*
ztrcat(
size_t size,
char * dest,
const char * src ) {
96 if ( dest==NULL || size==0 ) {
return dest; }
97 else if ( size==1 ) { *dest=0;
return dest; }
100 size_t destlen = strlen( dest );
102 if ( destlen>size ) { destlen = size; }
104 while ( destlen<size ) {
105 if ( 0 == (*copy = *src) ) {
break; }
106 ++copy; ++src; ++destlen;
144 char*
ztrins(
size_t size,
char * dest,
size_t n,
const char * insert ) {
145 if ( dest==NULL || size==0 ) {
return dest; }
146 else if ( size==1 ) { *dest=0;
return dest; }
148 size_t inslen, destlen = strlen( dest );
150 if ( destlen>size ) { destlen = size; }
151 if ( n>size || n>destlen || insert[0]==0 ) {
152 dest[size] = 0;
return dest;
154 inslen = strlen( insert );
155 if ( size <= n+inslen ) {
156 memmove( &dest[n] , insert, (size-n) );
159 if ( size <= destlen+inslen ) {
160 memmove( &dest[n+inslen], &dest[n], (size-(n+inslen)) );
163 memmove( &dest[n+inslen], &dest[n], (destlen-n) );
164 size = destlen+inslen;
166 memmove( &dest[n] , insert , inslen );
182 size_t MAX = ( (0==0) ? 500 : UINT_MAX/2 );
183 assert( inslen<MAX ); assert( n<MAX ); assert( destlen<MAX ); assert( size<MAX );
200 char*
strdel(
char * dest,
size_t len ) {
201 if ( dest==NULL || len==0 ) { }
202 else if ( dest[0]==0 ) {
return dest; }
204 size_t destlen = strlen( dest );
205 if ( destlen<=len ) { dest[0]=0; }
207 memmove( dest, dest+len, 1+(destlen-len) );
222 char*
ztrsub(
size_t size,
char * dest,
const char * src,
size_t len ) {
223 if ( dest==NULL || size==0 ) {
return dest; }
224 else if ( size==1 ) { *dest=0;
return dest; }
228 size = ( size < len ? size : len );
230 if ( 0 == (*copy = *src) ) {
break; }
231 ++copy; ++src; --size;
245 if ( src==NULL ) {
return NULL; }
261 if ( src==NULL ) {
return NULL; }
306 size_t memczap(
size_t size,
void * mem,
int ch ) {
322 size_t len, count = 0;
323 i = j = (
char*)(mem);
325 assert(
"needs improvement" );
328 if ( (i-j)> (ptrdiff_t)(size) ) {
335 while ( count<size ) {
351 size_t memczap_smaller(
size_t size,
void *mem,
int ch ) {
380 int strpfx(
const char *str,
const char *prefix ) {
381 while ( *prefix != 0 ) {
382 if ( *prefix!=*str ) {
return 0; }
393 int strsffx(
const char *str,
const char *suffix ) {
394 size_t slen = strlen( str );
395 size_t xlen = strlen( suffix );
396 if ( slen<xlen ) {
return 0; }
398 const char *pStr = str+slen;
399 const char *pSfx = suffix+xlen;
400 while ( pSfx != suffix ) {
401 if ( *pStr!=*pSfx ) {
return 0; }
421 size_t strrspn(
const char * str,
char a,
char z ) {
423 while ( ((*str)!=0) && (a<=(*str)) && ((*str)<=z) ) {
451 tr =
"AAAAAAECEEEEIIIIDNOOOOOx0UUUUYPsaaaaaaeceeeeiiiidnooooo/0uuuuypy";
452 size_t char ch = (*p);
465 char*
strtokl(
char * str,
const char * delimiters ,
size_t *len );
474 char str[] =
"- This, a sample string.";
476 printf (
"Splitting string \"%s\" into tokens:\n",str);
477 pch = strtok (str,
" ,.-");
478 while (pch != NULL) {
480 pch = strtok (NULL,
" ,.-");
486 char str[] =
"- This, a sample string.";
489 printf (
"Splitting string \"%s\" into tokens:\n",str);
490 pch =
strtokl (str,
" ,.-",&len);
491 while (pch != NULL) {
size_t strrspn(const char *str, char a, char z)
Get span until character in character range '[a..z]'.
char * ztrcat(size_t size, char *dest, const char *src)
Append characters to a string.
int strsffx(const char *str, const char *suffix)
Returns '1' if 'suffix' is a suffix of 'str'.
char * strrtrim(char *src, char tr)
Removes from 'str' all trailing characters that are equal to 'tr'.
A few string functions to enhance C's <string.h> library.
char * strltrim(const char *src, char tr)
Returns a pointer to the first character in 'str' different from 'tr'.
char * strtrim(char *src, char tr)
return strrtrim( strltrim(s,tr),tr ).
char * ztrins(size_t size, char *dest, size_t n, const char *insert)
Inserts string 'insert' into 'dest' at position 'n'.
char * strdel(char *dest, size_t len)
Deletes the leading 'len' characters from 'str'.
char * ztrsub(size_t size, char *dest, const char *src, size_t len)
Copies the first 'len' characters from 'src' to 'dest'.
char * ztrcpy(size_t size, char *dest, const char *src)
Copies up to 'size' characters from 'src' to 'dest'.
char * strxacct(char *str)
Uses strxltn1() to convert all letters in 'str'.
char * strtokl(char *str, const char *delimiters, size_t *len)
char strxltn1(char accented_latin_1)
Translates characters in range [192<–>192+63] into letters or ASCII symbols that look similar...
size_t memczap(size_t size, void *mem, int ch)
Removes every ocurrence of 'ch' from 'mem'.
int strpfx(const char *str, const char *prefix)
Returns '1' if 'prefix' is a prefix of 'str'.
[u]Micro module for [Unit] program testing.