Skip to content

Commit cefa97d

Browse files
author
David Rajchenbach-Teller
committed
[Stdlib doc] char.rs: documented to_digit, cmp
1 parent 2dedcc8 commit cefa97d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/lib/char.rs

+25
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,21 @@ pure fn is_whitespace(c: char) -> bool {
9494
} else if c == ch_no_break_space { true } else { false }
9595
}
9696

97+
/*
98+
Function: to_digit
99+
100+
Convert a char to the corresponding digit.
101+
102+
Parameters:
103+
c - a char, either '0' to '9', 'a' to 'z' or 'A' to 'Z'
97104
105+
Returns:
106+
If `c` is between '0' and '9', the corresponding value between 0 and 9.
107+
If `c` is 'a' or 'A', 10. If `c` is 'b' or 'B', 11, etc.
108+
109+
Safety note:
110+
This function fails if `c` is not a valid char
111+
*/
98112
pure fn to_digit(c: char) -> u8 {
99113
alt c {
100114
'0' to '9' { c as u8 - ('0' as u8) }
@@ -104,7 +118,18 @@ pure fn to_digit(c: char) -> u8 {
104118
}
105119
}
106120

121+
/*
122+
Function: cmp
123+
124+
Compare two chars.
107125
126+
Parameters:
127+
a - a char
128+
b - a char
129+
130+
Returns:
131+
-1 if a<b, 0 if a==b, +1 if a>b
132+
*/
108133
fn cmp(a: char, b: char) -> int {
109134
ret if b > a { -1 }
110135
else if b < a { 1 }

0 commit comments

Comments
 (0)