Class: Gammo::Tokenizer::EscapedToken
- Includes:
- Escape
- Defined in:
- lib/gammo/tokenizer/tokens.rb
Constant Summary collapse
- NULL =
?\x00.freeze
- REPLACEMENT =
"\ufffd".freeze
Constants included from Escape
Gammo::Tokenizer::Escape::ESCAPE_REPLACEMENT_TABLE, Gammo::Tokenizer::Escape::LONGEST_ENTITY_WITHOUT_SEMICOLON, Gammo::Tokenizer::Escape::REPLACEMENT_TABLE
Instance Attribute Summary collapse
-
#convert_null ⇒ Object
(also: #convert_null?)
Returns the value of attribute convert_null.
-
#raw ⇒ Object
(also: #require_raw_data?)
Returns the value of attribute raw.
Attributes inherited from BaseToken
Instance Method Summary collapse
-
#initialize(data = nil, raw: false, convert_null: false, **options) ⇒ EscapedToken
constructor
A new instance of EscapedToken.
- #load_data(raw_data) ⇒ Object
Methods included from Escape
Methods inherited from BaseToken
Constructor Details
#initialize(data = nil, raw: false, convert_null: false, **options) ⇒ EscapedToken
Returns a new instance of EscapedToken.
36 37 38 39 40 41 |
# File 'lib/gammo/tokenizer/tokens.rb', line 36 def initialize(data = nil, raw: false, convert_null: false, **) super(data, **) @raw = raw @convert_null = convert_null load_data(data) end |
Instance Attribute Details
#convert_null ⇒ Object Also known as: convert_null?
Returns the value of attribute convert_null.
34 35 36 |
# File 'lib/gammo/tokenizer/tokens.rb', line 34 def convert_null @convert_null end |
#raw ⇒ Object Also known as: require_raw_data?
Returns the value of attribute raw.
34 35 36 |
# File 'lib/gammo/tokenizer/tokens.rb', line 34 def raw @raw end |
Instance Method Details
#load_data(raw_data) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/gammo/tokenizer/tokens.rb', line 43 def load_data(raw_data) unless raw_data @data = nil return end raw_data = convert_newlines(raw_data).force_encoding(Encoding::UTF_8) raw_data = raw_data.gsub(%r{#{NULL}}, REPLACEMENT) if should_convert_null?(raw_data) @data = require_raw_data? ? raw_data : unescape(raw_data, in_attribute: false) end |