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 =
'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 =
TkCore::INTERP.encoding_table

Instance Method Summary collapse

Instance Method Details

#default_encoding=(enc) ⇒ Object



2720
2721
2722
# File 'lib/tk.rb', line 2720

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

#encoding=(name) ⇒ Object



2724
2725
2726
# File 'lib/tk.rb', line 2724

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



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

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



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

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



2857
2858
2859
2860
# File 'lib/tk.rb', line 2857

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

#encoding_dirs=(dir_array) ⇒ Object



2862
2863
2864
2865
# File 'lib/tk.rb', line 2862

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



2728
2729
2730
# File 'lib/tk.rb', line 2728

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

#encoding_namesObject



2741
2742
2743
2744
2745
# File 'lib/tk.rb', line 2741

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

#encoding_objObject



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

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

#encoding_objsObject



2746
2747
2748
2749
2750
# File 'lib/tk.rb', line 2746

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

#encoding_system=(enc) ⇒ Object



2752
2753
2754
# File 'lib/tk.rb', line 2752

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

#encoding_system_nameObject Also known as: encoding_system



2756
2757
2758
# File 'lib/tk.rb', line 2756

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

#encoding_system_objObject



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

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

#force_default_encoding(mode) ⇒ Object



2712
2713
2714
# File 'lib/tk.rb', line 2712

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

#force_default_encoding=(mode) ⇒ Object



2769
2770
2771
# File 'lib/tk.rb', line 2769

def force_default_encoding=(mode)
  true
end

#force_default_encoding?Boolean

Returns:

  • (Boolean)


2716
2717
2718
# File 'lib/tk.rb', line 2716

def force_default_encoding?
  TkCore::INTERP.force_default_encoding?
end

#tk_encoding_namesObject



2737
2738
2739
2740
# File 'lib/tk.rb', line 2737

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