# String (Class)

In: | jcode.rb
Parent: | Object

## Methods

chop chop! delete delete! each_char end_regexp jcount jlength jsize mbchar? squeeze squeeze! succ succ! tr tr! tr_s tr_s!

## Constants

PATTERN_SJIS | = | '[\x81-\x9f\xe0-\xef][\x40-\x7e\x80-\xfc]'
PATTERN_EUC | = | '[\xa1-\xfe][\xa1-\xfe]'
PATTERN_UTF8 | = | '[\xc0-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf][\x80-\xbf]'
RE_SJIS | = | Regexp.new(PATTERN_SJIS, 0, 'n')
RE_EUC | = | Regexp.new(PATTERN_EUC, 0, 'n')
RE_UTF8 | = | Regexp.new(PATTERN_UTF8, 0, 'n')
SUCC | = | {}
HashCache | = | {}
TrPatternCache | = | {}
DeletePatternCache | = | {}
SqueezePatternCache | = | {}

## External Aliases

succ! -> original_succ!
succ -> original_succ

## Public Instance methods

mbchar?()

[Source]

    # File jcode.rb, line 46
      def mbchar?
        case $KCODE[0]
        when ?s, ?S
          self =~ RE_SJIS
        when ?e, ?E
          self =~ RE_EUC
        when ?u, ?U
          self =~ RE_UTF8
        else
          nil
        end
      end

end_regexp()

[Source]

    # File jcode.rb, line 59
      def end_regexp
        case $KCODE[0]
        when ?s, ?S
          /#{PATTERN_SJIS}$/on
        when ?e, ?E
          /#{PATTERN_EUC}$/on
        when ?u, ?U
          /#{PATTERN_UTF8}$/on
        else
          /.$/on
        end
      end

succ!()

[Source]

    # File jcode.rb, line 78
      def succ!
        reg = end_regexp
        if self =~ reg
          succ_table = SUCC[$KCODE[0,1].downcase]
          begin
            self[-1] += succ_table[self[-1]]
            self[-2] += 1 if self[-1] == 0
          end while self !~ reg
          self
        else
          original_succ!
        end
      end

succ()

[Source]

    # File jcode.rb, line 92
      def succ
        (str = self.dup).succ! or str
      end

tr!(from, to)

[Source]

    # File jcode.rb, line 132
      def tr!(from, to)
        return nil if from == ""
        return self.delete!(from) if to == ""

        pattern = TrPatternCache[from] ||= /[#{_regex_quote(from)}]/
        if from[0] == ?^
          last = /.$/.match(to)[0]
          self.gsub!(pattern, last)
        else
          h = HashCache[from + "1-0" + to] ||= expand_ch_hash(from, to)
          self.gsub!(pattern) do |c| h[c] end
        end
      end

tr(from, to)

[Source]

    # File jcode.rb, line 146
      def tr(from, to)
        (str = self.dup).tr!(from, to) or str
      end

delete!(del)

[Source]

    # File jcode.rb, line 150
      def delete!(del)
        return nil if del == ""
        self.gsub!(DeletePatternCache[del] ||= /[#{_regex_quote(del)}]+/, '')
      end

delete(del)

[Source]

    # File jcode.rb, line 155
      def delete(del)
        (str = self.dup).delete!(del) or str
      end

squeeze!(del=nil)

[Source]

    # File jcode.rb, line 159
      def squeeze!(del=nil)
        return nil if del == ""
        pattern =
          if del
            SqueezePatternCache[del] ||= /([#{_regex_quote(del)}])\1+/
          else
            /(.|\n)\1+/
          end
        self.gsub!(pattern, '\1')
      end

squeeze(del=nil)

[Source]

    # File jcode.rb, line 170
      def squeeze(del=nil)
        (str = self.dup).squeeze!(del) or str
      end

tr_s!(from, to)

[Source]

    # File jcode.rb, line 174
      def tr_s!(from, to)
        return self.delete!(from) if to.length == 0

        pattern = SqueezePatternCache[from] ||= /([#{_regex_quote(from)}])\1+/
        if from[0] == ?^
          last = /.$/.match(to)[0]
          self.gsub!(pattern, last)
        else
          h = HashCache[from + "1-0" + to] ||= expand_ch_hash(from, to)
          self.gsub!(pattern) do h[$1] end
        end
      end

tr_s(from, to)

[Source]

    # File jcode.rb, line 187
      def tr_s(from, to)
        (str = self.dup).tr_s!(from,to) or str
      end

chop!()

[Source]

    # File jcode.rb, line 191
      def chop!
        self.gsub!(/(?:.|\r?\n)\z/, '')
      end

chop()

[Source]

    # File jcode.rb, line 195
      def chop
        (str = self.dup).chop! or str
      end

jlength()

[Source]

    # File jcode.rb, line 199
      def jlength
        self.gsub(/[^\Wa-zA-Z_\d]/, ' ').length
      end

jsize()

Alias for jlength

jcount(str)

[Source]

    # File jcode.rb, line 204
      def jcount(str)
        self.delete("^#{str}").jlength
      end

each_char() {|x| ...}

[Source]

    # File jcode.rb, line 208
      def each_char
        if block_given?
          scan(/./m) do |x|
            yield x
          end
        else
          scan(/./m)
        end
      end

[Validate]