1
- # [ doc = " Utilities for manipulating the char type" ] ;
1
+ //! Utilities for manipulating the char type
2
2
3
3
/*
4
4
Lu Uppercase_Letter an uppercase letter
@@ -46,72 +46,72 @@ import is_XID_start = unicode::derived_property::XID_Start;
46
46
import is_XID_continue = unicode:: derived_property:: XID_Continue ;
47
47
48
48
49
- # [ doc = "
50
- Indicates whether a character is in lower case, defined
51
- in terms of the Unicode General Category 'Ll'
52
- " ]
49
+ /**
50
+ * Indicates whether a character is in lower case, defined
51
+ * in terms of the Unicode General Category 'Ll'
52
+ */
53
53
pure fn is_lowercase ( c : char ) -> bool {
54
54
ret unicode:: general_category:: Ll ( c) ;
55
55
}
56
56
57
- # [ doc = "
58
- Indicates whether a character is in upper case, defined
59
- in terms of the Unicode General Category 'Lu'.
60
- " ]
57
+ /**
58
+ * Indicates whether a character is in upper case, defined
59
+ * in terms of the Unicode General Category 'Lu'.
60
+ */
61
61
pure fn is_uppercase ( c : char ) -> bool {
62
62
ret unicode:: general_category:: Lu ( c) ;
63
63
}
64
64
65
- # [ doc = "
66
- Indicates whether a character is whitespace, defined in
67
- terms of the Unicode General Categories 'Zs', 'Zl', 'Zp'
68
- additional 'Cc'-category control codes in the range [0x09, 0x0d]/~
69
- " ]
65
+ /**
66
+ * Indicates whether a character is whitespace, defined in
67
+ * terms of the Unicode General Categories 'Zs', 'Zl', 'Zp'
68
+ * additional 'Cc'-category control codes in the range [0x09, 0x0d]
69
+ */
70
70
pure fn is_whitespace ( c : char ) -> bool {
71
71
ret ( '\x09' <= c && c <= '\x0d' )
72
72
|| unicode:: general_category:: Zs ( c)
73
73
|| unicode:: general_category:: Zl ( c)
74
74
|| unicode:: general_category:: Zp ( c) ;
75
75
}
76
76
77
- # [ doc = "
78
- Indicates whether a character is alphanumeric, defined
79
- in terms of the Unicode General Categories 'Nd',
80
- 'Nl', 'No' and the Derived Core Property 'Alphabetic'.
81
- " ]
77
+ /**
78
+ * Indicates whether a character is alphanumeric, defined
79
+ * in terms of the Unicode General Categories 'Nd',
80
+ * 'Nl', 'No' and the Derived Core Property 'Alphabetic'.
81
+ */
82
82
pure fn is_alphanumeric ( c : char ) -> bool {
83
83
ret unicode:: derived_property:: Alphabetic ( c) ||
84
84
unicode:: general_category:: Nd ( c) ||
85
85
unicode:: general_category:: Nl ( c) ||
86
86
unicode:: general_category:: No ( c) ;
87
87
}
88
88
89
- # [ doc = " Indicates whether the character is an ASCII character" ]
89
+ /// Indicates whether the character is an ASCII character
90
90
pure fn is_ascii ( c : char ) -> bool {
91
91
c - ( '\x7F' & c) == '\x00'
92
92
}
93
93
94
- # [ doc = " Indicates whether the character is numeric (Nd, Nl, or No)" ]
94
+ /// Indicates whether the character is numeric (Nd, Nl, or No)
95
95
pure fn is_digit ( c : char ) -> bool {
96
96
ret unicode:: general_category:: Nd ( c) ||
97
97
unicode:: general_category:: Nl ( c) ||
98
98
unicode:: general_category:: No ( c) ;
99
99
}
100
100
101
- # [ doc = "
102
- Convert a char to the corresponding digit.
103
-
104
- # Safety note
105
-
106
- This function fails if `c` is not a valid char
107
-
108
- # Return value
109
-
110
- If `c` is between '0' and '9', the corresponding value
111
- between 0 and 9. If `c` is 'a' or 'A', 10. If `c` is
112
- 'b' or 'B', 11, etc. Returns none if the char does not
113
- refer to a digit in the given radix.
114
- " ]
101
+ /**
102
+ * Convert a char to the corresponding digit.
103
+ *
104
+ * # Safety note
105
+ *
106
+ * This function fails if `c` is not a valid char
107
+ *
108
+ * # Return value
109
+ *
110
+ * If `c` is between '0' and '9', the corresponding value
111
+ * between 0 and 9. If `c` is 'a' or 'A', 10. If `c` is
112
+ * 'b' or 'B', 11, etc. Returns none if the char does not
113
+ * refer to a digit in the given radix.
114
+ */
115
115
pure fn to_digit ( c : char , radix : uint ) -> option < uint > {
116
116
let val = alt c {
117
117
'0' to ' 9 ' { c as uint - ( '0' as uint ) }
@@ -123,15 +123,15 @@ pure fn to_digit(c: char, radix: uint) -> option<uint> {
123
123
else { none }
124
124
}
125
125
126
- # [ doc = "
127
- Return the hexadecimal unicode escape of a char.
128
-
129
- The rules are as follows:
130
-
131
- - chars in [0,0xff]/~ get 2-digit escapes: `\\ xNN`
132
- - chars in [0x100,0xffff]/~ get 4-digit escapes: `\\ uNNNN`
133
- - chars above 0x10000 get 8-digit escapes: `\\ UNNNNNNNN`
134
- " ]
126
+ /**
127
+ * Return the hexadecimal unicode escape of a char.
128
+ *
129
+ * The rules are as follows:
130
+ *
131
+ * - chars in [0,0xff] get 2-digit escapes: `\\xNN`
132
+ * - chars in [0x100,0xffff] get 4-digit escapes: `\\uNNNN`
133
+ * - chars above 0x10000 get 8-digit escapes: `\\UNNNNNNNN`
134
+ */
135
135
fn escape_unicode ( c : char ) -> str {
136
136
let s = u32:: to_str ( c as u32 , 16 u) ;
137
137
let ( c, pad) = ( if c <= '\xff' { ( 'x' , 2 u) }
@@ -145,18 +145,18 @@ fn escape_unicode(c: char) -> str {
145
145
ret out;
146
146
}
147
147
148
- # [ doc = "
149
- Return a 'default' ASCII and C++11-like char-literal escape of a char.
150
-
151
- The default is chosen with a bias toward producing literals that are
152
- legal in a variety of languages, including C++11 and similar C-family
153
- languages. The exact rules are:
154
-
155
- - Tab, CR and LF are escaped as '\t ', '\r ' and '\n ' respectively.
156
- - Single-quote, double-quote and backslash chars are backslash-escaped.
157
- - Any other chars in the range [0x20,0x7e]/~ are not escaped.
158
- - Any other chars are given hex unicode escapes; see `escape_unicode`.
159
- " ]
148
+ /**
149
+ * Return a 'default' ASCII and C++11-like char-literal escape of a char.
150
+ *
151
+ * The default is chosen with a bias toward producing literals that are
152
+ * legal in a variety of languages, including C++11 and similar C-family
153
+ * languages. The exact rules are:
154
+ *
155
+ * - Tab, CR and LF are escaped as '\t', '\r' and '\n' respectively.
156
+ * - Single-quote, double-quote and backslash chars are backslash-escaped.
157
+ * - Any other chars in the range [0x20,0x7e] are not escaped.
158
+ * - Any other chars are given hex unicode escapes; see `escape_unicode`.
159
+ */
160
160
fn escape_default ( c : char ) -> str {
161
161
alt c {
162
162
'\t' { "\\ t" }
@@ -170,13 +170,13 @@ fn escape_default(c: char) -> str {
170
170
}
171
171
}
172
172
173
- # [ doc = "
174
- Compare two chars
175
-
176
- # Return value
177
-
178
- -1 if a < b, 0 if a == b, +1 if a > b
179
- " ]
173
+ /**
174
+ * Compare two chars
175
+ *
176
+ * # Return value
177
+ *
178
+ * -1 if a < b, 0 if a == b, +1 if a > b
179
+ */
180
180
pure fn cmp ( a : char , b : char ) -> int {
181
181
ret if b > a { -1 }
182
182
else if b < a { 1 }
0 commit comments