### Home Classes Methods

### In Files

- lib/sass/util/multibyte_string_scanner.rb

### Parent

DelegateClass(StringScanner)

### Methods

- ::new
- ::new
- #byte_matched_size
- #byte_pos
- #check
- #check_until
- #clear
- #get_byte
- #getbyte
- #getch
- #is_a?
- #match?
- #matched_size
- #peek
- #peep
- #pointer
- #pos
- #pos=
- #reset
- #rest_size
- #scan
- #scan_full
- #scan_until
- #search_full
- #skip
- #skip_until
- #string=
- #terminate
- #unscan

### Class/Module Index

Quicksearch

- Sass
- Sass::BaseEnvironment
- Sass::CSS
- Sass::CacheStores
- Sass::CacheStores::Base
- Sass::CacheStores::Chain
- Sass::CacheStores::Filesystem
- Sass::CacheStores::Memory
- Sass::CacheStores::Null
- Sass::Callbacks
- Sass::Callbacks::InstanceMethods
- Sass::Engine
- Sass::Engine::Line
- Sass::Environment
- Sass::Exec
- Sass::Exec::Base
- Sass::Exec::SassConvert
- Sass::Exec::SassScss
- Sass::Exec::SassScss::Sass::Plugin.compiler
- Sass::Features
- Sass::Importers
- Sass::Importers::Base
- Sass::Importers::Filesystem
- Sass::Logger
- Sass::Logger::Base
- Sass::Logger::LogLevel
- Sass::Logger::LogLevel::ClassMethods
- Sass::Media
- Sass::Media::Query
- Sass::Media::QueryList
- Sass::Plugin
- Sass::Plugin::Compiler
- Sass::Plugin::Configuration
- Sass::Plugin::MerbBootLoader
- Sass::Plugin::Rack
- Sass::Plugin::StalenessChecker
- Sass::ReadOnlyEnvironment
- Sass::Repl
- Sass::SCSS
- Sass::SCSS::CssParser
- Sass::SCSS::Parser
- Sass::SCSS::RX
- Sass::SCSS::ScriptLexer
- Sass::SCSS::ScriptParser
- Sass::SCSS::StaticParser
- Sass::Script
- Sass::Script::CssLexer
- Sass::Script::CssParser
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::Lexer
- Sass::Script::Parser
- Sass::Script::Tree
- Sass::Script::Tree::Funcall
- Sass::Script::Tree::Interpolation
- Sass::Script::Tree::ListLiteral
- Sass::Script::Tree::Literal
- Sass::Script::Tree::MapLiteral
- Sass::Script::Tree::Node
- Sass::Script::Tree::Operation
- Sass::Script::Tree::Selector
- Sass::Script::Tree::StringInterpolation
- Sass::Script::Tree::UnaryOperation
- Sass::Script::Tree::Variable
- Sass::Script::Value
- Sass::Script::Value::ArgList
- Sass::Script::Value::Base
- Sass::Script::Value::Bool
- Sass::Script::Value::Color
- Sass::Script::Value::Helpers
- Sass::Script::Value::List
- Sass::Script::Value::Map
- Sass::Script::Value::Null
- Sass::Script::Value::Number
- Sass::Script::Value::String
- Sass::Selector
- Sass::Selector::AbstractSequence
- Sass::Selector::Attribute
- Sass::Selector::Class
- Sass::Selector::CommaSequence
- Sass::Selector::Element
- Sass::Selector::Id
- Sass::Selector::Parent
- Sass::Selector::Placeholder
- Sass::Selector::Pseudo
- Sass::Selector::Sequence
- Sass::Selector::Simple
- Sass::Selector::SimpleSequence
- Sass::Selector::Universal
- Sass::SemiGlobalEnvironment
- Sass::Shared
- Sass::Source
- Sass::Source::Map
- Sass::Source::Map::Mapping
- Sass::Source::Position
- Sass::Source::Range
- Sass::Stack
- Sass::Stack::Frame
- Sass::Supports
- Sass::Supports::Condition
- Sass::Supports::Declaration
- Sass::Supports::Interpolation
- Sass::Supports::Negation
- Sass::Supports::Operator
- Sass::SyntaxError
- Sass::Tree
- Sass::Tree::AtRootNode
- Sass::Tree::CharsetNode
- Sass::Tree::CommentNode
- Sass::Tree::ContentNode
- Sass::Tree::CssImportNode
- Sass::Tree::DebugNode
- Sass::Tree::DirectiveNode
- Sass::Tree::EachNode
- Sass::Tree::ErrorNode
- Sass::Tree::ExtendNode
- Sass::Tree::ForNode
- Sass::Tree::FunctionNode
- Sass::Tree::IfNode
- Sass::Tree::ImportNode
- Sass::Tree::KeyframeRuleNode
- Sass::Tree::MediaNode
- Sass::Tree::MixinDefNode
- Sass::Tree::MixinNode
- Sass::Tree::Node
- Sass::Tree::PropNode
- Sass::Tree::ReturnNode
- Sass::Tree::RootNode
- Sass::Tree::RuleNode
- Sass::Tree::SupportsNode
- Sass::Tree::TraceNode
- Sass::Tree::VariableNode
- Sass::Tree::Visitors
- Sass::Tree::Visitors::Base
- Sass::Tree::Visitors::CheckNesting
- Sass::Tree::Visitors::Convert
- Sass::Tree::Visitors::Cssize
- Sass::Tree::Visitors::Cssize::Bubble
- Sass::Tree::Visitors::DeepCopy
- Sass::Tree::Visitors::Extend
- Sass::Tree::Visitors::Perform
- Sass::Tree::Visitors::SetOptions
- Sass::Tree::Visitors::ToCss
- Sass::Tree::WarnNode
- Sass::Tree::WhileNode
- Sass::UnitConversionError
- Sass::Util
- Sass::Util::CrossPlatformRandom
- Sass::Util::MultibyteStringScanner
- Sass::Util::NormalizedMap
- Sass::Util::StaticConditionalContext
- Sass::Util::SubsetMap
- Sass::Util::Test
- Sass::Version
- ActionController
- ActionController::Base
- Object
- OrderedHash

No matching classes.

# Sass::Util::MultibyteStringScanner

A wrapper of the native StringScanner class that works correctly with multibyte character encodings. The native class deals only in bytes, not characters, for methods like [pos] and [matched_size]. This class deals only in characters, instead.

### Public Class Methods

new(str) click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 14
    def initialize(str)
      super(StringScanner.new(str))
      @mb_pos = 0
      @mb_matched_size = nil
      @mb_last_pos = nil
    end

new(str) click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 41
    def self.new(str)
      return StringScanner.new(str) if str.ascii_only?
      super
    end

### Public Instance Methods

byte_matched_size() click to toggle source
Alias for: matched_size
byte_pos() click to toggle source
Alias for: pos
check(pattern) click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 49
    def check(pattern); _match super; end

check_until(pattern) click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 50
    def check_until(pattern); _matched super; end

clear() click to toggle source
Alias for: terminate
get_byte() click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 64
    def get_byte
      raise "MultibyteStringScanner doesn't support #get_byte."
    end

getbyte() click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 68
    def getbyte
      raise "MultibyteStringScanner doesn't support #getbyte."
    end

getch() click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 51
    def getch; _forward _match super; end

is_a?(klass) click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 21
    def is_a?(klass)
      __getobj__.is_a?(klass) || super
    end

match?(pattern) click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 52
    def match?(pattern); _size check(pattern); end

matched_size() click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 53
    def matched_size; @mb_matched_size; end

Also aliased as: byte_matched_size
peek(len) click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 54
    def peek(len); string[@mb_pos, len]; end

Also aliased as: peep
peep(len) click to toggle source
Alias for: peek
pointer() click to toggle source
Alias for: pos
pos() click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 56
    def pos; @mb_pos; end

Also aliased as: byte_pos, pointer
pos=(n) click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 72
    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

reset() click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 95
    def reset
      @mb_pos = 0
      @mb_matched_size = nil
      @mb_last_pos = nil
      super
    end

rest_size() click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 58
    def rest_size; rest.size; end

scan(pattern) click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 59
    def scan(pattern); _forward _match super; end

scan_full(pattern, advance_pointer_p, return_string_p) click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 102
    def scan_full(pattern, advance_pointer_p, return_string_p)
      res = _match super(pattern, advance_pointer_p, true)
      _forward res if advance_pointer_p
      return res if return_string_p
    end

scan_until(pattern) click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 60
    def scan_until(pattern); _forward _matched super; end

search_full(pattern, advance_pointer_p, return_string_p) click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 108
    def search_full(pattern, advance_pointer_p, return_string_p)
      res = super(pattern, advance_pointer_p, true)
      _forward res if advance_pointer_p
      _matched((res if return_string_p))
    end

skip(pattern) click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 61
    def skip(pattern); _size scan(pattern); end

skip_until(pattern) click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 62
    def skip_until(pattern); _matched _size scan_until(pattern); end

string=(str) click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 114
    def string=(str)
      @mb_pos = 0
      @mb_matched_size = nil
      @mb_last_pos = nil
      super
    end

terminate() click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 121
    def terminate
      @mb_pos = string.size
      @mb_matched_size = nil
      @mb_last_pos = nil
      super
    end

Also aliased as: clear
unscan() click to toggle source

    # File lib/sass/util/multibyte_string_scanner.rb, line 129
    def unscan
      super
      @mb_pos = @mb_last_pos
      @mb_last_pos = @mb_matched_size = nil
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.