source/Emoji/gemoji-parser/lib/gemoji-parser.rb
# Generates a macro regex for matching one or more symbol sets.
# Regex uses various formats, based on symbol sets. Yields match as $1 OR $2
# T/EU:        (token-$1)|(emoticon-unicode-$2)
# T/E or T/U:  (token-$1)|(emoticon/unicode-$2)
# EU:          (emoticon/unicode-$1)
# - Options: unicode:boolean, tokens:boolean, emoticons:boolean
Generates a macro regex for matching one or more symbol sets.
Regex uses various formats, based on symbol sets.
Generates a macro regex for matching one or more symbol sets . Regex uses various formats based on symbol sets .
def macro_regex(opts={})
    opts = { unicode: true, tokens: true, emoticons: true }.merge(opts)
    unicode_regex if opts[:unicode]
    token_regex if opts[:tokens]
    emoticon_regex if opts[:emoticons]
    pattern = []
    if opts[:emoticons] && opts[:unicode]
      pattern << "(?:#{ @emoticon_pattern })"
      pattern << @unicode_pattern
    else
      pattern << @emoticon_pattern if opts[:emoticons]
      pattern << @unicode_pattern if opts[:unicode]
    end
    pattern = pattern.any? ? "(#{ pattern.join('|') })" : ""
    if opts[:tokens]
      if pattern.empty?
        pattern = @token_pattern
      else
        pattern = "(?:#{ @token_pattern })|#{ pattern }"
      end
    end
    Regexp.new(pattern)
  end
def macro_regex ( opts = { } ) opts = { unicode : true , tokens : true , emoticons : true } . merge ( opts ) unicode_regex if opts [ :unicode ] token_regex if opts [ :tokens ] emoticon_regex if opts [ :emoticons ] pattern = [ ] if opts [ :emoticons ] && opts [ :unicode ] pattern << "(?:#{ @emoticon_pattern })" pattern << @unicode_pattern else pattern << @emoticon_pattern if opts [ :emoticons ] pattern << @unicode_pattern if opts [ :unicode ] end pattern = pattern . any? ? "(#{ pattern.join('|') })" : "" if opts [ :tokens ] if pattern . empty? pattern = @token_pattern else pattern = "(?:#{ @token_pattern })|#{ pattern }" end end Regexp . new ( pattern ) end
Generates a macro regex for matching one or more symbol sets.
Generates a macro regex for matching one or more symbol sets .
opts