|
| 1 | +// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +use super::tables::{derived_property, charwidth}; |
| 12 | + |
| 13 | +/// Returns whether the specified character satisfies the 'XID_Start' |
| 14 | +/// Unicode property. |
| 15 | +/// |
| 16 | +/// 'XID_Start' is a Unicode Derived Property specified in |
| 17 | +/// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications), |
| 18 | +/// mostly similar to ID_Start but modified for closure under NFKx. |
| 19 | +#[unstable(feature = "unicode", |
| 20 | + reason = "mainly needed for compiler internals")] |
| 21 | +#[inline] |
| 22 | +pub fn is_xid_start(ch: char) -> bool { derived_property::XID_Start(ch) } |
| 23 | + |
| 24 | +/// Returns whether the specified `char` satisfies the 'XID_Continue' |
| 25 | +/// Unicode property. |
| 26 | +/// |
| 27 | +/// 'XID_Continue' is a Unicode Derived Property specified in |
| 28 | +/// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications), |
| 29 | +/// mostly similar to 'ID_Continue' but modified for closure under NFKx. |
| 30 | +#[unstable(feature = "unicode", |
| 31 | + reason = "mainly needed for compiler internals")] |
| 32 | +#[inline] |
| 33 | +pub fn is_xid_continue(ch: char) -> bool { derived_property::XID_Continue(ch) } |
| 34 | + |
| 35 | +/// Returns this character's displayed width in columns, or `None` if it is a |
| 36 | +/// control character other than `'\x00'`. |
| 37 | +/// |
| 38 | +/// `is_cjk` determines behavior for characters in the Ambiguous category: |
| 39 | +/// if `is_cjk` is `true`, these are 2 columns wide; otherwise, they are 1. |
| 40 | +/// In CJK contexts, `is_cjk` should be `true`, else it should be `false`. |
| 41 | +/// [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/) |
| 42 | +/// recommends that these characters be treated as 1 column (i.e., |
| 43 | +/// `is_cjk` = `false`) if the context cannot be reliably determined. |
| 44 | +#[deprecated(reason = "use the crates.io `unicode-width` library instead", |
| 45 | + since = "1.0.0")] |
| 46 | +#[unstable(feature = "unicode", |
| 47 | + reason = "needs expert opinion. is_cjk flag stands out as ugly")] |
| 48 | +pub fn width(ch: char, is_cjk: bool) -> Option<usize> { |
| 49 | + charwidth::width(ch, is_cjk) |
| 50 | +} |
0 commit comments