// Thanks to Hugo Giraudel for his str-replace function (http://www.sassmeister.com/gist/1b4f2da5527830088e4d)
@function str-replace($string, $search, $replace: '') {
  $index: str-index($string, $search);
  @if $index {
    @return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
  }
  @return $string;
}


$encoding-reference: (('<', '%3C'), ('>', '%3E'), ('"', '\''), ('#', '%23'), ('&', '%26'));

@function svg-encode($svg, $fill-color: $body-bg) {
  $svg: str-replace($svg, 'XXXXXX', $fill-color);
  @each $char, $encoded in $encoding-reference {
    $svg: str-replace($svg, $char, $encoded);
  }
  @return 'data:image/svg+xml,' + $svg;
}
