Module: Sashite::Cell::Parser Private
- Defined in:
- lib/sashite/cell/parser.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Parses CELL coordinate strings into index arrays.
This module handles the conversion from CELL string representation to numeric indices, following the cyclic pattern:
-
Dimension 1, 4, 7…: lowercase letters (a-z, aa-iv)
-
Dimension 2, 5, 8…: positive integers (1-256)
-
Dimension 3, 6, 9…: uppercase letters (A-Z, AA-IV)
Security considerations:
-
Character-by-character parsing (no regex, no ReDoS risk)
-
Fail-fast on invalid input
-
Bounded iteration (max 7 characters)
-
Explicit ASCII validation
Class Method Summary collapse
-
.parse_to_indices(string) ⇒ Array<Integer>
private
Parses a CELL string into an array of indices.
Class Method Details
.parse_to_indices(string) ⇒ Array<Integer>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parses a CELL string into an array of indices.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/sashite/cell/parser.rb', line 37 def self.parse_to_indices(string) raise Errors::Argument, Errors::Argument::Messages::EMPTY_INPUT if string.empty? if string.length > Constants::MAX_STRING_LENGTH raise Errors::Argument, Errors::Argument::Messages::INPUT_TOO_LONG end first_byte = string.getbyte(0) unless lowercase?(first_byte) raise Errors::Argument, Errors::Argument::Messages::INVALID_START end indices = [] pos = 0 dimension_type = 0 # 0: lowercase, 1: integer, 2: uppercase while pos < string.length if indices.size >= Constants::MAX_DIMENSIONS raise Errors::Argument, Errors::Argument::Messages::TOO_MANY_DIMENSIONS end case dimension_type when 0 value, consumed = parse_lowercase(string, pos) indices << value pos += consumed dimension_type = 1 when 1 value, consumed = parse_integer(string, pos) indices << value pos += consumed dimension_type = 2 when 2 value, consumed = parse_uppercase(string, pos) indices << value pos += consumed dimension_type = 0 end end indices end |