1
- #[ doc = "Utilities for manipulating the char type" ] ;
1
+ /*
2
+ Module: char
3
+
4
+ Utilities for manipulating the char type
5
+ */
2
6
3
7
/*
4
8
Lu Uppercase_Letter an uppercase letter
@@ -43,40 +47,50 @@ import is_alphabetic = unicode::derived_property::Alphabetic;
43
47
import is_XID_start = unicode:: derived_property:: XID_Start ;
44
48
import is_XID_continue = unicode:: derived_property:: XID_Continue ;
45
49
50
+ /*
51
+ Function: is_lowercase
46
52
47
- #[ doc(
48
- brief = "Indicates whether a character is in lower case, defined\
49
- in terms of the Unicode General Category 'Ll'."
50
- ) ]
53
+ Indicates whether a character is in lower case, defined in terms of the
54
+ Unicode General Category 'Ll'.
55
+ */
51
56
pure fn is_lowercase ( c : char ) -> bool {
52
57
ret unicode:: general_category:: Ll ( c) ;
53
58
}
54
59
55
- #[ doc(
56
- brief = "Indicates whether a character is in upper case, defined\
57
- in terms of the Unicode General Category 'Lu'."
58
- ) ]
60
+ /*
61
+ Function: is_uppercase
62
+
63
+ Indicates whether a character is in upper case, defined in terms of the
64
+ Unicode General Category 'Lu'.
65
+ */
59
66
pure fn is_uppercase ( c : char ) -> bool {
60
67
ret unicode:: general_category:: Lu ( c) ;
61
68
}
62
69
63
- #[ doc(
64
- brief = "Indicates whether a character is whitespace, defined in\
65
- terms of the Unicode General Categories 'Zs', 'Zl', 'Zp'\
66
- additional 'Cc'-category control codes in the range [0x09, 0x0d]"
67
- ) ]
70
+ /*
71
+ Function: is_whitespace
72
+
73
+ Indicates whether a character is whitespace, defined in terms of
74
+ the Unicode General Categories 'Zs', 'Zl', 'Zp' and the additional
75
+ 'Cc'-category control codes in the range [0x09, 0x0d].
76
+
77
+ */
68
78
pure fn is_whitespace ( c : char ) -> bool {
69
79
ret ( '\x09' <= c && c <= '\x0d' )
70
80
|| unicode:: general_category:: Zs ( c)
71
81
|| unicode:: general_category:: Zl ( c)
72
82
|| unicode:: general_category:: Zp ( c) ;
73
83
}
74
84
75
- #[ doc(
76
- brief = "Indicates whether a character is alphanumeric, defined\
77
- in terms of the Unicode General Categories 'Nd',\
78
- 'Nl', 'No' and the Derived Core Property 'Alphabetic'."
79
- ) ]
85
+ /*
86
+ Function: is_alphanumeric
87
+
88
+ Indicates whether a character is alphanumeric, defined in terms of
89
+ the Unicode General Categories 'Nd', 'Nl', 'No' and the Derived
90
+ Core Property 'Alphabetic'.
91
+
92
+ */
93
+
80
94
pure fn is_alphanumeric ( c : char ) -> bool {
81
95
ret unicode:: derived_property:: Alphabetic ( c) ||
82
96
unicode:: general_category:: Nd ( c) ||
@@ -85,24 +99,34 @@ pure fn is_alphanumeric(c: char) -> bool {
85
99
}
86
100
87
101
88
- #[ doc(
89
- brief = "Convert a char to the corresponding digit.\
90
- Safety note: This function fails if `c` is not a valid char",
91
- return = "If `c` is between '0' and '9', the corresponding value\
92
- between 0 and 9. If `c` is 'a' or 'A', 10. If `c` is\
93
- 'b' or 'B', 11, etc."
94
- ) ]
102
+ /*
103
+ Function: to_digit
104
+
105
+ Convert a char to the corresponding digit.
106
+
107
+ Parameters:
108
+ c - a char, either '0' to '9', 'a' to 'z' or 'A' to 'Z'
109
+
110
+ Returns:
111
+ If `c` is between '0' and '9', the corresponding value between 0 and 9.
112
+ If `c` is 'a' or 'A', 10. If `c` is 'b' or 'B', 11, etc.
113
+
114
+ Safety note:
115
+ This function fails if `c` is not a valid char
116
+ */
95
117
pure fn to_digit ( c : char ) -> u8 unsafe {
96
118
alt maybe_digit ( c) {
97
119
option:: some ( x) { x }
98
120
option:: none. { fail; }
99
121
}
100
122
}
101
123
102
- #[ doc(
103
- brief = "Convert a char to the corresponding digit. Returns none when\
104
- character is not a valid hexadecimal digit."
105
- ) ]
124
+ /*
125
+ Function: maybe_digit
126
+
127
+ Convert a char to the corresponding digit. Returns none when the
128
+ character is not a valid hexadecimal digit.
129
+ */
106
130
pure fn maybe_digit ( c : char ) -> option:: t < u8 > {
107
131
alt c {
108
132
'0' to ' 9 ' { option : : some ( c as u8 - ( '0' as u8 ) ) }
@@ -113,11 +137,12 @@ pure fn maybe_digit(c: char) -> option::t<u8> {
113
137
}
114
138
115
139
/*
140
+ Function: to_lower
141
+
142
+ Convert a char to the corresponding lower case.
143
+
116
144
FIXME: works only on ASCII
117
145
*/
118
- #[ doc(
119
- brief = "Convert a char to the corresponding lower case."
120
- ) ]
121
146
pure fn to_lower ( c : char ) -> char {
122
147
alt c {
123
148
'A' to ' Z ' { ( ( c as u8 ) + 32u8 ) as char }
@@ -126,22 +151,31 @@ pure fn to_lower(c: char) -> char {
126
151
}
127
152
128
153
/*
154
+ Function: to_upper
155
+
156
+ Convert a char to the corresponding upper case.
157
+
129
158
FIXME: works only on ASCII
130
159
*/
131
- #[ doc(
132
- brief = "Convert a char to the corresponding upper case."
133
- ) ]
134
160
pure fn to_upper ( c : char ) -> char {
135
161
alt c {
136
162
'a' to ' z' { ( ( c as u8 ) - 32u8 ) as char }
137
163
_ { c }
138
164
}
139
165
}
140
166
141
- #[ doc(
142
- brief = "Compare two chars." ,
143
- return = "-1 if a<b, 0 if a==b, +1 if a>b"
144
- ) ]
167
+ /*
168
+ Function: cmp
169
+
170
+ Compare two chars.
171
+
172
+ Parameters:
173
+ a - a char
174
+ b - a char
175
+
176
+ Returns:
177
+ -1 if a<b, 0 if a==b, +1 if a>b
178
+ */
145
179
pure fn cmp ( a : char , b : char ) -> int {
146
180
ret if b > a { -1 }
147
181
else if b < a { 1 }
0 commit comments