build_rule_index

in lib/twitter_cldr/transforms/conversion_rule_set.rb [131:160]


      def build_rule_index(rules)
        TwitterCldr::Utils::Trie.new.tap do |trie|
          rules.each_with_index do |rule, idx|
            next unless rule.forward?

            if rule.has_codepoints?
              codepoints = rule.codepoints

              if codepoints.size > 0
                rule.codepoints.each do |codepoint|
                  bytes = codepoint.chr('UTF-8').bytes

                  if entry = trie.get(bytes)
                    entry << rule
                  else
                    trie.add(bytes, [rule])
                  end
                end
              end
            else
              if entry = trie.get([0])
                entry << rule
              else
                trie.add([0], [rule])
              end
            end
          end
        end
      end