Module: Tk::Encoding

Extended by:
Encoding
Included in:
Tk, Encoding
Defined in:
lib/tk.rb,
lib/tk.rb

Constant Summary collapse

TkCommandNames =
['encoding'.freeze].freeze
RubyEncoding =
::Encoding
BINARY_NAME =

for saving GC cost ENCNAMES_CMD = [‘encoding’.freeze, ‘names’.freeze]

'binary'.freeze
UTF8_NAME =
'utf-8'.freeze
DEFAULT_EXTERNAL_NAME =
RubyEncoding.default_external.name.freeze
DEFAULT_INTERNAL_NAME =
RubyEncoding.default_internal.name.freeze rescue nil
BINARY =
RubyEncoding.find(BINARY_NAME)
UNKNOWN =
RubyEncoding.find('ASCII-8BIT')
ENCODING_TABLE =

start of creating ENCODING_TABLE

TkCore::INTERP.encoding_table

Instance Method Summary collapse

Instance Method Details

#default_encoding=(enc) ⇒ Object



2722
2723
2724
# File 'lib/tk.rb', line 2722

def default_encoding=(enc)
  TkCore::INTERP.default_encoding = Tk::Encoding::ENCODING_TABLE.get_name(enc)
end

#encoding=(name) ⇒ Object



2726
2727
2728
# File 'lib/tk.rb', line 2726

def encoding=(enc)
  TkCore::INTERP.encoding = Tk::Encoding::ENCODING_TABLE.get_name(enc)
end

#encoding_convertfrom(str, enc = None) ⇒ Object Also known as: encoding_convert_from



2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
# File 'lib/tk.rb', line 2821

def encoding_convertfrom(str, enc=nil)
  enc = encoding_system_name unless enc
  str = str.dup
  if TkCore::WITH_ENCODING
    if str.kind_of?(Tk::EncodedString)
      str.__instance_variable_set('@encoding', nil)
    else
      str.instance_variable_set('@encoding', nil)
    end
    str.force_encoding('binary')
  else
    str.instance_variable_set('@encoding', 'binary')
  end
  ret = TkCore::INTERP._invoke_without_enc('encoding', 'convertfrom',
                                           enc, str)
  if TkCore::WITH_ENCODING
    ret.force_encoding('utf-8')
  else
    Tk::UTF8_String.new(ret)
  end
  ret
end

#encoding_convertto(str, enc = None) ⇒ Object Also known as: encoding_convert_to



2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
# File 'lib/tk.rb', line 2845

def encoding_convertto(str, enc=nil)
  # str must be a UTF-8 string
  enc = encoding_system_name unless enc
  ret = TkCore::INTERP._invoke_without_enc('encoding', 'convertto',
                                           enc, str)
  #ret.instance_variable_set('@encoding', 'binary')
  if TkCore::WITH_ENCODING
    #ret.force_encoding(Tk::Encoding::ENCODING_TABLE.get_obj('binary'))
    ret.force_encoding(Tk::Encoding::ENCODING_TABLE.get_obj(enc))
  end
  ret
end

#encoding_dirsObject



2859
2860
2861
2862
# File 'lib/tk.rb', line 2859

def encoding_dirs
  # Tcl8.5 feature
  TkComm.simplelist(Tk.tk_call_without_enc('encoding', 'dirs'))
end

#encoding_dirs=(dir_array) ⇒ Object

an array or a Tcl’s list string



2864
2865
2866
2867
# File 'lib/tk.rb', line 2864

def encoding_dirs=(dir_list) # an array or a Tcl's list string
  # Tcl8.5 feature
  Tk.tk_call_without_enc('encoding', 'dirs', dir_list)
end

#encoding_nameObject Also known as: encoding, default_encoding



2730
2731
2732
# File 'lib/tk.rb', line 2730

def encoding_name
  Tk::Encoding::ENCODING_TABLE.get_name(TkCore::INTERP.encoding)
end

#encoding_namesObject



2743
2744
2745
2746
2747
# File 'lib/tk.rb', line 2743

def encoding_names
  self.tk_encoding_names.find_all{|name|
    Tk::Encoding::ENCODING_TABLE.get_name(name) rescue false
  }
end

#encoding_objObject



2733
2734
2735
# File 'lib/tk.rb', line 2733

def encoding_obj
  Tk::Encoding::ENCODING_TABLE.get_obj(TkCore::INTERP.encoding)
end

#encoding_objsObject



2748
2749
2750
2751
2752
# File 'lib/tk.rb', line 2748

def encoding_objs
  self.tk_encoding_names.map!{|name|
    Tk::Encoding::ENCODING_TABLE.get_obj(name) rescue nil
  }.compact
end

#encoding_system=(enc) ⇒ Object



2754
2755
2756
# File 'lib/tk.rb', line 2754

def encoding_system=(enc)
  TclTkLib.encoding_system = Tk::Encoding::ENCODING_TABLE.get_name(enc)
end

#encoding_system_nameObject Also known as: encoding_system



2758
2759
2760
# File 'lib/tk.rb', line 2758

def encoding_system_name
  Tk::Encoding::ENCODING_TABLE.get_name(TclTkLib.encoding_system)
end

#encoding_system_objObject



2761
2762
2763
# File 'lib/tk.rb', line 2761

def encoding_system_obj
  Tk::Encoding::ENCODING_TABLE.get_obj(TclTkLib.encoding_system)
end

#force_default_encoding(mode) ⇒ Object

Ruby 1.9



2714
2715
2716
# File 'lib/tk.rb', line 2714

def force_default_encoding(mode)
  TkCore::INTERP.force_default_encoding = mode
end

#force_default_encoding=(mode) ⇒ Object

Ruby 1.8-



2771
2772
2773
# File 'lib/tk.rb', line 2771

def force_default_encoding=(mode)
  true
end

#force_default_encoding?Boolean

Returns:

  • (Boolean)


2718
2719
2720
# File 'lib/tk.rb', line 2718

def force_default_encoding?
  TkCore::INTERP.force_default_encoding?
end

#tk_encoding_namesObject



2739
2740
2741
2742
# File 'lib/tk.rb', line 2739

def tk_encoding_names
  #TkComm.simplelist(TkCore::INTERP._invoke_without_enc(Tk::Encoding::ENCNAMES_CMD[0], Tk::Encoding::ENCNAMES_CMD[1]))
  TkComm.simplelist(TkCore::INTERP._invoke_without_enc('encoding', 'names'))
end