Class: Prawn::SVG::CSS::FontParser

Inherits:
Object
  • Object
show all
Defined in:
lib/prawn/svg/css/font_parser.rb

Class Method Summary collapse

Class Method Details

.parse(string) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/prawn/svg/css/font_parser.rb', line 3

def self.parse(string)
  in_quote = nil
  in_escape = false
  in_list_delimiter = false
  current = nil
  values = []

  string.each_char do |char|
    if in_escape
      in_escape = false
      if current.nil?
        current = char
        values << current
      else
        current << char
      end
    elsif char == ',' && in_quote.nil? && !in_escape && current
      current << char
      in_list_delimiter = true
    elsif char == '\\'
      in_escape = true
    elsif current.nil?
      if char.match(/\s/).nil?
        in_list_delimiter = false
        current = char
        values << current
      end
    elsif !in_quote && !in_escape && !in_list_delimiter && char.match(/\s/)
      current = nil
    else
      current << char
    end

    if char == in_quote
      in_quote = nil
    elsif in_quote.nil? && ['"', "'"].include?(char)
      in_quote = char
    end
  end

  values.map(&:rstrip)
end