From 31091ba18d502021efaa09030fee36b0443b50fd Mon Sep 17 00:00:00 2001 From: lquint Date: Sat, 17 Jul 2021 13:43:20 +0200 Subject: [PATCH] fixed range of char and digits, added single char, still printing for tests --- class.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/class.c b/class.c index 7200b69..97f9fe9 100644 --- a/class.c +++ b/class.c @@ -20,10 +20,8 @@ char *classify(char *spec) // test if the next thing is \ . // or test if you have X-Y (where X or Y might be a character or escaped character) // \n-\r - if (spec[index]=='-' && index!=0 && !(index==1 && spec[0]=='^')){ - if(spec[index+1]=='\0'){ - printf("Error, bad use of range\n"); - } + if (spec[index]=='-' && index!=0 && !(index==1 && spec[0]=='^') && spec[index+1]!='\0'){ + if(spec[index-1]<65 || spec[index+1]>122 || (spec[index-1]>90 && spec[index-1]<97) || (spec[index+1]>90 && spec[index+1]<97)){ //= if(spec[index-1] or spec[index+1] are not letters) @@ -35,7 +33,9 @@ char *classify(char *spec) for(int j=spec[index-1]; j<=spec[index+1] ; j++){ setBit(class,j); printf("added digit : %c\n",j); + } + index++; } } else{ @@ -51,18 +51,25 @@ char *classify(char *spec) setBit(class,j); printf("added char : %c\n",j); } + index++; } else if( spec[index-1]>=97 && spec[index-1]<=122 && spec[index+1]>=97 && spec[index+1]<=122 ){ for(int j=spec[index-1]; j<=spec[index+1] ; j++){ setBit(class,j); printf("added char : %c\n",j); + } + index++; } } - } - printf("%i\n",spec[index]); + else if((spec[index]>=65 && spec[index]<=90) || (spec[index]>=97 && spec[index]<=122)){ + setBit(class,spec[index]); + printf("added char : %c\n",spec[index]); + } + printf("%c\n",spec[index]); + printf("%i\n",index); index++; } @@ -80,7 +87,7 @@ int main() ssize_t line_len=0; char a='a'; printf("%i\n",(int)a); - printf("%s",classify("^-abca")); + printf("%s",classify("a-cA-Z")); while ((line_len= getline(&line,&line_max,stdin)) >= 0) { if (line_len>0 && line[line_len-1]=='\n') { line[line_len-1]=0;