@use 'sass:string';
@use 'string' as spirit-string;
@use '../settings/svg' as svg-settings;

@function escape($string) {
    @if string.index($string, 'data:image/svg+xml') {
        @each $char, $encoded in svg-settings.$escaped-characters {
            // Do not escape the url brackets
            @if string.index($string, 'url(') == 1 {
                $string: url('#{spirit-string.replace(string.slice($string, 6, -3), $char, $encoded)}');
            } @else {
                $string: spirit-string.replace($string, $char, $encoded);
            }
        }
    }

    @return $string;
}
