Skip to content

Commit a52565c

Browse files
author
David Rajchenbach-Teller
committed
---
yaml --- r: 6171 b: refs/heads/master c: cefa97d h: refs/heads/master i: 6169: bdb889e 6167: 8cee295 v: v3
1 parent c3dc165 commit a52565c

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 2dedcc8aa2e6c9eb5011dab2c22679f5ae8e35fc
2+
refs/heads/master: cefa97dc2e2792871a91fe1d59dab26014fbc9d3

trunk/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)