consolidate implementation of unvendor()
This commit is contained in:
parent
8b907d4b67
commit
ae77325ad0
@ -144,3 +144,26 @@ impl Identifier {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `name` without a vendor prefix.
|
||||
///
|
||||
/// If `name` has no vendor prefix, it's returned as-is.
|
||||
pub(crate) fn unvendor(name: &str) -> &str {
|
||||
let bytes = name.as_bytes();
|
||||
|
||||
if bytes.len() < 2 {
|
||||
return name;
|
||||
}
|
||||
|
||||
if bytes.get(0_usize) != Some(&b'-') || bytes.get(1_usize) == Some(&b'-') {
|
||||
return name;
|
||||
}
|
||||
|
||||
for i in 2..bytes.len() {
|
||||
if bytes.get(i) == Some(&b'-') {
|
||||
return &name[i + 1..];
|
||||
}
|
||||
}
|
||||
|
||||
name
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ use peekmore::PeekMore;
|
||||
use crate::{
|
||||
args::CallArgs,
|
||||
atrule::Function,
|
||||
common::unvendor,
|
||||
error::SassResult,
|
||||
utils::{read_until_closing_curly_brace, read_until_semicolon_or_closing_curly_brace},
|
||||
value::Value,
|
||||
@ -16,27 +17,6 @@ use super::{NeverEmptyVec, Parser, Stmt};
|
||||
const FORBIDDEN_IDENTIFIERS: [&str; 7] =
|
||||
["calc", "element", "expression", "url", "and", "or", "not"];
|
||||
|
||||
fn unvendor(name: &str) -> &str {
|
||||
let mut chars = name.chars();
|
||||
if !matches!(chars.next(), Some('-')) {
|
||||
return name;
|
||||
}
|
||||
if matches!(chars.next(), Some('-')) {
|
||||
return name;
|
||||
}
|
||||
if name.chars().count() < 2 {
|
||||
return name;
|
||||
}
|
||||
let mut pos = 2;
|
||||
for c in chars {
|
||||
if c == '-' {
|
||||
return &name[pos..];
|
||||
}
|
||||
pos += 1;
|
||||
}
|
||||
name
|
||||
}
|
||||
|
||||
impl<'a> Parser<'a> {
|
||||
pub(super) fn parse_function(&mut self) -> SassResult<()> {
|
||||
self.whitespace_or_comment();
|
||||
|
@ -1,6 +1,7 @@
|
||||
use codemap::Span;
|
||||
|
||||
use crate::{
|
||||
common::unvendor,
|
||||
error::SassResult,
|
||||
parse::Parser,
|
||||
utils::{is_name, is_name_start, read_until_closing_paren},
|
||||
@ -560,29 +561,6 @@ fn is_simple_selector_start(c: char) -> bool {
|
||||
matches!(c, '*' | '[' | '.' | '#' | '%' | ':')
|
||||
}
|
||||
|
||||
/// Returns `name` without a vendor prefix.
|
||||
///
|
||||
/// If `name` has no vendor prefix, it's returned as-is.
|
||||
fn unvendor(name: &str) -> &str {
|
||||
let bytes = name.as_bytes();
|
||||
|
||||
if bytes.len() < 2 {
|
||||
return name;
|
||||
}
|
||||
|
||||
if bytes[0_usize] != b'-' || bytes[1_usize] == b'-' {
|
||||
return name;
|
||||
}
|
||||
|
||||
for i in 2..bytes.len() {
|
||||
if bytes.get(i) == Some(&b'-') {
|
||||
return &name[i + 1..];
|
||||
}
|
||||
}
|
||||
|
||||
name
|
||||
}
|
||||
|
||||
/// Returns whether `name` is the name of a pseudo-element that can be written
|
||||
/// with pseudo-class syntax (`:before`, `:after`, `:first-line`, or
|
||||
/// `:first-letter`)
|
||||
|
Loading…
x
Reference in New Issue
Block a user