class Sass::Util::MultibyteStringScanner
def pos=(n)
def pos=(n) @mb_last_pos = nil # We set position kind of a lot during parsing, so we want it to be as # efficient as possible. This is complicated by the fact that UTF-8 is a # variable-length encoding, so it's difficult to find the byte length that # corresponds to a given character length. # # Our heuristic here is to try to count the fewest possible characters. So # if the new position is close to the current one, just count the # characters between the two; if the new position is closer to the # beginning of the string, just count the characters from there. if @mb_pos - n < @mb_pos / 2 # New position is close to old position byte_delta = @mb_pos > n ? -string[n...@mb_pos].bytesize : string[@mb_pos...n].bytesize super(byte_pos + byte_delta) else # New position is close to BOS super(string[0...n].bytesize) end @mb_pos = n end