/// Parses a JSON encoded string
/// @param {String} $source - JSON complete source
/// @param {Number} $pointer - current pointer
/// @throw Unterminated string.
/// @return {List} (new pointer, parsed string / color / length)
/// @require {function} _throw
/// @require {function} _find-ending-quote
/// @require {function} _strip-token
/// @require {function} _color
/// @require {function} _length
@function _json-decode--string($source, $pointer) {
  // Check for the end of the string
  $temp: str-slice($source, $pointer);
  $end: _find-ending-quote($temp);
  $string: "";

  // If no end is found
  @if not $end or $end == 0 {
    @return _throw("Unterminated string.", $pointer);
  } @else if $end > 1 {
    // If string is not empty
    $string: str-slice($temp, 1, $end - 1);

    $cr: "\a ";
    $string: _strip-token($string, "\\\r", $cr);
    $string: _strip-token($string, "\\\n", $cr);
    $string: _strip-token($string, '\\\"', '"');

    // Test whether the string could be a CSS length
    $string: _length($string);

    // Test whether the string could be a CSS color
    @if type-of($string) == "string" {
      $string: _color($string);
    }
  }

  @return ($pointer + $end, $string);
}
