Module: Tk::Encoding
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
- #default_encoding=(enc) ⇒ Object
- #encoding=(name) ⇒ Object
- #encoding_convertfrom(str, enc = None) ⇒ Object (also: #encoding_convert_from)
- #encoding_convertto(str, enc = None) ⇒ Object (also: #encoding_convert_to)
- #encoding_dirs ⇒ Object
-
#encoding_dirs=(dir_array) ⇒ Object
an array or a Tcl’s list string.
- #encoding_name ⇒ Object (also: #encoding, #default_encoding)
- #encoding_names ⇒ Object
- #encoding_obj ⇒ Object
- #encoding_objs ⇒ Object
- #encoding_system=(enc) ⇒ Object
- #encoding_system_name ⇒ Object (also: #encoding_system)
- #encoding_system_obj ⇒ Object
-
#force_default_encoding(mode) ⇒ Object
Ruby 1.9.
-
#force_default_encoding=(mode) ⇒ Object
Ruby 1.8-.
- #force_default_encoding? ⇒ Boolean
- #tk_encoding_names ⇒ Object
Instance Method Details
#default_encoding=(enc) ⇒ Object
2551 2552 2553 |
# File 'ext/lib/tk.rb', line 2551 def default_encoding=(enc) TkCore::INTERP.default_encoding = Tk::Encoding::ENCODING_TABLE.get_name(enc) end |
#encoding=(name) ⇒ Object
2555 2556 2557 |
# File 'ext/lib/tk.rb', line 2555 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
2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 |
# File 'ext/lib/tk.rb', line 2650 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
2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 |
# File 'ext/lib/tk.rb', line 2674 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_dirs ⇒ Object
2688 2689 2690 2691 |
# File 'ext/lib/tk.rb', line 2688 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
2693 2694 2695 2696 |
# File 'ext/lib/tk.rb', line 2693 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_name ⇒ Object Also known as: encoding, default_encoding
2559 2560 2561 |
# File 'ext/lib/tk.rb', line 2559 def encoding_name Tk::Encoding::ENCODING_TABLE.get_name(TkCore::INTERP.encoding) end |
#encoding_names ⇒ Object
2572 2573 2574 2575 2576 |
# File 'ext/lib/tk.rb', line 2572 def encoding_names self.tk_encoding_names.find_all{|name| Tk::Encoding::ENCODING_TABLE.get_name(name) rescue false } end |
#encoding_obj ⇒ Object
2562 2563 2564 |
# File 'ext/lib/tk.rb', line 2562 def encoding_obj Tk::Encoding::ENCODING_TABLE.get_obj(TkCore::INTERP.encoding) end |
#encoding_objs ⇒ Object
2577 2578 2579 2580 2581 |
# File 'ext/lib/tk.rb', line 2577 def encoding_objs self.tk_encoding_names.map!{|name| Tk::Encoding::ENCODING_TABLE.get_obj(name) rescue nil }.compact end |
#encoding_system=(enc) ⇒ Object
2583 2584 2585 |
# File 'ext/lib/tk.rb', line 2583 def encoding_system=(enc) TclTkLib.encoding_system = Tk::Encoding::ENCODING_TABLE.get_name(enc) end |
#encoding_system_name ⇒ Object Also known as: encoding_system
2587 2588 2589 |
# File 'ext/lib/tk.rb', line 2587 def encoding_system_name Tk::Encoding::ENCODING_TABLE.get_name(TclTkLib.encoding_system) end |
#encoding_system_obj ⇒ Object
2590 2591 2592 |
# File 'ext/lib/tk.rb', line 2590 def encoding_system_obj Tk::Encoding::ENCODING_TABLE.get_obj(TclTkLib.encoding_system) end |
#force_default_encoding(mode) ⇒ Object
Ruby 1.9
2543 2544 2545 |
# File 'ext/lib/tk.rb', line 2543 def force_default_encoding(mode) TkCore::INTERP.force_default_encoding = mode end |
#force_default_encoding=(mode) ⇒ Object
Ruby 1.8-
2600 2601 2602 |
# File 'ext/lib/tk.rb', line 2600 def force_default_encoding=(mode) true end |
#force_default_encoding? ⇒ Boolean
2547 2548 2549 |
# File 'ext/lib/tk.rb', line 2547 def force_default_encoding? TkCore::INTERP.force_default_encoding? end |
#tk_encoding_names ⇒ Object
2568 2569 2570 2571 |
# File 'ext/lib/tk.rb', line 2568 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 |