Skip to content

Commit ad422ed

Browse files
committed
unicode: Convert UnicodeChar methods to by-value
Extension traits for primitive types should be by-value. [breaking-change]
1 parent 34930ec commit ad422ed

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

src/libunicode/u_char.rs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ pub fn width(c: char, is_cjk: bool) -> Option<uint> {
166166
pub trait UnicodeChar {
167167
/// Returns whether the specified character is considered a Unicode
168168
/// alphabetic code point.
169-
fn is_alphabetic(&self) -> bool;
169+
fn is_alphabetic(self) -> bool;
170170

171171
/// Returns whether the specified character satisfies the 'XID_Start'
172172
/// Unicode property.
@@ -175,7 +175,7 @@ pub trait UnicodeChar {
175175
/// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications),
176176
/// mostly similar to ID_Start but modified for closure under NFKx.
177177
#[allow(non_snake_case)]
178-
fn is_XID_start(&self) -> bool;
178+
fn is_XID_start(self) -> bool;
179179

180180
/// Returns whether the specified `char` satisfies the 'XID_Continue'
181181
/// Unicode property.
@@ -184,40 +184,40 @@ pub trait UnicodeChar {
184184
/// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications),
185185
/// mostly similar to 'ID_Continue' but modified for closure under NFKx.
186186
#[allow(non_snake_case)]
187-
fn is_XID_continue(&self) -> bool;
187+
fn is_XID_continue(self) -> bool;
188188

189189

190190
/// Indicates whether a character is in lowercase.
191191
///
192192
/// This is defined according to the terms of the Unicode Derived Core
193193
/// Property `Lowercase`.
194-
fn is_lowercase(&self) -> bool;
194+
fn is_lowercase(self) -> bool;
195195

196196
/// Indicates whether a character is in uppercase.
197197
///
198198
/// This is defined according to the terms of the Unicode Derived Core
199199
/// Property `Uppercase`.
200-
fn is_uppercase(&self) -> bool;
200+
fn is_uppercase(self) -> bool;
201201

202202
/// Indicates whether a character is whitespace.
203203
///
204204
/// Whitespace is defined in terms of the Unicode Property `White_Space`.
205-
fn is_whitespace(&self) -> bool;
205+
fn is_whitespace(self) -> bool;
206206

207207
/// Indicates whether a character is alphanumeric.
208208
///
209209
/// Alphanumericness is defined in terms of the Unicode General Categories
210210
/// 'Nd', 'Nl', 'No' and the Derived Core Property 'Alphabetic'.
211-
fn is_alphanumeric(&self) -> bool;
211+
fn is_alphanumeric(self) -> bool;
212212

213213
/// Indicates whether a character is a control code point.
214214
///
215215
/// Control code points are defined in terms of the Unicode General
216216
/// Category `Cc`.
217-
fn is_control(&self) -> bool;
217+
fn is_control(self) -> bool;
218218

219219
/// Indicates whether the character is numeric (Nd, Nl, or No).
220-
fn is_numeric(&self) -> bool;
220+
fn is_numeric(self) -> bool;
221221

222222
/// Converts a character to its lowercase equivalent.
223223
///
@@ -228,7 +228,7 @@ pub trait UnicodeChar {
228228
///
229229
/// Returns the lowercase equivalent of the character, or the character
230230
/// itself if no conversion is possible.
231-
fn to_lowercase(&self) -> char;
231+
fn to_lowercase(self) -> char;
232232

233233
/// Converts a character to its uppercase equivalent.
234234
///
@@ -250,7 +250,7 @@ pub trait UnicodeChar {
250250
/// [`SpecialCasing`.txt`]: ftp://ftp.unicode.org/Public/UNIDATA/SpecialCasing.txt
251251
///
252252
/// [2]: http://www.unicode.org/versions/Unicode4.0.0/ch03.pdf#G33992
253-
fn to_uppercase(&self) -> char;
253+
fn to_uppercase(self) -> char;
254254

255255
/// Returns this character's displayed width in columns, or `None` if it is a
256256
/// control character other than `'\x00'`.
@@ -261,31 +261,33 @@ pub trait UnicodeChar {
261261
/// [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
262262
/// recommends that these characters be treated as 1 column (i.e.,
263263
/// `is_cjk` = `false`) if the context cannot be reliably determined.
264-
fn width(&self, is_cjk: bool) -> Option<uint>;
264+
#[experimental = "needs expert opinion. is_cjk flag stands out as ugly"]
265+
fn width(self, is_cjk: bool) -> Option<uint>;
265266
}
266267

267268
impl UnicodeChar for char {
268-
fn is_alphabetic(&self) -> bool { is_alphabetic(*self) }
269+
fn is_alphabetic(self) -> bool { is_alphabetic(self) }
269270

270-
fn is_XID_start(&self) -> bool { is_XID_start(*self) }
271+
fn is_XID_start(self) -> bool { is_XID_start(self) }
271272

272-
fn is_XID_continue(&self) -> bool { is_XID_continue(*self) }
273+
fn is_XID_continue(self) -> bool { is_XID_continue(self) }
273274

274-
fn is_lowercase(&self) -> bool { is_lowercase(*self) }
275+
fn is_lowercase(self) -> bool { is_lowercase(self) }
275276

276-
fn is_uppercase(&self) -> bool { is_uppercase(*self) }
277+
fn is_uppercase(self) -> bool { is_uppercase(self) }
277278

278-
fn is_whitespace(&self) -> bool { is_whitespace(*self) }
279+
fn is_whitespace(self) -> bool { is_whitespace(self) }
279280

280-
fn is_alphanumeric(&self) -> bool { is_alphanumeric(*self) }
281+
fn is_alphanumeric(self) -> bool { is_alphanumeric(self) }
281282

282-
fn is_control(&self) -> bool { is_control(*self) }
283+
fn is_control(self) -> bool { is_control(self) }
283284

284-
fn is_numeric(&self) -> bool { is_digit(*self) }
285+
fn is_numeric(self) -> bool { is_digit(self) }
285286

286-
fn to_lowercase(&self) -> char { to_lowercase(*self) }
287+
fn to_lowercase(self) -> char { to_lowercase(self) }
287288

288-
fn to_uppercase(&self) -> char { to_uppercase(*self) }
289+
fn to_uppercase(self) -> char { to_uppercase(self) }
289290

290-
fn width(&self, is_cjk: bool) -> Option<uint> { width(*self, is_cjk) }
291+
#[experimental = "needs expert opinion. is_cjk flag stands out as ugly"]
292+
fn width(self, is_cjk: bool) -> Option<uint> { width(self, is_cjk) }
291293
}

0 commit comments

Comments
 (0)