Sha256: 073682b59b90db93f63cb3920183da655eefab802cd8a15d66d210e62e12e63e

Contents?: true

Size: 949 Bytes

Versions: 22

Compression:

Stored size: 949 Bytes

Contents

# frozen_string_literal: true
module Mail::Parsers
  class PhraseListsParser

    def parse(s)
      raise Mail::Field::ParseError.new(Mail::PhraseList, s, 'nil is invalid') if s.nil?

      actions, error = Ragel.parse(:phrase_lists, s)
      if error
        raise Mail::Field::ParseError.new(Mail::PhraseList, s, error)
      end

      phrase_lists = PhraseListsStruct.new([])

      phrase_s = nil
      actions.each_slice(2) do |action_id, p|
        action = Mail::Parsers::Ragel::ACTIONS[action_id]
        case action

        # Phrase
        when :phrase_s then phrase_s = p
        when :phrase_e
          phrase_lists.phrases << s[phrase_s..(p-1)] if phrase_s
          phrase_s = nil

        when :comment_e, :comment_s, :qstr_s, :qstr_e then nil

        else
          raise Mail::Field::ParseError.new(Mail::PhraseList, s, "Failed to process unknown action: #{action}")
        end
      end

      phrase_lists
    end
  end
end

Version data entries

22 entries across 20 versions & 6 rubygems

Version Path
tdiary-5.0.6 vendor/bundle/gems/mail-2.6.6/lib/mail/parsers/phrase_lists_parser.rb
tdiary-5.0.5 vendor/bundle/gems/mail-2.6.4/lib/mail/parsers/phrase_lists_parser.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/mail-2.6.4/lib/mail/parsers/phrase_lists_parser.rb
tdiary-5.0.5 vendor/bundle/gems/mail-2.6.6/lib/mail/parsers/phrase_lists_parser.rb
mail-2.6.6 lib/mail/parsers/phrase_lists_parser.rb
mail-2.6.6.rc1 lib/mail/parsers/phrase_lists_parser.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/mail-2.6.5/lib/mail/parsers/phrase_lists_parser.rb
mail-2.6.5 lib/mail/parsers/phrase_lists_parser.rb
mail-2.6.5.rc1 lib/mail/parsers/phrase_lists_parser.rb
tdiary-5.0.4 vendor/bundle/gems/mail-2.6.4/lib/mail/parsers/phrase_lists_parser.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/parsers/phrase_lists_parser.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/parsers/phrase_lists_parser.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/parsers/phrase_lists_parser.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/parsers/phrase_lists_parser.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/parsers/phrase_lists_parser.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/parsers/phrase_lists_parser.rb
autocompl-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/parsers/phrase_lists_parser.rb
abaci-0.3.0 vendor/bundle/gems/mail-2.6.4/lib/mail/parsers/phrase_lists_parser.rb
tdiary-5.0.2 vendor/bundle/gems/mail-2.6.4/lib/mail/parsers/phrase_lists_parser.rb
tdiary-5.0.1 vendor/bundle/gems/mail-2.6.4/lib/mail/parsers/phrase_lists_parser.rb