alias sass:string
builtin functions
This commit is contained in:
parent
ca4c5da73e
commit
b3d20a574a
@ -15,7 +15,7 @@ use crate::{
|
||||
value::{Number, Value},
|
||||
};
|
||||
|
||||
fn to_upper_case(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
pub(crate) fn to_upper_case(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
args.max_args(1)?;
|
||||
match args.get_err(0, "string")? {
|
||||
Value::String(mut i, q) => {
|
||||
@ -30,7 +30,7 @@ fn to_upper_case(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Valu
|
||||
}
|
||||
}
|
||||
|
||||
fn to_lower_case(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
pub(crate) fn to_lower_case(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
args.max_args(1)?;
|
||||
match args.get_err(0, "string")? {
|
||||
Value::String(mut i, q) => {
|
||||
@ -45,7 +45,7 @@ fn to_lower_case(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Valu
|
||||
}
|
||||
}
|
||||
|
||||
fn str_length(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
pub(crate) fn str_length(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
args.max_args(1)?;
|
||||
match args.get_err(0, "string")? {
|
||||
Value::String(i, _) => Ok(Value::Dimension(
|
||||
@ -61,7 +61,7 @@ fn str_length(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value>
|
||||
}
|
||||
}
|
||||
|
||||
fn quote(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
pub(crate) fn quote(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
args.max_args(1)?;
|
||||
match args.get_err(0, "string")? {
|
||||
Value::String(i, _) => Ok(Value::String(i, QuoteKind::Quoted)),
|
||||
@ -73,7 +73,7 @@ fn quote(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
}
|
||||
}
|
||||
|
||||
fn unquote(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
pub(crate) fn unquote(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
args.max_args(1)?;
|
||||
match args.get_err(0, "string")? {
|
||||
i @ Value::String(..) => Ok(i.unquote()),
|
||||
@ -85,7 +85,7 @@ fn unquote(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
}
|
||||
}
|
||||
|
||||
fn str_slice(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
pub(crate) fn str_slice(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
args.max_args(3)?;
|
||||
let (string, quotes) = match args.get_err(0, "string")? {
|
||||
Value::String(s, q) => (s, q),
|
||||
@ -178,7 +178,7 @@ fn str_slice(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
}
|
||||
}
|
||||
|
||||
fn str_index(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
pub(crate) fn str_index(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
args.max_args(2)?;
|
||||
let s1 = match args.get_err(0, "string")? {
|
||||
Value::String(i, _) => i,
|
||||
@ -208,7 +208,7 @@ fn str_index(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
})
|
||||
}
|
||||
|
||||
fn str_insert(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
pub(crate) fn str_insert(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
args.max_args(3)?;
|
||||
let (s1, quotes) = match args.get_err(0, "string")? {
|
||||
Value::String(i, q) => (i, q),
|
||||
@ -305,7 +305,7 @@ fn str_insert(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value>
|
||||
|
||||
#[cfg(feature = "random")]
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
fn unique_id(args: CallArgs, _: &mut Parser<'_>) -> SassResult<Value> {
|
||||
pub(crate) fn unique_id(args: CallArgs, _: &mut Parser<'_>) -> SassResult<Value> {
|
||||
args.max_args(0)?;
|
||||
let mut rng = thread_rng();
|
||||
let string = std::iter::repeat(())
|
||||
|
@ -1,4 +1,4 @@
|
||||
mod functions;
|
||||
pub(crate) mod modules;
|
||||
|
||||
pub(crate) use functions::{list, map, math, meta, selector, Builtin, GLOBAL_FUNCTIONS};
|
||||
pub(crate) use functions::{list, map, math, meta, selector, string, Builtin, GLOBAL_FUNCTIONS};
|
||||
|
@ -1,5 +1,28 @@
|
||||
use crate::{
|
||||
args::CallArgs, builtin::modules::Module, error::SassResult, parse::Parser, value::Value,
|
||||
args::CallArgs,
|
||||
builtin::{
|
||||
modules::Module,
|
||||
string::{
|
||||
quote, str_index, str_insert, str_length, str_slice, to_lower_case, to_upper_case,
|
||||
unquote,
|
||||
},
|
||||
},
|
||||
error::SassResult,
|
||||
parse::Parser,
|
||||
value::Value,
|
||||
};
|
||||
|
||||
pub(crate) fn declare(_f: &mut Module) {}
|
||||
#[cfg(feature = "random")]
|
||||
use crate::builtin::string::unique_id;
|
||||
|
||||
pub(crate) fn declare(f: &mut Module) {
|
||||
f.insert_builtin("quote", quote);
|
||||
f.insert_builtin("index", str_index);
|
||||
f.insert_builtin("insert", str_insert);
|
||||
f.insert_builtin("length", str_length);
|
||||
f.insert_builtin("slice", str_slice);
|
||||
f.insert_builtin("to-lower-case", to_lower_case);
|
||||
f.insert_builtin("to-upper-case", to_upper_case);
|
||||
#[cfg(feature = "random")]
|
||||
f.insert_builtin("unique-id", unique_id);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user