Tk::EncodedString (Class)

In: tk/lib/tk/encodedstr.rb
Parent: String

Constants

Encoding = nil

Attributes

encoding  [R] 

Public Class methods

[Source]

# File tk/lib/tk/encodedstr.rb, line 68
    def initialize(str, enc = nil)
      super(str)
      @encoding = ( enc || 
                   ((self.class::Encoding)? 
                       self.class::Encoding : Tk.encoding_system) )
    end

[Source]

# File tk/lib/tk/encodedstr.rb, line 60
    def self.new_with_utf_backslash(str, enc = nil)
      self.new('', enc).replace(self.subst_utf_backslash(str))
    end

[Source]

# File tk/lib/tk/encodedstr.rb, line 64
    def self.new_without_utf_backslash(str, enc = nil)
      self.new('', enc).replace(str)
    end

[Source]

# File tk/lib/tk/encodedstr.rb, line 21
    def self.subst_tk_backslash(str)
      TclTkLib._subst_Tcl_backslash(str)
    end

[Source]

# File tk/lib/tk/encodedstr.rb, line 13
    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

[Source]

# File tk/lib/tk/encodedstr.rb, line 38
    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

[Source]

# File tk/lib/tk/encodedstr.rb, line 17
    def self.utf_backslash(str)
      self.subst_utf_backslash(str)
    end

[Source]

# File tk/lib/tk/encodedstr.rb, line 34
    def self.utf_to_backslash(str)
      self.utf_to_backslash_sequence(str)
    end

[Source]

# File tk/lib/tk/encodedstr.rb, line 25
    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

[Validate]