int test_addchar( newstr *s ) { int failed = 0; int numshort = 5, numchars = 1000, i; /* ...appending '\0' characters won't increase length */ newstr_empty( s ); for ( i=0; i<numshort; ++i ) newstr_addchar( s, '\0' ); if ( test_consistency( s, 0, __FUNCTION__ ) || test_identity( s, "" ) ) failed++; /* ...build "11111" with newstr_addchar */ newstr_empty( s ); for ( i=0; i<numshort; ++i ) newstr_addchar( s, '1' ); if ( test_consistency( s, 5, __FUNCTION__ ) || test_identity( s, "11111" ) ) failed++; newstr_empty( s ); for ( i=0; i<numchars; ++i ) { newstr_addchar( s, ( i % 64 ) + 64); } if ( test_consistency( s, numchars, __FUNCTION__ ) ) failed++; return failed; }
static char* process_bibtexid( char *p, newstr *id ) { char *start_p = p; newstr tmp; newstr_init( &tmp ); p = newstr_cpytodelim( &tmp, p, ",", 1 ); if ( tmp.len ) { if ( strchr( tmp.data, '=' ) ) { /* Endnote writes bibtex files w/o fields, try to * distinguish via presence of an equal sign.... if * it's there, assume that it's a tag/data pair instead * and roll back. */ p = start_p; newstr_empty( id ); } else { newstr_strcpy( id, tmp.data ); } } else { newstr_empty( id ); } newstr_free( &tmp ); return skip_ws( p ); }
int endin_processf( fields *endin, char *p, char *filename, long nref ) { newstr tag, data; int n; newstr_init( &tag ); newstr_init( &data ); while ( *p ) { if ( endin_istag( p ) ) { p = process_endline( &tag, &data, p ); /* no empty fields allowed */ if ( data.len ) { fields_add( endin, tag.data, data.data, 0 ); } } else { p = process_endline2( &tag, &data, p ); /* endnote puts %K only on 1st line of keywords */ n = endin->nfields; if ( n>0 && data.len ) { if ( !strncmp( endin->tag[n-1].data, "%K", 2 ) ) { fields_add( endin, "%K", data.data, 0 ); } else { newstr_addchar( &(endin->data[n-1]), ' ' ); newstr_strcat( &(endin->data[n-1]), data.data ); } } } newstr_empty( &tag ); newstr_empty( &data ); } newstr_free( &tag ); newstr_free( &data ); return 1; }
/* char *newstr_caytodelim ( newstr *s, char *p, const char *delim, unsigned char finalstep ); */ static int test_cattodelim( newstr *s ) { char str1[] = "1 1 1 1 1 1 1"; int failed = 0, i, n = 2; char *q; newstr_empty( s ); for ( i=0; i<n; ++i ) { q = newstr_cattodelim( s, str1, " ", 0 ); if ( *q!=' ' ) { fprintf( stdout, "%s line %d: newstr_cattodelim() returned '%c', expected ' '\n", __FUNCTION__, __LINE__, *q ); failed++; } } if ( string_mismatch( s, n, "11" ) ) failed++; newstr_empty( s ); q = str1; while ( *q ) { q = newstr_cattodelim( s, q, " ", 1 ); if ( *q!='1' && *q!='\0' ) { fprintf( stdout, "%s line %d: newstr_cattodelim() returned '%c', expected '1' or '\\0' \n", __FUNCTION__, __LINE__, *q ); failed++; } } if ( string_mismatch( s, 7, "1111111" ) ) failed++; return failed; }
int test_strcpy( newstr *s ) { int failed = 0; int numstrings = 1000, i; /* Copying null string should reset string */ newstr_empty( s ); for ( i=0; i<numstrings; ++i ) { newstr_strcpy( s, "1" ); newstr_strcpy( s, "" ); if ( test_consistency( s, 0, __FUNCTION__ ) || test_identity( s, "" ) ) failed++; } newstr_empty( s ); for ( i=0; i<numstrings; ++i ) { newstr_strcpy( s, "1" ); if ( test_consistency( s, 1, __FUNCTION__ ) || test_identity( s, "1" ) ) failed++; } newstr_empty( s ); for ( i=0; i<numstrings; ++i ) { newstr_strcpy( s, "XXOO" ); if ( test_consistency( s, 4, __FUNCTION__ ) || test_identity( s, "XXOO" ) ) failed++; } return failed; }
int risin_processf( fields *risin, char *p, char *filename, long nref ) { newstr tag, data; newstr_init( &tag ); newstr_init( &data ); while ( *p ) { if ( risin_istag( p ) ) { p = process_line( &tag, &data, p ); /* no anonymous fields allowed */ /* if ( tag.len && data.len )*/ if ( tag.len ) fields_add( risin, tag.data, data.data, 0 ); } else { p = process_line2( &tag, &data, p ); if ( data.len && risin->nfields>0 ) { newstr *od; od = &(risin->data[risin->nfields-1] ); newstr_addchar( od, ' ' ); newstr_strcat( od, data.data ); } } newstr_empty( &tag ); newstr_empty( &data ); } newstr_free( &tag ); newstr_free( &data ); return 1; }
int isiin_processf( fields *isiin, char *p, char *filename, long nref ) { newstr tag, data; int n; newstr_init( &tag ); newstr_init( &data ); while ( *p ) { newstr_empty( &tag ); newstr_empty( &data ); p = process_isiline( &tag, &data, p ); if ( !data.len ) continue; if ( (tag.len>1) && isiin_istag( tag.data ) ) { fields_add( isiin, tag.data, data.data, 0 ); } else { n = isiin->nfields; if ( n>0 ) { /* only one AU or AF for list of authors */ if ( !strcmp( isiin->tag[n-1].data,"AU") ){ fields_add( isiin, "AU", data.data, 0); } else if ( !strcmp( isiin->tag[n-1].data,"AF") ){ fields_add( isiin, "AF", data.data, 0); } /* otherwise append multiline data */ else { newstr_addchar( &(isiin->data[n-1]),' '); newstr_strcat( &(isiin->data[n-1]), data.data ); } } } } newstr_free( &data ); newstr_free( &tag ); return 1; }
static int test_addchar( newstr *s ) { int failed = 0; int numshort = 5, numchars = 1000, i; /* ...appending '\0' characters won't increase length */ newstr_empty( s ); for ( i=0; i<numshort; ++i ) newstr_addchar( s, '\0' ); if ( string_mismatch( s, 0, "" ) ) failed++; /* ...build "11111" with newstr_addchar */ newstr_empty( s ); for ( i=0; i<numshort; ++i ) newstr_addchar( s, '1' ); if ( string_mismatch( s, 5, "11111" ) ) failed++; /* ...build a bunch of random characters */ newstr_empty( s ); for ( i=0; i<numchars; ++i ) { newstr_addchar( s, ( i % 64 ) + 64); } if ( inconsistent_len( s, numchars ) ) failed++; return failed; }
static int test_segcat( newstr *s ) { char segment[]="0123456789"; char *start=&(segment[2]), *end=&(segment[5]); int numstrings = 1000, i; int failed = 0; newstr t, u; newstr_init( &t ); newstr_init( &u ); newstr_empty( s ); newstr_segcpy( s, start, start ); if ( string_mismatch( s, 0, "" ) ) failed++; newstr_segcpy( &t, start, start ); if ( string_mismatch( &t, 0, "" ) ) failed++; newstr_segcpy( &u, start, end ); if ( string_mismatch( &u, 3, "234" ) ) failed++; newstr_empty( s ); for ( i=0; i<numstrings; ++i ) newstr_segcat( s, start, end ); if ( inconsistent_len( s, 3*numstrings ) ) failed++; newstr_free( &t ); newstr_free( &u ); return failed; }
static int test_strcpy( newstr *s ) { int failed = 0; int numstrings = 1000, i; /* Copying null string should reset string */ newstr_empty( s ); for ( i=0; i<numstrings; ++i ) { newstr_strcpy( s, "1" ); newstr_strcpy( s, "" ); if ( string_mismatch( s, 0, "" ) ) failed++; } /* Many rounds of copying just "1" should give "1" */ newstr_empty( s ); for ( i=0; i<numstrings; ++i ) { newstr_strcpy( s, "1" ); if ( string_mismatch( s, 1, "1" ) ) failed++; } /* Many rounds of copying just "XXOO" should give "XXOO" */ newstr_empty( s ); for ( i=0; i<numstrings; ++i ) { newstr_strcpy( s, "XXOO" ); if ( string_mismatch( s, 4, "XXOO" ) ) failed++; } return failed; }
static int test_indxcat( newstr *s ) { char segment[]="0123456789"; int numstrings = 3, i; newstr t, u; int failed = 0; newstr_init( &t ); newstr_init( &u ); newstr_empty( s ); newstr_indxcat( s, segment, 2, 2 ); if ( string_mismatch( s, 0, "" ) ) failed++; newstr_indxcat( &t, segment, 2, 2 ); if ( string_mismatch( &t, 0, "" ) ) failed++; newstr_indxcat( &u, segment, 2, 5 ); if ( string_mismatch( &u, 3, "234" ) ) failed++; newstr_empty( s ); for ( i=0; i<numstrings; ++i ) newstr_indxcat( s, segment, 2, 5 ); if ( string_mismatch( s, 9, "234234234" ) ) failed++; newstr_free( &t ); newstr_free( &u ); return failed; }
/* extract_range() * * Handle input strings like: * * "1-15" * " 1 - 15 " * " 1000--- 1500" * " 1 <<em-dash>> 10" * " 107 111" */ static void extract_range( newstr *input, newstr *begin, newstr *end ) { /* -30 is the first character of a UTF8 em-dash and en-dash */ const char terminators[] = { ' ', '-', '\t', '\r', '\n', -30, '\0' }; char *p; newstr_empty( begin ); newstr_empty( end ); if ( input->len==0 ) return; p = skip_ws( input->data ); while ( *p && !strchr( terminators, *p ) ) newstr_addchar( begin, *p++ ); p = skip_ws( p ); while ( *p=='-' ) p++; while ( utf8_is_emdash( p ) ) p+=3; while ( utf8_is_endash( p ) ) p+=3; p = skip_ws( p ); while ( *p && !strchr( terminators, *p ) ) newstr_addchar( end, *p++ ); }
int copacin_readf( FILE *fp, char *buf, int bufsize, int *bufpos, newstr *line, newstr *reference, int *fcharset ) { int haveref = 0, inref=0; char *p; while ( !haveref && readmore( fp, buf, bufsize, bufpos, line ) ) { /* blank line separates */ if ( line->data==NULL ) continue; if ( inref && line->len==0 ) haveref=1; p = &(line->data[0]); if ( copacin_istag( p ) ) { if ( inref ) newstr_addchar( reference, '\n' ); newstr_strcat( reference, p ); newstr_empty( line ); inref = 1; } else if ( inref ) { if ( p ) { /* copac puts tag only on 1st line */ newstr_addchar( reference, ' ' ); if ( *p ) p++; if ( *p ) p++; if ( *p ) p++; newstr_strcat( reference, p ); } newstr_empty( line ); } else { newstr_empty( line ); } } *fcharset = CHARSET_UNKNOWN; return haveref; }
/* * readf() * * returns zero if cannot get reference and hit end of-file * returns 1 if last reference in file, 2 if reference within file */ int bibtexin_readf( FILE *fp, char *buf, int bufsize, int *bufpos, newstr *line, newstr *reference, int *fcharset ) { int haveref = 0; char *p; *fcharset = CHARSET_UNKNOWN; while ( haveref!=2 && readmore( fp, buf, bufsize, bufpos, line ) ) { if ( line->len == 0 ) continue; /* blank line */ p = &(line->data[0]); /* Recognize UTF8 BOM */ if ( line->len > 2 && (unsigned char)(p[0])==0xEF && (unsigned char)(p[1])==0xBB && (unsigned char)(p[2])==0xBF ) { *fcharset = CHARSET_UNICODE; p += 3; } p = skip_ws( p ); if ( *p == '%' ) { /* commented out line */ newstr_empty( line ); continue; } if ( *p == '@' ) haveref++; if ( haveref && haveref<2 ) { newstr_strcat( reference, p ); newstr_addchar( reference, '\n' ); newstr_empty( line ); } else if ( !haveref ) newstr_empty( line ); } return haveref; }
int copacin_processf( fields *copacin, char *p, char *filename, long nref ) { newstr tag, data; int status; newstr_init( &tag ); newstr_init( &data ); while ( *p ) { p = skip_ws( p ); if ( copacin_istag( p ) ) { p = copacin_addtag2( p, &tag, &data ); /* don't add empty strings */ if ( tag.len && data.len ) { status = fields_add( copacin, tag.data, data.data, 0 ); if ( status!=FIELDS_OK ) return 0; } newstr_empty( &tag ); newstr_empty( &data ); } else p = copacin_nextline( p ); } newstr_free( &tag ); newstr_free( &data ); return 1; }
static void xxx_to_url( fields *f, int n, char *http_prefix, char *urltag, newstr *xxx_url ) { newstr_empty( xxx_url ); construct_url( http_prefix, fields_value( f, n, FIELDS_STRP ), xxx_url ); if ( url_exists( f, urltag, xxx_url ) ) newstr_empty( xxx_url ); }
static int test_newstrcat( newstr *s ) { int numshort = 5, numstrings = 1000, i; int failed = 0; newstr t; newstr_init( &t ); /* ...adding empty strings to an empty string shouldn't change length */ newstr_empty( s ); for ( i=0; i<numstrings; ++i ) newstr_newstrcat( s, &t ); if ( string_mismatch( s, 0, "" ) ) failed++; /* ...adding empty strings to a defined string shouldn't change string */ newstr_strcpy( s, "1" ); for ( i=0; i<numstrings; ++i ) newstr_newstrcat( s, &t ); if ( string_mismatch( s, 1, "1" ) ) failed++; /* ...build "1111" with newstr_strcat */ newstr_empty( s ); newstr_strcpy( &t, "1" ); for ( i=0; i<numshort; ++i ) newstr_newstrcat( s, &t ); if ( string_mismatch( s, numshort, "11111" ) ) failed++; /* ...build "xoxoxoxoxo" with newstr_strcat */ newstr_empty( s ); newstr_strcpy( &t, "xo" ); for ( i=0; i<numshort; ++i ) newstr_newstrcat( s, &t ); if ( string_mismatch( s, numshort*2, "xoxoxoxoxo" ) ) failed++; newstr_empty( s ); newstr_strcpy( &t, "1" ); for ( i=0; i<numstrings; ++i ) newstr_newstrcat( s, &t ); if ( inconsistent_len( s, numstrings ) ) failed++; newstr_empty( s ); newstr_strcpy( &t, "XXOO" ); for ( i=0; i<numstrings; ++i ) newstr_newstrcat( s, &t ); if ( inconsistent_len( s, numstrings*4 ) ) failed++; newstr_free( &t ); return failed; }
int test_empty( newstr *s ) { int failed = 0; int numchars = 1000, i, j; newstr_empty( s ); for ( i=0; i<numchars; ++i ) { for ( j=0; j<i; ++j ) newstr_addchar( s, 'x' ); newstr_empty( s ); if ( test_consistency( s, 0, __FUNCTION__ ) || test_identity( s, "" ) ) failed++; } return failed; }
static void cleanup_wiley_author( fields *endin, int n ) { newstr tmp, tmppart; int i, nauthor = 0; newstrs_init( &tmp, &tmppart, NULL ); newstr_newstrcpy( &tmp, &( endin->data[n] ) ); i = 0; while ( i<tmp.len ) { if ( tmp.data[i]==',' ) { if ( nauthor==0 ) newstr_newstrcpy( &(endin->data[n]), &tmppart ); else fields_add( endin, endin->tag[n].data, tmppart.data, endin->level[n] ); newstr_empty( &tmppart ); nauthor++; while ( i<tmp.len && is_ws( tmp.data[i] ) ) i++; } else { newstr_addchar( &tmppart, tmp.data[i] ); } i++; } newstrs_free( &tmp, &tmppart, NULL ); }
static int test_makepath( newstr *s ) { int failed = 0; newstr_empty( s ); newstr_makepath( s, "", "", '/' ); if ( string_mismatch( s, 0, "" ) ) failed++; newstr_makepath( s, "", "file1.txt", '/' ); if ( string_mismatch( s, 9, "file1.txt" ) ) failed++; newstr_makepath( s, "/home/user", "", '/' ); if ( string_mismatch( s, 11, "/home/user/" ) ) failed++; newstr_makepath( s, "/home/user", "file1.txt", '/' ); if ( string_mismatch( s, 20, "/home/user/file1.txt" ) ) failed++; newstr_makepath( s, "/home/user/", "", '/' ); if ( string_mismatch( s, 11, "/home/user/" ) ) failed++; newstr_makepath( s, "/home/user/", "file1.txt", '/' ); if ( string_mismatch( s, 20, "/home/user/file1.txt" ) ) failed++; return failed; }
static void bibtex_cleandata( newstr *s, fields *info, param *p ) { list tokens; int i; if ( !s->len ) return; list_init( &tokens ); bibtex_split( &tokens, s ); for ( i=0; i<tokens.n; ++i ) { if ( !bibtex_protected( &(tokens.str[i] ) ) ) { bibtex_usestrings( &(tokens.str[i]) ); } else { if (!strncasecmp(tokens.str[i].data,"\\href{", 6)) { bibtex_addtitleurl( info, &(tokens.str[i]) ); } bibtex_cleantoken( &(tokens.str[i]), p ); } } newstr_empty( s ); for ( i=0; i<tokens.n; ++i ) { if ( bibtex_protected( &(tokens.str[i]) ) ) bibtex_removeprotection( &(tokens.str[i])); newstr_strcat( s, tokens.str[i].data ); } list_free( &tokens ); }
/* get reference name */ static char* process_bibtexid( char *p, newstr *data ) { newstr tmp; char *start_p = p; newstr_init( &tmp ); newstr_empty( data ); while ( *p && *p!=',' ) newstr_addchar( &tmp, *p++ ); if ( *p==',' ) p++; p = skip_ws( p ); /* skip ending newline/carriage return */ if ( tmp.len ) { if ( strchr( tmp.data, '=' ) ) { /* Endnote writes bibtex files w/o fields, try to * distinguish via presence of an equal sign.... if * it's there, assume that it's a tag/data pair instead * and roll back. */ p = start_p; } else { /* add '{' and '}' to protect from string expansion */ newstr_addchar( data, '{' ); newstr_strcat( data, tmp.data ); newstr_addchar( data, '}' ); } } newstr_free( &tmp ); return p; }
static void bibtex_split( list *tokens, newstr *s ) { newstr currtok; int nquotes = 0, nbrackets = 0; int i, n = s->len; newstr_init( &currtok ); for ( i=0; i<n; ++i ) { if ( s->data[i]=='\"' ) { if ( nquotes ) nquotes = 0; else nquotes = 1; newstr_addchar( &currtok, '\"' ); } else if ( s->data[i]=='{' ) { nbrackets++; newstr_addchar( &currtok, '{' ); } else if ( s->data[i]=='}' ) { nbrackets--; newstr_addchar( &currtok, '}' ); } else if ( s->data[i]=='#' && !nquotes && !nbrackets ) { if ( currtok.len ) list_add( tokens, currtok.data ); newstr_empty( &currtok ); } else if ( !is_ws( s->data[i] ) || nquotes || nbrackets ) { newstr_addchar( &currtok, s->data[i] ); } } if ( currtok.len ) list_add( tokens, currtok.data ); for ( i=0; i<tokens->n; ++i ) { newstr_trimendingws( &(tokens->str[i]) ); } newstr_free( &currtok ); }
void name_add( fields *info, char *tag, char *q, int level, list *asis, list *corps ) { newstr inname; char *p, *start, *end; if ( !q ) return; newstr_init( &inname ); while ( *q ) { start = q = skip_ws( q ); /* strip tailing whitespace and commas */ while ( *q && *q!='|' ) q++; end = q; while ( is_ws( *end ) || *end==',' || *end=='|' || *end=='\0' ) end--; for ( p=start; p<=end; p++ ) newstr_addchar( &inname, *p ); /* keep "names" like " , " from coredumping program */ if ( inname.len ) { name_process( info, tag, level, &inname, asis, corps ); newstr_empty( &inname ); } if ( *q=='|' ) q++; } newstr_free( &inname ); }
static int read_ref( FILE *fp, bibl *bin, char *filename, convert_rules *r, param *p ) { newstr reference, line; fields *ref; char buf[256]=""; int nrefs = 0, bufpos = 0, fcharset; newstr_init( &reference ); newstr_init( &line ); while ( r->readf( fp, buf, sizeof(buf), &bufpos, &line, &reference, &fcharset ) ) { if ( reference.len==0 ) continue; ref = fields_new(); if ( !ref ) return BIBL_ERR_MEMERR; if ( r->processf( ref, reference.data, filename, nrefs+1 )){ bibl_addref( bin, ref ); } else { fields_free( ref ); free( ref ); } newstr_empty( &reference ); if ( fcharset!=CHARSET_UNKNOWN ) { /* charset from file takes priority over default, but * not user-specified */ if ( p->charsetin_src!=BIBL_SRC_USER ) { p->charsetin_src = BIBL_SRC_FILE; p->charsetin = fcharset; if ( fcharset!=CHARSET_UNICODE ) p->utf8in = 0; } } } newstr_free( &line ); newstr_free( &reference ); return BIBL_OK; }
static int bibtex_cleandata( newstr *tag, newstr *s, fields *info, param *p ) { int i, status; list tokens; newstr *tok; if ( !s->len ) return BIBL_OK; /* protect url from undergoing any parsing */ if ( is_url_tag( tag ) ) return BIBL_OK; list_init( &tokens ); status = bibtex_split( &tokens, s ); if ( status!=BIBL_OK ) goto out; for ( i=0; i<tokens.n; ++i ) { tok = list_get( &tokens, i ); if ( bibtex_protected( tok ) ) { if (!strncasecmp(tok->data,"\\href{", 6)) { bibtex_addtitleurl( info, tok ); } } if ( p->latexin && !is_name_tag( tag ) && !is_url_tag( tag ) ) bibtex_cleantoken( tok ); } newstr_empty( s ); for ( i=0; i<tokens.n; ++i ) { tok = list_get( &tokens, i ); if ( i>0 ) newstr_addchar( s, ' ' ); newstr_newstrcat( s, tok ); } out: list_free( &tokens ); return status; }
/* newstr_fget() * returns 0 if we're done, 1 if we're not done * extracts line by line (regardless of end characters) * and feeds from buf.... */ int newstr_fget( FILE *fp, char *buf, int bufsize, int *pbufpos, newstr *outs ) { int bufpos = *pbufpos, done = 0; char *ok; newstr_empty( outs ); while ( !done ) { while ( buf[bufpos] && buf[bufpos]!='\r' && buf[bufpos]!='\n' ) newstr_addchar( outs, buf[bufpos++] ); if ( buf[bufpos]=='\0' ) { ok = fgets( buf, bufsize, fp ); bufpos=*pbufpos=0; if ( !ok && feof(fp) ) { /* end-of-file */ buf[bufpos] = 0; if ( outs->len==0 ) return 0; /*nothing in out*/ else return 1; /*one last out */ } } else if ( buf[bufpos]=='\r' || buf[bufpos]=='\n' ) done=1; } if ( ( buf[bufpos]=='\n' && buf[bufpos+1]=='\r') || ( buf[bufpos]=='\r' && buf[bufpos+1]=='\n') ) bufpos+=2; else if ( buf[bufpos]=='\n' || buf[bufpos]=='\r' ) bufpos+=1; *pbufpos = bufpos; return 1; }
static int medin_authorlist( xml *node, fields *info ) { int fstatus, status; newstr name; char *tag; newstr_init( &name ); node = node->down; while ( node ) { if ( xml_tagexact( node, "Author" ) && node->down ) { status = medin_author( node->down, &name ); tag = "AUTHOR"; if ( !name.len ) { status = medin_corpauthor( node->down, &name ); tag = "AUTHOR:CORP"; } if ( newstr_memerr( &name ) || status!=BIBL_OK ) return BIBL_ERR_MEMERR; if ( name.len ) { fstatus = fields_add(info,tag,name.data,0); if ( fstatus!=FIELDS_OK ) return BIBL_ERR_MEMERR; } newstr_empty( &name ); } node = node->next; } newstr_free( &name ); return BIBL_OK; }
int test_strcat( newstr *s ) { int failed = 0; int numshort = 5, numstrings = 1000, i; /* ...adding empty strings to an empty string shouldn't change length */ newstr_empty( s ); for ( i=0; i<numstrings; ++i ) newstr_strcat( s, "" ); if ( test_consistency( s, 0, __FUNCTION__ ) || test_identity( s, "" ) ) failed++; /* ...adding empty strings to a defined string shouldn't change string */ newstr_strcpy( s, "1" ); for ( i=0; i<numstrings; ++i ) newstr_strcat( s, "" ); if ( test_consistency( s, 1, __FUNCTION__ ) || test_identity( s, "1" ) ) failed++; /* ...build "1111" with newstr_strcat */ newstr_empty( s ); for ( i=0; i<numshort; ++i ) newstr_strcat( s, "1" ); if ( test_consistency( s, numshort, __FUNCTION__ ) || test_identity( s, "11111" ) ) failed++; /* ...build "xoxoxoxoxo" with newstr_strcat */ newstr_empty( s ); for ( i=0; i<numshort; ++i ) newstr_strcat( s, "xo" ); if ( test_consistency( s, numshort*2, __FUNCTION__ ) || test_identity( s, "xoxoxoxoxo" ) ) failed++; newstr_empty( s ); for ( i=0; i<numstrings; ++i ) newstr_strcat( s, "1" ); if ( test_consistency( s, numstrings, __FUNCTION__ ) ) failed++; newstr_empty( s ); for ( i=0; i<numstrings; ++i ) { newstr_strcat( s, "XXOO" ); } failed += test_consistency( s, numstrings*4, __FUNCTION__ ); return failed; }
static int test_trimws( newstr *s ) { char str1[] = " ksjadfk lajskfjds askdjflkj "; char str2[] = " "; int failed = 0; newstr_empty( s ); newstr_trimstartingws( s ); if ( string_mismatch( s, 0, "" ) ) failed++; newstr_trimendingws( s ); if ( string_mismatch( s, 0, "" ) ) failed++; newstr_strcpy( s, str2 ); newstr_trimstartingws( s ); if ( string_mismatch( s, 0, "" ) ) failed++; newstr_strcpy( s, str2 ); newstr_trimendingws( s ); if ( string_mismatch( s, 0, "" ) ) failed++; newstr_strcpy( s, str1 ); newstr_trimstartingws( s ); if ( string_mismatch( s, strlen("ksjadfk lajskfjds askdjflkj "), "ksjadfk lajskfjds askdjflkj " ) ) failed++; newstr_trimendingws( s ); if ( string_mismatch( s, strlen("ksjadfk lajskfjds askdjflkj"), "ksjadfk lajskfjds askdjflkj" ) ) failed++; newstr_strcpy( s, str1 ); newstr_trimendingws( s ); if ( string_mismatch( s, strlen(" ksjadfk lajskfjds askdjflkj"), " ksjadfk lajskfjds askdjflkj" ) ) failed++; newstr_trimstartingws( s ); if ( string_mismatch( s, strlen("ksjadfk lajskfjds askdjflkj"), "ksjadfk lajskfjds askdjflkj" ) ) failed++; newstr_empty( s ); newstr_stripws( s ); if ( string_mismatch( s, 0, "" ) ) failed++; newstr_strcpy( s, "0123456789" ); newstr_stripws( s ); if ( string_mismatch( s, 10, "0123456789" ) ) failed++; newstr_strcpy( s, str1 ); newstr_stripws( s ); if ( string_mismatch( s, strlen("ksjadfklajskfjdsaskdjflkj"), "ksjadfklajskfjdsaskdjflkj" ) ) failed++; return failed; }