pub struct StringQuery<'a> { /* private fields */ }Expand description
Queries whether a string is a valid name of a given kind in Ruby.
The string is interpreted as UTF-8 unless another encoding is given with
StringQuery::encoding, and the answer is for the latest version of Ruby
unless another version is given with StringQuery::version.
use ruby_prism::StringQuery;
assert_eq!(Ok(true), StringQuery::new(b"foo").is_local());
assert_eq!(Ok(true), StringQuery::new(b"Foo").is_constant());
assert_eq!(Ok(true), StringQuery::new(b"foo?").is_method_name());
assert_eq!(Ok(true), StringQuery::new(b"defined?").is_keyword());Implementations§
Source§impl<'a> StringQuery<'a>
impl<'a> StringQuery<'a>
Sourcepub const fn encoding(self, encoding: &'a str) -> Self
pub const fn encoding(self, encoding: &'a str) -> Self
Sets the name of the encoding that the string is in, such as
"Windows-31J" or "US-ASCII".
Sourcepub const fn version(self, version: Version) -> Self
pub const fn version(self, version: Version) -> Self
Sets the version of Ruby to answer for. Which letters begin a constant name depends on the version of Unicode that it uses.
Sourcepub fn is_local(&self) -> Result<bool, InvalidEncodingError>
pub fn is_local(&self) -> Result<bool, InvalidEncodingError>
Returns whether the string is a valid local variable name.
§Errors
Returns InvalidEncodingError if the encoding is unknown or not
ASCII-compatible.
Sourcepub fn is_constant(&self) -> Result<bool, InvalidEncodingError>
pub fn is_constant(&self) -> Result<bool, InvalidEncodingError>
Returns whether the string is a valid constant name.
§Errors
Returns InvalidEncodingError if the encoding is unknown or not
ASCII-compatible.
Sourcepub fn is_method_name(&self) -> Result<bool, InvalidEncodingError>
pub fn is_method_name(&self) -> Result<bool, InvalidEncodingError>
Returns whether the string is a valid method name.
§Errors
Returns InvalidEncodingError if the encoding is unknown or not
ASCII-compatible.
Sourcepub fn is_keyword(&self) -> Result<bool, InvalidEncodingError>
pub fn is_keyword(&self) -> Result<bool, InvalidEncodingError>
Returns whether the string is a keyword (reserved word), such as if,
defined?, or __FILE__.
§Errors
Returns InvalidEncodingError if the encoding is unknown or not
ASCII-compatible.