/*
  @a-pollo-doc
  @author: [Vittorio Vittori](http://github.com/vitto)
  @category: Functions
  @code: Usage example
    $list: str-explode('hello world',  ' ');
    .selector {
      content: nth($list, 1);
    }
  @css: The CSS generated
    .selector {
      content: "hello";
    }
  @date: 2017-02-21T12:57:57+01:00
  @type: function
  @icon: fa fa-scissors
  @name: str-explode
  @title: String
  @param: {string} ($string) [required]
          The string you want to split
  @param: {string} ($split) [required]
          The search term to split the string in a list
  @public: true
  @returns: list
  @text: A function to replace multiple occurrences inside a string
  @version: 4.0.0
*/

@function str-explode($string, $split) {
  $list: ();
  $sum: str-length($string);
  @for $i from 1 through $sum {
    $str: str-index($string, $split);
    @if str-length($string) >= 1 and $str == null {
      $list: append($list, $string);
      $string: '';
    }
    @if type-of($str) == number {
      $each: str-slice($string, 0, ($str - 1));
      $list: append($list, $each);
      $string: str-slice($string, ($str + 1), $sum);
    }
  }
  @return $list;
}

/*
  @a-pollo-doc
  @author: [Vittorio Vittori](http://github.com/vitto)
  @category: Functions
  @code: Usage example
    .selector {
      content: str-replace('hello world', 'o', '*');
    }
  @css: The CSS generated
    .selector {
      content: "hell* w*rld";
    }
  @date: 2017-02-21T12:47:26+01:00
  @type: function
  @icon: fa fa-exchange
  @name: str-replace
  @param: {string} ($string) [required]
          The string you want to manipulate
  @param: {string} ($search) [required]
          The search term you want to replace, will be performed a global search inside the string
  @param: {string} ($replace) [empty string]
          The string will be used to replace occurrences
  @public: true
  @returns: string
  @text: A function to replace multiple occurrences inside a string
  @version: 4.0.0
*/

@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;
}
