瀏覽代碼

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 \ .
// 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;

Loading…
取消
儲存