[][src]Struct encode_unicode::Utf16Char

pub struct Utf16Char { /* fields omitted */ }

An unicode codepoint stored as UTF-16.

It can be borrowed as an u16 slice, and has the same size as char.

Methods

impl Utf16Char[src]

pub fn from_str_start(s: &str) -> Result<(Self, usize), EmptyStrError>[src]

Create an Utf16Char from the first codepoint in a string slice, converting from UTF-8 to UTF-16.

The returned usize is the number of UTF-8 bytes used from the str, and not the number of UTF-16 units.

Returns an error if the str is empty.

Examples

use encode_unicode::Utf16Char;

assert_eq!(Utf16Char::from_str_start("a"), Ok((Utf16Char::from('a'),1)));
assert_eq!(Utf16Char::from_str_start("ab"), Ok((Utf16Char::from('a'),1)));
assert_eq!(Utf16Char::from_str_start("🂠 "), Ok((Utf16Char::from('🂠'),4)));
assert_eq!(Utf16Char::from_str_start("é"), Ok((Utf16Char::from('e'),1)));// 'e'+u301 combining mark
assert!(Utf16Char::from_str_start("").is_err());

pub fn from_slice_start(src: &[u16]) -> Result<(Self, usize), InvalidUtf16Slice>[src]

Validate and store the first UTF-16 codepoint in the slice. Also return how many units were needed.

pub unsafe fn from_slice_start_unchecked(src: &[u16]) -> (Self, usize)[src]

Store the first UTF-16 codepoint of the slice.

Safety

The slice must be non-empty and start with a valid UTF-16 codepoint.
The length of the slice is never checked.

pub fn from_array(units: [u16; 2]) -> Result<Self, InvalidUtf16Array>[src]

Validate and store an UTF-16 array as returned from char.to_utf16_array().

Examples

use encode_unicode::Utf16Char;
use encode_unicode::error::InvalidUtf16Array;

assert_eq!(Utf16Char::from_array(['x' as u16, 'y' as u16]), Ok(Utf16Char::from('x')));
assert_eq!(Utf16Char::from_array(['睷' as u16, 0]), Ok(Utf16Char::from('睷')));
assert_eq!(Utf16Char::from_array([0xda6f, 0xdcde]), Ok(Utf16Char::from('\u{abcde}')));
assert_eq!(Utf16Char::from_array([0xf111, 0xdbad]), Ok(Utf16Char::from('\u{f111}')));
assert_eq!(Utf16Char::from_array([0xdaaf, 0xdaaf]), Err(InvalidUtf16Array::SecondIsNotTrailingSurrogate));
assert_eq!(Utf16Char::from_array([0xdcac, 0x9000]), Err(InvalidUtf16Array::FirstIsTrailingSurrogate));

pub unsafe fn from_array_unchecked(units: [u16; 2]) -> Self[src]

Create an Utf16Char from an array as returned from char.to_utf16_array().

Safety

The units must form a valid codepoint, and the second unit must be 0 when a surrogate pair is not required. Violating this can easily lead to undefined behavior, although unlike char bad Utf16Chars simply existing is not immediately UB.

pub fn from_tuple(utf16: (u16, Option<u16>)) -> Result<Self, InvalidUtf16Tuple>[src]

Validate and store a UTF-16 pair as returned from char.to_utf16_tuple().

pub unsafe fn from_tuple_unchecked(utf16: (u16, Option<u16>)) -> Self[src]

Create an Utf16Char from a tuple as returned from char.to_utf16_tuple().

Safety

The units must form a valid codepoint with the second being 0 when a surrogate pair is not required. Violating this can easily lead to undefined behavior.

pub fn from_bmp(bmp_codepoint: u16) -> Result<Self, NonBMPError>[src]

Create an Utf16Char from a single unit.

Codepoints < '\u{1_0000}' (which fit in a u16) are part of the basic multilingual plane unless they are reserved for surrogate pairs.

Errors

Returns NonBMPError if the unit is in the range 0xd800..0xe000 (which means that it's part of a surrogat pair)

Examples

assert_eq!(Utf16Char::from_bmp(0x40).unwrap(), '@');
assert_eq!(Utf16Char::from_bmp('ø' as u16).unwrap(), 'ø');
assert!(Utf16Char::from_bmp(0xdddd).is_err());

pub unsafe fn from_bmp_unchecked(bmp_codepoint: u16) -> Self[src]

Create an Utf16Char from a single unit without checking that it's a valid codepoint on its own.

Safety

The unit must be less than 0xd800 or greater than 0xdfff. In other words, not part of a surrogate pair.
Violating this can easily lead to undefined behavior.

pub fn is_bmp(&self) -> bool[src]

Checks that the codepoint is in the basic multilingual plane.

Examples

assert_eq!(Utf16Char::from('e').is_bmp(), true);
assert_eq!(Utf16Char::from('€').is_bmp(), true);
assert_eq!(Utf16Char::from('𝔼').is_bmp(), false);

pub fn len(self) -> usize[src]

The number of units this character is made up of.

Is either 1 or 2 and identical to .as_char().len_utf16() or .as_ref().len().

pub fn is_ascii(&self) -> bool[src]

Checks that the codepoint is an ASCII character.

pub fn eq_ignore_ascii_case(&self, other: &Self) -> bool[src]

Checks that two characters are an ASCII case-insensitive match.

Is equivalent to a.to_ascii_lowercase() == b.to_ascii_lowercase().

pub fn to_ascii_uppercase(&self) -> Self[src]

Converts the character to its ASCII upper case equivalent.

ASCII letters 'a' to 'z' are mapped to 'A' to 'Z', but non-ASCII letters are unchanged.

pub fn to_ascii_lowercase(&self) -> Self[src]

Converts the character to its ASCII lower case equivalent.

ASCII letters 'A' to 'Z' are mapped to 'a' to 'z', but non-ASCII letters are unchanged.

pub fn make_ascii_uppercase(&mut self)[src]

Converts the character to its ASCII upper case equivalent in-place.

ASCII letters 'a' to 'z' are mapped to 'A' to 'Z', but non-ASCII letters are unchanged.

pub fn make_ascii_lowercase(&mut self)[src]

Converts the character to its ASCII lower case equivalent in-place.

ASCII letters 'A' to 'Z' are mapped to 'a' to 'z', but non-ASCII letters are unchanged.

pub fn to_char(self) -> char[src]

Convert from UTF-16 to UTF-32

pub fn to_slice(self, dst: &mut [u16]) -> usize[src]

Write the internal representation to a slice, and then returns the number of u16s written.

Panics

Will panic the buffer is too small; You can get the required length from .len(), but a buffer of length two is always large enough.

pub fn to_array(self) -> [u16; 2][src]

Get the character represented as an array of two units.

The second u16 is zero for codepoints that fit in one unit.

pub fn to_tuple(self) -> (u16, Option<u16>)[src]

The second u16 is used for surrogate pairs.

Trait Implementations

impl From<Utf16Char> for Utf8Char[src]

impl From<char> for Utf16Char[src]

impl From<Utf8Char> for Utf16Char[src]

impl From<Utf16Char> for char[src]

impl From<AsciiChar> for Utf16Char[src]

Requires the feature "ascii".

impl From<Utf16Char> for Utf16Iterator[src]

impl Ord for Utf16Char[src]

fn max(self, other: Self) -> Self1.21.0[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self1.21.0[src]

Compares and returns the minimum of two values. Read more

fn clamp(self, min: Self, max: Self) -> Self[src]

🔬 This is a nightly-only experimental API. (clamp)

Restrict a value to a certain interval. Read more

impl PartialOrd<Utf16Char> for Utf8Char[src]

#[must_use] fn lt(&self, other: &Rhs) -> bool1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use] fn le(&self, other: &Rhs) -> bool1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use] fn gt(&self, other: &Rhs) -> bool1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use] fn ge(&self, other: &Rhs) -> bool1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialOrd<Utf16Char> for Utf16Char[src]

#[must_use] fn lt(&self, other: &Rhs) -> bool1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use] fn le(&self, other: &Rhs) -> bool1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use] fn gt(&self, other: &Rhs) -> bool1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use] fn ge(&self, other: &Rhs) -> bool1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialOrd<char> for Utf16Char[src]

#[must_use] fn lt(&self, other: &Rhs) -> bool1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use] fn le(&self, other: &Rhs) -> bool1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use] fn gt(&self, other: &Rhs) -> bool1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use] fn ge(&self, other: &Rhs) -> bool1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialOrd<Utf16Char> for char[src]

#[must_use] fn lt(&self, other: &Rhs) -> bool1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use] fn le(&self, other: &Rhs) -> bool1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use] fn gt(&self, other: &Rhs) -> bool1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use] fn ge(&self, other: &Rhs) -> bool1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialOrd<Utf8Char> for Utf16Char[src]

#[must_use] fn lt(&self, other: &Rhs) -> bool1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use] fn le(&self, other: &Rhs) -> bool1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use] fn gt(&self, other: &Rhs) -> bool1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use] fn ge(&self, other: &Rhs) -> bool1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialOrd<AsciiChar> for Utf16Char[src]

Utf16Chars that are not ASCII always compare greater.

#[must_use] fn lt(&self, other: &Rhs) -> bool1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use] fn le(&self, other: &Rhs) -> bool1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use] fn gt(&self, other: &Rhs) -> bool1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use] fn ge(&self, other: &Rhs) -> bool1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialOrd<Utf16Char> for AsciiChar[src]

Utf16Chars that are not ASCII always compare greater.

#[must_use] fn lt(&self, other: &Rhs) -> bool1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use] fn le(&self, other: &Rhs) -> bool1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use] fn gt(&self, other: &Rhs) -> bool1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use] fn ge(&self, other: &Rhs) -> bool1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialEq<Utf16Char> for Utf8Char[src]

#[must_use] fn ne(&self, other: &Rhs) -> bool1.0.0[src]

This method tests for !=.

impl PartialEq<Utf16Char> for Utf16Char[src]

impl PartialEq<char> for Utf16Char[src]

#[must_use] fn ne(&self, other: &Rhs) -> bool1.0.0[src]

This method tests for !=.

impl PartialEq<Utf16Char> for char[src]

#[must_use] fn ne(&self, other: &Rhs) -> bool1.0.0[src]

This method tests for !=.

impl PartialEq<Utf8Char> for Utf16Char[src]

#[must_use] fn ne(&self, other: &Rhs) -> bool1.0.0[src]

This method tests for !=.

impl PartialEq<u16> for Utf16Char[src]

Only considers the unit equal if the codepoint of the Utf16Char is not made up of a surrogate pair.

There is no impl in the opposite direction, as this should only be used to compare Utf16Chars against constants.

Examples

assert!(Utf16Char::from('6') == b'6' as u16);
assert!(Utf16Char::from('\u{FFFF}') == 0xffff_u16);
assert!(Utf16Char::from_tuple((0xd876, Some(0xdef9))).unwrap() != 0xd876_u16);

#[must_use] fn ne(&self, other: &Rhs) -> bool1.0.0[src]

This method tests for !=.

impl PartialEq<u8> for Utf16Char[src]

Only considers the byte equal if the codepoint of the Utf16Char is <= U+FF.

Examples

assert!(Utf16Char::from('6') == b'6');
assert!(Utf16Char::from('\u{00FF}') == b'\xff');
assert!(Utf16Char::from('\u{0100}') != b'\0');

#[must_use] fn ne(&self, other: &Rhs) -> bool1.0.0[src]

This method tests for !=.

impl PartialEq<AsciiChar> for Utf16Char[src]

Utf16Chars that are not ASCII never compare equal.

#[must_use] fn ne(&self, other: &Rhs) -> bool1.0.0[src]

This method tests for !=.

impl PartialEq<Utf16Char> for AsciiChar[src]

Utf16Chars that are not ASCII never compare equal.

#[must_use] fn ne(&self, other: &Rhs) -> bool1.0.0[src]

This method tests for !=.

impl Default for Utf16Char[src]

impl IntoIterator for Utf16Char[src]

type Item = u16

The type of the elements being iterated over.

type IntoIter = Utf16Iterator

Which kind of iterator are we turning this into?

Important traits for Utf16Iterator
fn into_iter(self) -> Utf16Iterator[src]

Iterate over the units.

impl Extend<Utf16Char> for Vec<u16>[src]

impl<'a> Extend<&'a Utf16Char> for Vec<u16>[src]

impl Extend<Utf16Char> for String[src]

impl<'a> Extend<&'a Utf16Char> for String[src]

impl Clone for Utf16Char[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Eq for Utf16Char[src]

impl AsRef<[u16]> for Utf16Char[src]

impl Copy for Utf16Char[src]

impl Deref for Utf16Char[src]

type Target = [u16]

The resulting type after dereferencing.

impl Display for Utf16Char[src]

impl Debug for Utf16Char[src]

impl FromStr for Utf16Char[src]

type Err = FromStrError

The associated error which can be returned from parsing.

fn from_str(s: &str) -> Result<Self, FromStrError>[src]

Create an Utf16Char from a string slice. The string must contain exactly one codepoint.

Examples

use encode_unicode::error::FromStrError::*;
use encode_unicode::Utf16Char;
use std::str::FromStr;

assert_eq!(Utf16Char::from_str("a"), Ok(Utf16Char::from('a')));
assert_eq!(Utf16Char::from_str("🂠"), Ok(Utf16Char::from('🂠')));
assert_eq!(Utf16Char::from_str(""), Err(Empty));
assert_eq!(Utf16Char::from_str("ab"), Err(MultipleCodepoints));
assert_eq!(Utf16Char::from_str("é"), Err(MultipleCodepoints));// 'e'+u301 combining mark

impl Hash for Utf16Char[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl FromIterator<Utf16Char> for Vec<u16>[src]

impl<'a> FromIterator<&'a Utf16Char> for Vec<u16>[src]

impl FromIterator<Utf16Char> for String[src]

impl<'a> FromIterator<&'a Utf16Char> for String[src]

impl Borrow<[u16]> for Utf16Char[src]

impl AsciiExt for Utf16Char[src]

type Owned = Self

Deprecated since 1.26.0:

use inherent methods instead

Container type for copied ASCII characters.

impl ToAsciiChar for Utf16Char[src]

Requires the feature "ascii".

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]