1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
// Copyright 2017 The UNIC Project Developers. // // See the COPYRIGHT file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. #[macro_export] /// Convenience macro for the initialization of `CharRange`s. /// /// # Syntax /// /// ``` /// # #[macro_use] extern crate unic_char_range; /// # fn main() { /// chars!('a'..'z'); // The half open range including 'a' and excluding 'z' /// chars!('a'..='z'); // The closed range including 'a' and including 'z' /// chars!(..); // All characters /// # } /// ``` /// /// `chars!('a'..='z')` and `chars!(..)` are constant-time expressions, and can be used /// where such are required, such as in the initialization of constant data structures. /// /// Note that because an `expr` capture cannot be followed by a `..`/`..=`, /// this macro captures token trees. This means that if you want to pass more than one token, /// you must parenthesize it (e.g. `chars!('\0' ..= (char::MAX))`). macro_rules! chars { ( $low:tt .. $high:tt ) => ( $crate::CharRange::open_right($low, $high) ); ( $low:tt ..= $high:tt ) => ( $crate::CharRange { low: $low, high: $high } ); ( .. ) => ( chars!( '\0' ..= '\u{10ffff}' ) ); }