ソースを参照

fixed range of char and digits, added single char, still printing for tests

main
lquint 3年前
コミット
31091ba18d
1個のファイルの変更14行の追加7行の削除
  1. +14
    -7
      class.c

+ 14
- 7
class.c ファイルの表示

@ -20,10 +20,8 @@ char *classify(char *spec)
// test if the next thing is \ . // test if the next thing is \ .
// or test if you have X-Y (where X or Y might be a character or escaped character) // or test if you have X-Y (where X or Y might be a character or escaped character)
// \n-\r // \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]<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) //= 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++){ for(int j=spec[index-1]; j<=spec[index+1] ; j++){
setBit(class,j); setBit(class,j);
printf("added digit : %c\n",j); printf("added digit : %c\n",j);
} }
index++;
} }
} }
else{ else{
@ -51,18 +51,25 @@ char *classify(char *spec)
setBit(class,j); setBit(class,j);
printf("added char : %c\n",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 ){ 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++){ for(int j=spec[index-1]; j<=spec[index+1] ; j++){
setBit(class,j); setBit(class,j);
printf("added char : %c\n",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++; index++;
} }
@ -80,7 +87,7 @@ int main()
ssize_t line_len=0; ssize_t line_len=0;
char a='a'; char a='a';
printf("%i\n",(int)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) { while ((line_len= getline(&line,&line_max,stdin)) >= 0) {
if (line_len>0 && line[line_len-1]=='\n') { if (line_len>0 && line[line_len-1]=='\n') {
line[line_len-1]=0; line[line_len-1]=0;

読み込み中…
キャンセル
保存