libsass inspect, str_index

95 views Asked by At

I have the following code that works well under sass 3.4.14

@function replaceAttribute($xml, $insert, $attribute) {
@if type-of($insert) != string {
    $insert: inspect($insert);
}
$search_str: $attribute + '="';

//How much to add to get to where the string should be inserted
$offset: str_length($search_str);
$idx: 1;
//The next attribute to replace in string
$next: str_index($xml, $search_str);

@while $next != null {
    $idx: $idx + $offset + $next - 1;

    //Remove old attribute value and add new
    $length_next: str_index(str_slice($xml, $idx), '"');
    $xml: str_slice($xml, 0, $idx - 1) + str_slice($xml, $idx + $length_next - 1);
    $xml: str_insert($xml, $insert, $idx);

    //Find new next attribute to replace
    $next: str_index(str_slice($xml, $idx), $search_str);
}
@return $xml;
}

It doesn't work well using libsass 3.2 but according to sass-compatibility.github.io/ all the string functions used here should be supported. I get the following error message:

argument $insert of str-insert($string, $insert, $index) must be a string

How do I fix this? I am trying to switch to libsass for reasons of sass compile time.

0

There are 0 answers