sassIndexToStringIndex method

int sassIndexToStringIndex(
  1. Value sassIndex,
  2. [String? name]

Converts sassIndex into a Dart-style index into text.

Sass indexes are one-based, while Dart indexes are zero-based. Sass indexes may also be negative in order to index from the end of the string.

In addition, Sass indices refer to Unicode code points while Dart string indices refer to UTF-16 code units. For example, the character U+1F60A, Smiling Face With Smiling Eyes, is a single Unicode code point but is represented in UTF-16 as two code units (0xD83D and 0xDE0A). So in Dart, "a😊b".codeUnitAt(1) returns 0xD83D, whereas in Sass str-slice("a😊b", 1, 1) returns "😊".

This function converts Sass's code point indexes to Dart's code unit indexes. This means it's O(n) in the length of text. See also sassIndexToRuneIndex, which is O(1) and returns an index into the string's code points (accessible via text.runes).

Throws a SassScriptException if sassIndex isn't a number, if that number isn't an integer, or if that integer isn't a valid index for this string. If sassIndex came from a function argument, name is the argument name (without the $). It's used for error reporting.


int sassIndexToStringIndex(Value sassIndex, [String? name]) =>
        text, sassIndexToRuneIndex(sassIndex, name));