diff options
| author | David Rajchenbach-Teller <dteller@mozilla.com> | 2011-11-06 17:26:31 +0100 |
|---|---|---|
| committer | David Rajchenbach-Teller <dteller@mozilla.com> | 2011-11-06 18:10:22 +0100 |
| commit | cefa97dc2e2792871a91fe1d59dab26014fbc9d3 (patch) | |
| tree | bbcb10d9b123900187136ade9cb43c34210edd61 /src/lib | |
| parent | 2dedcc8aa2e6c9eb5011dab2c22679f5ae8e35fc (diff) | |
| download | rust-cefa97dc2e2792871a91fe1d59dab26014fbc9d3.tar.gz rust-cefa97dc2e2792871a91fe1d59dab26014fbc9d3.zip | |
[Stdlib doc] char.rs: documented to_digit, cmp
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/char.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/lib/char.rs b/src/lib/char.rs index 0af3b0d1a91..bc8e74355c6 100644 --- a/src/lib/char.rs +++ b/src/lib/char.rs @@ -94,7 +94,21 @@ pure fn is_whitespace(c: char) -> bool { } else if c == ch_no_break_space { true } else { false } } +/* + Function: to_digit + + Convert a char to the corresponding digit. + + Parameters: + c - a char, either '0' to '9', 'a' to 'z' or 'A' to 'Z' + Returns: + If `c` is between '0' and '9', the corresponding value between 0 and 9. + If `c` is 'a' or 'A', 10. If `c` is 'b' or 'B', 11, etc. + + Safety note: + This function fails if `c` is not a valid char +*/ pure fn to_digit(c: char) -> u8 { alt c { '0' to '9' { c as u8 - ('0' as u8) } @@ -104,7 +118,18 @@ pure fn to_digit(c: char) -> u8 { } } +/* + Function: cmp + + Compare two chars. + Parameters: + a - a char + b - a char + + Returns: + -1 if a<b, 0 if a==b, +1 if a>b +*/ fn cmp(a: char, b: char) -> int { ret if b > a { -1 } else if b < a { 1 } |
