pub struct Identifier(pub UniCase<String>);Tuple Fields§
§0: UniCase<String>Implementations§
Source§impl Identifier
impl Identifier
Sourcepub const MAX_LEN: usize = 64
pub const MAX_LEN: usize = 64
Maximum length of an identifier, in bytes. The limit applies in the encoding used by the dictionary, not in UTF-8.
pub fn new(s: impl Into<UniCase<String>>) -> Result<Self, Error>
Sourcepub fn codepage_to_unicode(&mut self)
pub fn codepage_to_unicode(&mut self)
Converts this identifier to UTF-8. This is generally a no-op, because our internal encoding is UTF-8, but some identifiers are longer in UTF-8 than in their code page, which means that to satisfy the 64-byte limit this function sometimes has to remove trailing grapheme clusters.
pub fn from_encoding( s: impl Into<UniCase<String>>, encoding: &'static Encoding, ) -> Result<Identifier, Error>
Sourcepub fn check_encoding(&self, encoding: &'static Encoding) -> Result<(), Error>
pub fn check_encoding(&self, encoding: &'static Encoding) -> Result<(), Error>
Checks whether this is a valid identifier in the given encoding. An
identifier that is valid in one encoding might be invalid in another
because some characters are unencodable or because it is too long.
pub fn check_plausible(s: &str) -> Result<(), Error>
Sourcepub fn matches_keyword(&self, keyword: &str) -> bool
pub fn matches_keyword(&self, keyword: &str) -> bool
Returns true if token is a case-insensitive match for keyword.
Keywords match keyword and token are identical, or token is at
least 3 characters long and those characters are identical to keyword
or differ only in case.
keyword must be ASCII.
Sourcepub fn matches_keyword_n(&self, keyword: &str, n: usize) -> bool
pub fn matches_keyword_n(&self, keyword: &str, n: usize) -> bool
Returns true if token is a case-insensitive match for at least the
first n characters of keyword.
keyword must be ASCII.
pub fn must_be_ordinary(self) -> Result<Self, Error>
pub fn class(&self) -> Class
pub fn as_str(&self) -> &str
Sourcepub fn shortened(&self, encoding: &'static Encoding) -> Self
pub fn shortened(&self, encoding: &'static Encoding) -> Self
Returns this this identifier truncated to at most 8 bytes in encoding.
Sourcepub fn with_suffix(
&self,
suffix: &str,
encoding: &'static Encoding,
max_len: usize,
) -> Result<Self, Error>
pub fn with_suffix( &self, suffix: &str, encoding: &'static Encoding, max_len: usize, ) -> Result<Self, Error>
Returns a prefix of this identifier concatenated with all of suffix,
including as many grapheme clusters from the beginning of this
identifier as would fit within max_len bytes if the resulting string
were to be re-encoded in encoding.
max_len would ordinarily be 64, since that’s the maximum length of an
identifier, but a value of 8 is appropriate for short variable names.
This function fails if adding or using suffix produces an invalid
Identifier, for example if max_len is short enough that none of the
identifier can be included and suffix begins with '_' or another
character that may not appear at the beginning of an identifier.
§Examples
Simple examples for UTF-8 encoding with max_len of 6:
identifier="abc", suffix="xyz" => "abcxyz"
identifier="abcd", suffix="xyz" => "abcxyz"
identifier="abc", suffix="uvwxyz" => "uvwxyz"
identifier="abc", suffix="tuvwxyz" => "tuvwxyz"Examples for windows-1252 encoding with max_len of 6:
identifier="éèä", suffix="xyz" => "éèäxyz"(each letter in the identifier is only 1 byte in windows-1252 even though they each take 2 bytes in UTF-8)
Methods from Deref<Target = UniCase<String>>§
Sourcepub fn to_folded_case(&self) -> String
pub fn to_folded_case(&self) -> String
Returns a copy of this string where each character is mapped to its Unicode CaseFolding equivalent.
§Note
Unicode Case Folding is meant for string storage and matching, not for display.
Trait Implementations§
Source§impl Clone for Identifier
impl Clone for Identifier
Source§fn clone(&self) -> Identifier
fn clone(&self) -> Identifier
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Identifier
impl Debug for Identifier
Source§impl Deref for Identifier
impl Deref for Identifier
Source§impl Display for Identifier
impl Display for Identifier
impl Eq for Identifier
Source§impl From<&Identifier> for Class
impl From<&Identifier> for Class
Source§fn from(id: &Identifier) -> Self
fn from(id: &Identifier) -> Self
Source§impl Hash for Identifier
impl Hash for Identifier
Source§impl Ord for Identifier
impl Ord for Identifier
Source§fn cmp(&self, other: &Identifier) -> Ordering
fn cmp(&self, other: &Identifier) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for Identifier
impl PartialEq for Identifier
Source§impl PartialEq<str> for Identifier
impl PartialEq<str> for Identifier
Source§impl PartialOrd for Identifier
impl PartialOrd for Identifier
Source§impl Serialize for Identifier
impl Serialize for Identifier
impl StructuralPartialEq for Identifier
Auto Trait Implementations§
impl Freeze for Identifier
impl RefUnwindSafe for Identifier
impl Send for Identifier
impl Sync for Identifier
impl Unpin for Identifier
impl UnsafeUnpin for Identifier
impl UnwindSafe for Identifier
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<T> CustomError for T
impl<T> CustomError for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more