Apply IRC formatting codes to a string, modifying it in place.
 @param [*Array] settings A list of color and formatting attributes you
   want to apply.
 @param [String] string A string you want to format.
 @return [String] A formatted string.
764571
def irc_format!(*settings, string)
      string = string.dup

      attributes = settings.select {|k| @@attributes.has_key?(k)}.map {|k| @@attributes[k]}
      colors = settings.select {|k| @@colors.has_key?(k)}.map {|k| @@colors[k]}
      if colors.size > 2
        raise ArgumentError, "At most two colors (foreground and background) might be specified"
      end

      attribute_string = attributes.join
      color_string = if colors.empty?
                       ""
                     else
                       "\x03#{colors.join(",")}"
                     end

      prepend = attribute_string + color_string
      append = @@attributes[:reset]

      # attributes act as toggles, so e.g. underline+underline = no
      # underline. We thus have to delete all duplicate attributes
      # from nested strings.
      string.delete!(attribute_string)

      # Replace the reset code of nested strings to continue the
      # formattings of the outer string.
      string.gsub!(/#{@@attributes[:reset]}/, @@attributes[:reset] + prepend)
      string.insert(0, prepend)
      string << append
      return string
    end
407450
def string(attr, metadata={})
      add_attribute(attr, :string, metadata)
      define_method("#{attr}=") do |arg|
        instance_variable_set("@#{attr}", arg.nil? ? nil : arg.to_s)
      end
    end
328524
def colorize(str, type)
      str = CGI.escapeHTML(str) if options[:html]
      if options[:plain] || !options[:color][type] || !inspector.colorize?
        str
      #
      # Check if the string color method is defined by awesome_print and accepts
      # html parameter or it has been overriden by some gem such as colorize.
      #
      elsif str.method(options[:color][type]).arity == -1 # Accepts html parameter.
        str.send(options[:color][type], options[:html])
      else
        str = %Q|<kbd style="color:#{options[:color][type]}">#{str}</kbd>| if options[:html]
        str.send(options[:color][type])
      end
    end
87446
def create_string(value)
      if (values = current_attributes[:values]) &&
        (values = values.sort_by {|e| e.to_s})
          value = auto_alias_value(values, value)
          validate_enum_values(values, value)
      end
      value
    end
1206164
def colorize(s, t: nil)
      s = s.to_s
      return s unless colorize_enabled?

      cc = COLOR_CODE
      color = cc[t]
      "#{color}#{s.sub(cc[:esc_m], cc[:esc_m] + color)}#{cc[:esc_m]}"
    end
855744
def call(str)
      # Set string encoding if option is set
      if options[:encoding] && str.respond_to?(:encoding)
        old = str.encoding
        str = str.dup if str.frozen?
        str.force_encoding(options[:encoding])
        # Fall back to old encoding if new encoding is invalid
        str.force_encoding(old_enc) unless str.valid_encoding?
      end

      result = [:multi]
      reset(str.split($/), [result])

      while @lines.first && @lines.first =~ /\A\s*\Z/
        @stacks.last << [:newline]
        next_line 
      end
      if @lines.first and @lines.first =~ /\A<doctype\s+([^>]*)>?/i
        if !$'.empty? and $'[0] !~ /\s*#/
          fail("did not expect content after doctype")
        end
        @stacks.last << [:html, :doctype, $1]
        next_line
      end

      parse_line while next_line

      reset
      result
    end
536248
def encodingStrings( reverse = false )
      @encodingStrings  = [ {"&" => "&amp;" },  {"<" => "&lt;"} , {">" => "&gt;"}, {"'" => "&apos;"}, {"\"" => "&quot;" }  ] if @encodingStrings.nil?
      if block_given?
         if reverse
            @encodingStrings.reverse_each{ |s| s.each{|k,v| yield v,k } }
         else
            @encodingStrings.each{ |s| s.each{|k,v| yield k,v }  }
         end
      else
         @encodingStrings
      end
   end
871644
def key(*keys)
      options = keys.extract_options!
      raise ArgumentError.new("has_settings: Option :defaults expected, but got #{options.keys.join(', ')}") unless options.blank? || (options.keys == [:defaults])
      keys.each do |key_name|
        unless key_name.is_a?(Symbol) || key_name.is_a?(String)
          raise ArgumentError.new("has_settings: symbol or string expected, but got a #{key_name.class}")
        end
      end

      options[:defaults].each do |k, v|
        has_settings(*keys).attr(k, default: v)
      end
    end
214436
def get_color_names(self, format_string):
        
        names = set()
        # Tokenize the format string and process them
        for token in self.tokens(format_string):
            if token.group("command"):
                name = dict(parse_qsl(token.group("command"))).get("color")
                if (
                    not name
                    or name in COLOR_NAMES_EXCLUDED
                    or name in COLOR_NAMES
                    or name[0] == "#"
                ):
                    continue
                names.add(name)
        return names
1080206
public void setString(String string) {
        rawString = string;
        colorIndices.clear();
        // Search for color codes
        final StringBuilder stringBuilder = new StringBuilder(string);
        final Matcher matcher = COLOR_PATTERN.matcher(string);
        int removedCount = 0;
        while (matcher.find()) {
            final int index = matcher.start() - removedCount;
            // Ignore escaped color codes
            if (index > 0 && stringBuilder.charAt(index - 1) == '\\') {
                // Remove the escape character
                stringBuilder.deleteCharAt(index - 1);
                removedCount++;
                continue;
            }
            // Add the color for the index and delete it from the string
            final String colorCode = matcher.group();
            colorIndices.put(index, CausticUtil.fromPackedARGB(Long.decode(colorCode).intValue()));
            final int length = colorCode.length();
            stringBuilder.delete(index, index + length);
            removedCount += length;
        }
        // Color code free string
        this.string = stringBuilder.toString();
    }
202757
def add_setting(header, name, value)
      raise DuplicateSetting if setting_exists?(header, name)

      new_setting = %Q{[#{ header }]\n#{ name } = #{ value }\n}
      write do
        if contents.nil?
          new_setting
        elsif contents.scan(header_regexp(header)).empty?
          contents << "\n\n#{ new_setting }"
        else
          contents.gsub(header_regexp(header), new_setting)
        end
      end
    end
696268
def markup_code(tokens)
            src = ""
            tokens.each do |t|
                next unless t
                #    p t.class
                #        style = STYLE_MAP[t.class]
                style = case t
                when RubyToken::TkCONSTANT then "ruby-constant"
                when RubyToken::TkKW       then "ruby-keyword kw"
                when RubyToken::TkIVAR     then "ruby-ivar"
                when RubyToken::TkOp       then "ruby-operator"
                when RubyToken::TkId       then "ruby-identifier"
                when RubyToken::TkNode     then "ruby-node"
                when RubyToken::TkCOMMENT  then "ruby-comment cmt"
                when RubyToken::TkREGEXP   then "ruby-regexp re"
                when RubyToken::TkSTRING   then "ruby-value str"
                when RubyToken::TkVal      then "ruby-value"
                else
                    nil
                end

                text = CGI.escapeHTML(t.text)

                if style
                    src << "<span class=\"#{style}\">#{text}</span>"
                else
                    src << text
                end
            end

            add_line_numbers(src)
            src
        end
922376
def format_color(text, color, use_color_setting):
    
    if not use_color_setting:
        return text
    else:
        return '{}{}{}'.format(color, text, NORMAL)
498679
def _coloredhelp(s):
    
    newlines = []
    bigindent = (' ' * 16)
    in_opts = False
    for line in s.split('\n'):
        linestripped = line.strip('\n').strip().strip(':')
        if linestripped == 'Usage':
            # label
            line = line.replace('Usage', str(C('Usage', **ARGS_LABEL)))
        elif linestripped == 'Options':
            line = line.replace('Options', str(C('Options', **ARGS_LABEL)))
            in_opts = True
        elif (':' in line) and (not line.startswith(bigindent)):
            # opt,desc line. colorize it.
            lineparts = line.split(':')
            opt = lineparts[0]
            vals = [lineparts[1]] if len(lineparts) == 2 else lineparts[1:]

            # colorize opt
            if ',' in opt:
                opts = opt.split(',')
            else:
                opts = [opt]
            optstr = ','.join(str(C(o, **ARGS_OPTIONS)) for o in opts)

            # colorize desc
            valstr = ':'.join(str(C(val, **ARGS_DESC)) for val in vals)
            line = ':'.join((optstr, valstr))
        elif in_opts and line.startswith(bigindent):
            # continued desc string..
            # Make any 'Default:Value' parts look the same as the opt,desc.

            line = ':'.join(str(C(s, **ARGS_DESC)) for s in line.split(':'))
        elif (not line.startswith('    ')):
            # header line.
            line = str(C(line, **ARGS_HEADER))
        else:
            # Everything else, usage mainly.
            if SCRIPT:
                line = line.replace(SCRIPT, str(C(SCRIPT, **ARGS_SCRIPT)))

        newlines.append(
            '{}{}'.format(line, C('', style='reset_all'))
        )
    return '\n'.join(newlines)
836072
function formatStr(str, values) {
    values = values || {};

    if (typeof str !== 'string') {
        return str;
    }

    return str.replace(FORMAT_REGEXP, (m0, m1, m2) => (m1 === '%' ? "%{" + m2 + "}" : values[m2]));
}
214719
static function updateSettings( $settings )
    {
        unset( $GLOBALS['eZTextCodecInternalCharsetReal'] );
        unset( $GLOBALS['eZTextCodecHTTPCharsetReal'] );
        unset( $GLOBALS['eZTextCodecCharsetCheck'] );
        $GLOBALS['eZTextCodecInternalCharset'] = $settings['internal-charset'];
        $GLOBALS['eZTextCodecHTTPCharset'] = $settings['http-charset'];
        $GLOBALS['eZTextCodecMBStringExtension'] = $settings['mbstring-extension'];
        if ( function_exists( 'mb_internal_encoding' ) )
        {
            @mb_internal_encoding( $settings['internal-charset'] );
        }
    }
297568
def run(string)
      string = string.to_s
      if ltr_characters?(string) && rtl_characters?(string)
        bidi
      elsif ltr_characters?(string)
        ltr
      elsif rtl_characters?(string)
        rtl
      end
    end