In Files

  • tk/lib/tk/encodedstr.rb

Class/Module Index [+]

Quicksearch

Tk::EncodedString

Constants

Encoding

Public Class Methods

new(str, enc = nil) click to toggle source
 
               # File tk/lib/tk/encodedstr.rb, line 69
def initialize(str, enc = nil)
  super(str)
  # @encoding = ( enc ||
  #              ((self.class::Encoding)?
  #                  self.class::Encoding : Tk.encoding_system) )
  enc ||= (self.class::Encoding)?
                     self.class::Encoding :
                     ((Tk.encoding)? Tk.encoding : Tk.encoding_system)
  if TkCore::WITH_ENCODING
    unless encobj = Tk::Encoding::ENCODING_TABLE.get_obj(enc)
      fail ArgumentError, "unsupported Tk encoding '#{enc}'"
    end
    self.force_encoding(encobj)
  else
    @encoding = enc
  end
end
            
new_with_utf_backslash(str, enc = nil) click to toggle source
 
               # File tk/lib/tk/encodedstr.rb, line 61
def self.new_with_utf_backslash(str, enc = nil)
  self.new('', enc).replace(self.subst_utf_backslash(str))
end
            
new_without_utf_backslash(str, enc = nil) click to toggle source
 
               # File tk/lib/tk/encodedstr.rb, line 65
def self.new_without_utf_backslash(str, enc = nil)
  self.new('', enc).replace(str)
end
            
subst_tk_backslash(str) click to toggle source
 
               # File tk/lib/tk/encodedstr.rb, line 22
def self.subst_tk_backslash(str)
  TclTkLib._subst_Tcl_backslash(str)
end
            
subst_utf_backslash(str) click to toggle source
 
               # File tk/lib/tk/encodedstr.rb, line 14
def self.subst_utf_backslash(str)
  # str.gsub(/\\u([0-9A-Fa-f]{1,4})/){[$1.hex].pack('U')}
  TclTkLib._subst_UTF_backslash(str)
end
            
to_backslash_sequence(str) click to toggle source
 
               # File tk/lib/tk/encodedstr.rb, line 39
def self.to_backslash_sequence(str)
  str.unpack('U*').collect{|c|
    if c <= 0x1F  # control character
      case c
      when 0x07; '\a'
      when 0x08; '\b'
      when 0x09; '\t'
      when 0x0a; '\n'
      when 0x0b; '\v'
      when 0x0c; '\f'
      when 0x0d; '\r'
      else
        format('\x%02X', c)
      end
    elsif c <= 0xFF  # ascii character
      c.chr
    else
      format('\u%X', c)
    end
  }.join('')
end
            
utf_backslash(str) click to toggle source
 
               # File tk/lib/tk/encodedstr.rb, line 18
def self.utf_backslash(str)
  self.subst_utf_backslash(str)
end
            
utf_to_backslash(str) click to toggle source
 
               # File tk/lib/tk/encodedstr.rb, line 35
def self.utf_to_backslash(str)
  self.utf_to_backslash_sequence(str)
end
            
utf_to_backslash_sequence(str) click to toggle source
 
               # File tk/lib/tk/encodedstr.rb, line 26
def self.utf_to_backslash_sequence(str)
  str.unpack('U*').collect{|c|
    if c <= 0xFF  # ascii character
      c.chr
    else
      format('\u%X', c)
    end
  }.join('')
end
            

Public Instance Methods

__encoding() click to toggle source
Alias for: encoding
__instance_eval(*args, &b) click to toggle source
Alias for: instance_eval
__instance_variable_get(key) click to toggle source

wrapper methods for compatibility

__instance_variable_set(key, value) click to toggle source
__instance_variables() click to toggle source
Alias for: instance_variables
encoding() click to toggle source
 
               # File tk/lib/tk/encodedstr.rb, line 90
def encoding
  Tk::Encoding::ENCODING_TABLE.get_name(super())
end
            
Also aliased as: encoding_obj, __encoding, encoding_obj
encoding_obj() click to toggle source
Alias for: encoding
instance_eval(*args, &b) click to toggle source
 
               # File tk/lib/tk/encodedstr.rb, line 128
def instance_eval(*args, &b)
  old_enc = @encoding = self.encoding

  ret = super(*args, &b)

  if @encoding
    if @encoding != old_enc
      # modified by user
      self.force_encoding(@encoding)
    end
    remove_instance_variable(:@encoding)
  else
    begin
      remove_instance_variable(:@encoding)
      # user sets to nil -> use current default
      self.force_encoding(Tk.encoding)
    rescue NameError
      # removed by user -> ignore, because user don't use @encoding
    end
  end
  ret
end
            
Also aliased as: __instance_eval
instance_variable_get(key) click to toggle source
 
               # File tk/lib/tk/encodedstr.rb, line 107
def instance_variable_get(key)
  if (key.to_s == '@encoding')
    self.encoding
  else
    super(key)
  end
end
            
Also aliased as: __instance_variable_get
instance_variable_set(key, value) click to toggle source
 
               # File tk/lib/tk/encodedstr.rb, line 115
def instance_variable_set(key, value)
  if (key.to_s == '@encoding')
    if value
      self.force_encoding(value)
    else
      self.force_encoding(Tk::Encoding::UNKNOWN)
    end
    value
  else
    super(key, value)
  end
end
            
Also aliased as: __instance_variable_set
instance_variables() click to toggle source
 
               # File tk/lib/tk/encodedstr.rb, line 152
def instance_variables
  ret = super()
  ret << :@encoding  # fake !!
  ret
end
            
Also aliased as: __instance_variables

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.