pub struct StringExpression { /* private fields */ }
Expand description
Represents a string literal in Lua source code.
String literals in Lua can be written with single quotes, double quotes,
or with long brackets ([[...]]
or [=[...]=]
etc.) for multi-line strings.
Implementations§
Source§impl StringExpression
impl StringExpression
Sourcepub fn new(string: &str) -> Result<Self, StringError>
pub fn new(string: &str) -> Result<Self, StringError>
Creates a new StringExpression
from a raw Lua string literal.
Handles quoted strings (with either ’ or “ delimiters), long bracket strings, and processes escape sequences in quoted strings.
let single_quoted = StringExpression::new("'hello'").unwrap();
let double_quoted = StringExpression::new("\"world\"").unwrap();
let bracket_string = StringExpression::new("[[multi\nline]]").unwrap();
Sourcepub fn from_value(value: impl IntoLuaStringValue) -> Self
pub fn from_value(value: impl IntoLuaStringValue) -> Self
Creates a new StringExpression
from a string value.
Sourcepub fn with_token(self, token: Token) -> Self
pub fn with_token(self, token: Token) -> Self
Attaches a token to this string expression.
Sourcepub fn get_token(&self) -> Option<&Token>
pub fn get_token(&self) -> Option<&Token>
Returns the token associated with this string expression, if any.
Sourcepub fn get_string_value(&self) -> Option<&str>
pub fn get_string_value(&self) -> Option<&str>
Returns the string value if it is valid UTF-8.
Sourcepub fn into_value(self) -> Vec<u8> ⓘ
pub fn into_value(self) -> Vec<u8> ⓘ
Consumes the string expression and returns the inner string value.
Sourcepub fn into_string(self) -> Option<String>
pub fn into_string(self) -> Option<String>
Consumes the string expression and returns the inner string value if it is valid UTF-8.
Sourcepub fn is_multiline(&self) -> bool
pub fn is_multiline(&self) -> bool
Checks if the string contains newline characters.
Sourcepub fn has_single_quote(&self) -> bool
pub fn has_single_quote(&self) -> bool
Checks if the string contains single quotes.
Useful when determining the best quote style to use when serializing the string.
Sourcepub fn has_double_quote(&self) -> bool
pub fn has_double_quote(&self) -> bool
Checks if the string contains double quotes.
Useful when determining the best quote style to use when serializing the string.
Sourcepub fn clear_comments(&mut self)
pub fn clear_comments(&mut self)
Clears all comments from the tokens in this node.
Sourcepub fn clear_whitespaces(&mut self)
pub fn clear_whitespaces(&mut self)
Clears all whitespaces information from the tokens in this node.
Trait Implementations§
Source§impl Clone for StringExpression
impl Clone for StringExpression
Source§fn clone(&self) -> StringExpression
fn clone(&self) -> StringExpression
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for StringExpression
impl Debug for StringExpression
Source§impl From<StringExpression> for Arguments
impl From<StringExpression> for Arguments
Source§fn from(string: StringExpression) -> Self
fn from(string: StringExpression) -> Self
Source§impl From<StringExpression> for Expression
impl From<StringExpression> for Expression
Source§fn from(string: StringExpression) -> Self
fn from(string: StringExpression) -> Self
Source§impl PartialEq for StringExpression
impl PartialEq for StringExpression
impl Eq for StringExpression
impl StructuralPartialEq for StringExpression
Auto Trait Implementations§
impl Freeze for StringExpression
impl RefUnwindSafe for StringExpression
impl Send for StringExpression
impl Sync for StringExpression
impl Unpin for StringExpression
impl UnwindSafe for StringExpression
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> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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<I, T> ExtractContext<I, ()> for T
impl<I, T> ExtractContext<I, ()> for T
Source§fn extract_context(self, _original_input: I)
fn extract_context(self, _original_input: I)
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