Search code examples
lazarusfreepascal

Free Pascal: detect "is word char" for WideChar


I use code

Result:=
((ch>='0') and (ch<='9')) or
((ch>='a') and (ch<='z')) or
((ch>='A') and (ch<='Z')) or
(ch='_');

it detects ok AnsiChar; how to detect "if char letter or digit" for WideChar?


Solution

  • I guess there's no simple way to solve this. What's your definition of a letter? Ω (omega) is a letter? is it just a symbol? You would have to manually decide what is a letter and what is not. You could make a big case statement that determines whether a char is alpha numeric or not...

    function is_alpha_num(ch : widechar) : boolean;
    begin
      case ch of
        #$0030..#$0039, // '0'..'9'                                                 
        #$0041..#$005A, // 'A'..'Z'                                                 
        #$0061..#$007A, // 'a'..'z'                                                 
        // need to define the rest here...                                          
        #$FF21..#$FF3A // 'A'..'Z'                                                
        : result := true;
       else result := false;
      end;
    end;