SmtString

Struct SmtString 

Source
pub struct SmtString(/* private fields */);
Expand description

An SMT-LIB string is a sequence of characters with unicode code points in the range 0x0000 to 0x2FFFF (first two planes of Unicode). The characters are represented by the SmtChar type.

ยงExamples

use smt_str::{SmtString, SmtChar};

// Create a new SmtString from a string literal
let s: SmtString = "foo".into();

// Obtain the length of the string
assert_eq!(s.len(), 3);

// SmtStrings have the correct length even for multi-byte characters
let s: SmtString = "๐Ÿฆ€".into();
assert_eq!(s.len(), 1);

// In Rust, the length of a string is counted in bytes, not characters
assert_eq!("๐Ÿฆ€".len(), 4);
assert_eq!("๐Ÿฆ€".chars().count(), 1);

// SmtString can be parsed from a string with escape sequences
let s: SmtString = SmtString::parse(r#"foo\u{61}bar"#);
assert_eq!(s, SmtString::from("fooabar"));

// Printing the string escapes non-printable characters
let s: SmtString = SmtString::from("foo\nbar");
assert_eq!(s.to_string(), r#"foo\u{A}bar"#);

Implementationsยง

Sourceยง

impl SmtString

Source

pub fn empty() -> Self

The empty string.

Source

pub fn new(chars: Vec<SmtChar>) -> Self

Create a new SmtString from a vector of SmtChar.

Source

pub fn parse(input: &str) -> Self

Parse a string into an SmtString.

The input string can contain escaped characters. The only valid escape sequences are:

  • \uDDDD
  • \u{D},
  • \u{DD},
  • \u{DDD},
  • \u{DDDD},
  • \u{DDDDD}

where D is a hexadecimal digit such that the resulting code point is in the range 0x0000 to 0x2FFFF. If the string contains valid escape sequences, they are replaced with the corresponding SmtChar. If the string contains invalid escape sequences, they are treated as literals. For example, the string "foo\u{61}bar" is parsed as the string "fooabar". But the string "foo\u{61bar" is parsed as the string "foo\u{61bar". The holds for syntactically valid escape sequences that result in code points outside the valid range. For example, the string "foo\u{3000A}bar" is parsed as the string "foo\u{3000A}bar", since the code point 0x3000A is outside the valid range.

ยงExamples
use smt_str::{SmtString};
let s: SmtString = SmtString::parse(r#"foo\u{61}bar"#);
assert_eq!(s, SmtString::from("fooabar"));

// Invalid escape sequence, treated as literal

let s: SmtString = SmtString::parse(r#"foo\u{61bar"#);
assert_eq!(s, SmtString::from(r#"foo\u{61bar"#));
Source

pub fn is_empty(&self) -> bool

Returns whether this string is empty.

ยงExamples
use smt_str::{SmtString};
assert!(SmtString::empty().is_empty());
let s: SmtString = "foo".into();
assert!(!s.is_empty());
Source

pub fn len(&self) -> usize

Returns the length of this string.

ยงExamples
use smt_str::{SmtString};
assert_eq!(SmtString::empty().len(), 0);
let s: SmtString = "foo".into();
assert_eq!(s.len(), 3);
Source

pub fn clear(&mut self)

Empties this string, removing all characters. After calling this method, the string will be empty.

ยงExamples
use smt_str::{SmtString};
let mut s: SmtString = "foo".into();
s.clear();
assert!(s.is_empty());
Source

pub fn append(&mut self, other: &SmtString)

Appends the characters of other to this string. The characters are appended in order.

ยงExamples
use smt_str::{SmtString, SmtChar};
let mut s: SmtString = "foo".into();
let other: SmtString = "bar".into();
s.append(&other);
let mut iter = s.iter();
assert_eq!(iter.next(), Some(&SmtChar::from('f')));
assert_eq!(iter.next(), Some(&SmtChar::from('o')));
assert_eq!(iter.next(), Some(&SmtChar::from('o')));
assert_eq!(iter.next(), Some(&SmtChar::from('b')));
assert_eq!(iter.next(), Some(&SmtChar::from('a')));
assert_eq!(iter.next(), Some(&SmtChar::from('r')));
assert_eq!(iter.next(), None);
Source

pub fn push(&mut self, c: impl Into<SmtChar>)

Pushes a character to the end of this string.

ยงExamples
use smt_str::{SmtString, SmtChar};
let mut s = SmtString::empty();
s.push(SmtChar::from('f'));
s.push(SmtChar::from('o'));
s.push(SmtChar::from('o'));
assert_eq!(s, SmtString::from("foo"));  
Source

pub fn concat(&self, other: &SmtString) -> SmtString

Concatenates this string with other and returns the result. This is a convenience method that does not modify this string. The characters of other are appended to the characters of this string, see [append].

ยงExamples
use smt_str::{SmtString};
let s1 = SmtString::from("foo");
let s2 = SmtString::from("bar");
let s3 = s1.concat(&s2);
assert_eq!(s3, SmtString::from("foobar"));
Source

pub fn contains_char(&self, c: impl Into<SmtChar>) -> bool

Checks if this string contains a character.

ยงExamples
use smt_str::{SmtString, SmtChar};
let s: SmtString = "foobar".into();
assert!(s.contains_char('f'));
assert!(s.contains_char('o'));
assert!(s.contains_char('b'));
assert!(!s.contains_char('z'));
Source

pub fn contains(&self, factor: &SmtString) -> bool

Return whether this string contains another string as a factor. This is a naive implementation that checks all possible factors of this string, leading to O(n^2) complexity.

ยงExamples
use smt_str::{SmtString};
let s: SmtString = "foobar".into();
assert!(s.contains(&SmtString::empty()));
assert!(s.contains(&SmtString::from("foo")));
assert!(s.contains(&SmtString::from("bar")));
assert!(s.contains(&SmtString::from("oba")));
assert!(!s.contains(&SmtString::from("baz")));

// The empty string contains only has the empty string as a factor
let empty: SmtString = SmtString::empty();
assert!(empty.contains(&SmtString::empty()));
assert!(!empty.contains(&SmtString::from("foo")));
Source

pub fn index_of(&self, factor: &SmtString, start: usize) -> Option<usize>

Find the index of the first occurrence of a factor in the suffix of this string starting at start. Returns None if the factor is not found. The empty string is a factor of every string and will always return Some(0).

ยงExamples
use smt_str::{SmtString};
let s: SmtString = "foobar".into();
assert_eq!(s.index_of(&SmtString::empty(),0), Some(0));
assert_eq!(s.index_of(&SmtString::from("foo"),0), Some(0));
assert_eq!(s.index_of(&SmtString::from("foo"),1), None);
assert_eq!(s.index_of(&SmtString::from("bar"),0), Some(3));
assert_eq!(s.index_of(&SmtString::from("oba"),0), Some(2));
assert_eq!(s.index_of(&SmtString::from("baz"),0), None);

// If the string is empty, the only factor is the empty string
let empty: SmtString = SmtString::empty();
assert_eq!(empty.index_of(&SmtString::empty(),0), Some(0));
assert_eq!(empty.index_of(&SmtString::from("foo"),0), None);
Source

pub fn starts_with(&self, prefix: &SmtString) -> bool

Returns whether this string starts with a prefix. The empty string is a prefix of every string.

ยงExamples
use smt_str::{SmtString};
let s: SmtString = "foobar".into();
assert!(s.starts_with(&SmtString::empty()));
assert!(s.starts_with(&SmtString::from("foo")));
assert!(!s.starts_with(&SmtString::from("bar")));
Source

pub fn ends_with(&self, suffix: &SmtString) -> bool

Returns whether this string ends with a suffix. The empty string is a suffix of every string.

ยงExamples
use smt_str::{SmtString};
let s: SmtString = "foobar".into();
assert!(s.ends_with(&SmtString::empty()));
assert!(s.ends_with(&SmtString::from("bar")));
assert!(!s.ends_with(&SmtString::from("foo")));
Source

pub fn first(&self) -> Option<SmtChar>

Returns the first character of this string, if it is not empty. Returns None if this string is empty.

ยงExamples
use smt_str::{SmtString, SmtChar};
let s: SmtString = "foo".into();
assert_eq!(s.first(), Some('f'.into()));
assert_eq!(SmtString::empty().first(), None);
Source

pub fn last(&self) -> Option<SmtChar>

Returns the last character of this string, if it is not empty. Returns None if this string is empty.

ยงExamples
use smt_str::{SmtString, SmtChar};
let s: SmtString = "foo".into();
assert_eq!(s.last(), Some('o'.into()));
assert_eq!(SmtString::empty().last(), None);
Source

pub fn take(&self, n: usize) -> SmtString

Returns the prefix of length n of this string. If n is greater than the length of this string, the entire string is returned. If n is zero, the empty string is returned.

ยงExamples
use smt_str::{SmtString, SmtChar};
let s: SmtString = "foo".into();

assert_eq!( s.take(2), SmtString::from("fo"));
assert!(s.take(10) == s);
assert!(s.take(0) == SmtString::empty());
Source

pub fn drop(&self, n: usize) -> SmtString

Returns the suffix of this string after removing the first n characters. If n is greater than the length of this string, the empty string is returned. If n is zero, the entire string is returned.

ยงExamples
use smt_str::{SmtString, SmtChar};
let s = SmtString::from("foo");
assert_eq!(s.drop(2), SmtString::from("o"));
assert_eq!(s.drop(10), SmtString::empty());
assert_eq!(s.drop(0), s);
Source

pub fn nth(&self, n: usize) -> Option<SmtChar>

Returns the n-th character of this string. Returns None if n is greater than or equal to the length of this string.

ยงExamples
use smt_str::{SmtString, SmtChar};
let s: SmtString = "foo".into();
assert_eq!(s.nth(0), Some(SmtChar::from('f')));
assert_eq!(s.nth(1), Some(SmtChar::from('o')));
assert_eq!(s.nth(2), Some(SmtChar::from('o')));
assert_eq!(s.nth(3), None);
Source

pub fn reversed(&self) -> Self

Returns the reverse of this string.

ยงExamples
use smt_str::{SmtString, SmtChar};
let s: SmtString = "foo".into();
let rev = s.reversed();
let mut iter = rev.iter();
assert_eq!(iter.next(), Some(&SmtChar::from('o')));
assert_eq!(iter.next(), Some(&SmtChar::from('o')));
assert_eq!(iter.next(), Some(&SmtChar::from('f')));
assert_eq!(iter.next(), None);
Source

pub fn repeat(&self, n: usize) -> Self

Repeat this string n times. If n is zero, the empty string is returned. If this string is empty, the empty string is returned. If n is one, this string is returned. Otherwise, the string is repeated n times.

ยงExamples
use smt_str::{SmtString, SmtChar};
let s = SmtString::from("foo");
assert_eq!(s.repeat(0), SmtString::empty());
assert_eq!(s.repeat(1), s);
assert_eq!(s.repeat(2), SmtString::from("foofoo"));
Source

pub fn replace(&self, from: &SmtString, to: &SmtString) -> SmtString

Replaces the first occurrence of from in this string with to. If from is not found in this string, the string is returned unchanged.

ยงExamples
use smt_str::{SmtString};
let s: SmtString = "barbar".into();
let from: SmtString = "bar".into();
let to: SmtString = "foo".into();
assert_eq!(s.replace(&from, &to), SmtString::from("foobar"));
Source

pub fn replace_all(&self, from: &SmtString, to: &SmtString) -> SmtString

Replaces all occurrences of from in this string with to. If from is not found in this string, the string is returned unchanged. If from is the empty string, the string is returned unchanged.

ยงExamples
use smt_str::{SmtString};
let s: SmtString = "barbar".into();
let from: SmtString = "bar".into();
let to: SmtString = "foo".into();
assert_eq!(s.replace_all(&from, &to), SmtString::from("foofoo"));
Source

pub fn iter(&self) -> Iter<'_, SmtChar>

Returns an iterator over the characters of this string.

Trait Implementationsยง

Sourceยง

impl Arbitrary for SmtString

Sourceยง

fn arbitrary(g: &mut Gen) -> Self

Return an arbitrary value. Read more
Sourceยง

fn shrink(&self) -> Box<dyn Iterator<Item = Self>>

Return an iterator of values that are smaller than itself. Read more
Sourceยง

impl Clone for SmtString

Sourceยง

fn clone(&self) -> SmtString

Returns a duplicate of the value. Read more
1.0.0 ยท Sourceยง

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Sourceยง

impl Debug for SmtString

Sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Sourceยง

impl Display for SmtString

Sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Sourceยง

impl From<&str> for SmtString

Sourceยง

fn from(s: &str) -> Self

Converts to this type from the input type.
Sourceยง

impl From<SmtChar> for SmtString

Sourceยง

fn from(c: SmtChar) -> Self

Converts to this type from the input type.
Sourceยง

impl From<String> for SmtString

Sourceยง

fn from(s: String) -> Self

Converts to this type from the input type.
Sourceยง

impl FromIterator<SmtChar> for SmtString

Sourceยง

fn from_iter<I: IntoIterator<Item = SmtChar>>(iter: I) -> Self

Creates a value from an iterator. Read more
Sourceยง

impl FromIterator<SmtString> for SmtString

Sourceยง

fn from_iter<I: IntoIterator<Item = SmtString>>(iter: I) -> Self

Creates a value from an iterator. Read more
Sourceยง

impl Hash for SmtString

Sourceยง

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 ยท Sourceยง

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

Feeds a slice of this type into the given Hasher. Read more
Sourceยง

impl Index<usize> for SmtString

Sourceยง

type Output = SmtChar

The returned type after indexing.
Sourceยง

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Sourceยง

impl PartialEq for SmtString

Sourceยง

fn eq(&self, other: &SmtString) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 ยท Sourceยง

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Sourceยง

impl Eq for SmtString

Sourceยง

impl StructuralPartialEq for SmtString

Auto Trait Implementationsยง

Blanket Implementationsยง

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<T> CloneToUninit for T
where T: Clone,

Sourceยง

unsafe fn clone_to_uninit(&self, dest: *mut u8)

๐Ÿ”ฌThis is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Sourceยง

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Sourceยง

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Sourceยง

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Sourceยง

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Sourceยง

impl<T> IntoEither for T

Sourceยง

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Sourceยง

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Sourceยง

impl<T> ToOwned for T
where T: Clone,

Sourceยง

type Owned = T

The resulting type after obtaining ownership.
Sourceยง

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Sourceยง

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Sourceยง

impl<T> ToString for T
where T: Display + ?Sized,

Sourceยง

fn to_string(&self) -> String

Converts the given value to a String. Read more
Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = Infallible

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

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

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Sourceยง

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Sourceยง

fn vzip(self) -> V