module Rdoba::Mixin::CaseString

Constants

Aliases
ConvertTable
Fixups

Public Class Methods

change_case_char(dest, char) click to toggle source
# File lib/rdoba/mixin.rb, line 140
def self.change_case_char dest, char
   ord = char.is_a?( String ) ? char.ord : char.to_i
   table = ConvertTable[ dest ]
   nord = table[ :ranges ].each do |range|
      c = range[ :ords ].each do |r|
         if r.include?( ord )
            break false ; end ; end
      if !c
         break range[ :change ].call ord ; end ; end

   if !nord.is_a? Numeric
      return table[ :default ].call ord ; end

   [ nord ].pack( 'U' ) ; end
downcase_char(char) click to toggle source
# File lib/rdoba/mixin.rb, line 158
def self.downcase_char char
   CaseString.change_case_char :down, char ; end
up_char(char) click to toggle source
# File lib/rdoba/mixin.rb, line 155
def self.up_char char
   CaseString.change_case_char :up, char ; end

Public Instance Methods

__rdoba_mixin_changecase__(reg, options = {}) click to toggle source
# File lib/rdoba/mixin.rb, line 189
def __rdoba_mixin_changecase__ reg, options = {}
   if ![ :up, :down ].include? reg
      return self ; end

   re = Regexp.new '[\x80-\xFF]', nil, 'n'
   if options == String::FirstChar || options.include?( :first_char )
      r = self.dup
      r[0] = CaseString.change_case_char reg, self.ord
      r
   elsif self.dup.force_encoding( 'ASCII-8BIT' ).match re
      self.unpack('U*').map do | chr |
         CaseString.change_case_char reg, chr
      end.join
   elsif reg == :up
      self.__rdoba_mixin_upcase_orig__
   else
      self.__rdoba_mixin_downcase_orig__ ; end ; end
__rdoba_mixin_downcase__(options = {}) click to toggle source
# File lib/rdoba/mixin.rb, line 183
def __rdoba_mixin_downcase__ options = {}
   self.__rdoba_mixin_changecase__ :down, options ; end
__rdoba_mixin_upcase__(options = {}) click to toggle source
# File lib/rdoba/mixin.rb, line 186
def __rdoba_mixin_upcase__ options = {}
   self.__rdoba_mixin_changecase__ :up, options ; end
encoding() click to toggle source
# File lib/rdoba/mixin.rb, line 164
def encoding
   'UTF-8'
end
force_encoding(*args) click to toggle source
# File lib/rdoba/mixin.rb, line 168
def force_encoding(*args)
   self
end
ord() click to toggle source
# File lib/rdoba/mixin.rb, line 172
def ord
   a = nil
   self.each_byte do |b|
      case ( b & 0xC0 )
      when 0xc0
         a = (b & 0x3F)
      when 0x80
         return (a << 6) + (b & 0x3F)
      else
         return b ; end ; end ; end