X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Ftwbs%2Fbootstrap-sass%2Ftasks%2Fconverter%2Fchar_string_scanner.rb;fp=vendor%2Ftwbs%2Fbootstrap-sass%2Ftasks%2Fconverter%2Fchar_string_scanner.rb;h=b2aead8c39551aafc63b7c13166b41f95311c051;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/twbs/bootstrap-sass/tasks/converter/char_string_scanner.rb b/vendor/twbs/bootstrap-sass/tasks/converter/char_string_scanner.rb new file mode 100644 index 000000000..b2aead8c3 --- /dev/null +++ b/vendor/twbs/bootstrap-sass/tasks/converter/char_string_scanner.rb @@ -0,0 +1,38 @@ +# regular string scanner works with bytes +# this one works with chars and provides #scan_next +class Converter + class CharStringScanner + extend Forwardable + + def initialize(*args) + @s = StringScanner.new(*args) + end + + def_delegators :@s, :scan_until, :skip_until, :string + + # advance scanner to pos after the next match of pattern and return the match + def scan_next(pattern) + return unless @s.scan_until(pattern) + @s.matched + end + + def pos + byte_to_str_pos @s.pos + end + + def pos=(i) + @s.pos = str_to_byte_pos i + i + end + + private + + def byte_to_str_pos(pos) + @s.string.byteslice(0, pos).length + end + + def str_to_byte_pos(pos) + @s.string.slice(0, pos).bytesize + end + end +end \ No newline at end of file