Skip to content

Commit

Permalink
Add isalphanum function to ascii.d
Browse files Browse the repository at this point in the history
  • Loading branch information
pineapplemachine committed Oct 23, 2017
1 parent 27ddee9 commit b88236a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions mach/text/ascii.d
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ bool isalpha(T)(in T ch) if(isCharacter!T){
return ch >= 'A' && ch <= 'z' && (ch <= 'Z' || ch >= 'a');
}

/// Determine whether an ASCII character is alphanumeric.
bool isalphanum(T)(in T ch) if(isCharacter!T){
return isalpha(ch) || isdigit(ch);
}

/// Determine whether an ASCII character is a upper-case letter.
bool isupper(T)(in T ch) if(isCharacter!T){
return ch >= 'A' && ch <= 'Z';
Expand Down Expand Up @@ -187,10 +192,24 @@ unittest{
test(T('A').isalpha);
test(T('Z').isalpha);
testf(T(0).isalpha);
testf(T('1').isalpha);
testf(T('@').isalpha);
testf(T('`').isalpha);
testf(T('{').isalpha);
});
tests("isalphanum", {
test(T('a').isalphanum);
test(T('z').isalphanum);
test(T('A').isalphanum);
test(T('Z').isalphanum);
test(T('1').isalphanum);
test(T('9').isalphanum);
test(T('0').isalphanum);
testf(T(0).isalphanum);
testf(T('@').isalphanum);
testf(T('`').isalphanum);
testf(T('{').isalphanum);
});
tests("isupper", {
test(T('A').isupper);
test(T('Z').isupper);
Expand Down

0 comments on commit b88236a

Please sign in to comment.