Class: Tk::EncodedString
- Inherits:
-
String
- Object
- String
- Tk::EncodedString
show all
- Defined in:
- lib/tk/encodedstr.rb
Constant Summary
collapse
- Encoding =
nil
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(str, enc = nil) ⇒ EncodedString
Returns a new instance of EncodedString.
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/tk/encodedstr.rb', line 68
def initialize(str, enc = nil)
super(str)
@encoding = ( enc ||
((self.class::Encoding)?
self.class::Encoding :
((Tk.encoding)? Tk.encoding : Tk.encoding_system) ) )
end
|
Instance Attribute Details
Returns the value of attribute encoding.
79
80
81
|
# File 'lib/tk/encodedstr.rb', line 79
def encoding
@encoding
end
|
Class Method Details
.new_with_utf_backslash(str, enc = nil) ⇒ Object
60
61
62
|
# File '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
|
.new_without_utf_backslash(str, enc = nil) ⇒ Object
64
65
66
|
# File 'lib/tk/encodedstr.rb', line 64
def self.new_without_utf_backslash(str, enc = nil)
self.new('', enc).replace(str)
end
|
.subst_tk_backslash(str) ⇒ Object
21
22
23
|
# File 'lib/tk/encodedstr.rb', line 21
def self.subst_tk_backslash(str)
TclTkLib._subst_Tcl_backslash(str)
end
|
.subst_utf_backslash(str) ⇒ Object
13
14
15
16
|
# File 'lib/tk/encodedstr.rb', line 13
def self.subst_utf_backslash(str)
TclTkLib._subst_UTF_backslash(str)
end
|
.to_backslash_sequence(str) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/tk/encodedstr.rb', line 38
def self.to_backslash_sequence(str)
str.unpack('U*').collect{|c|
if c <= 0x1F
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
c.chr
else
format('\u%X', c)
end
}.join('')
end
|
.utf_backslash(str) ⇒ Object
17
18
19
|
# File 'lib/tk/encodedstr.rb', line 17
def self.utf_backslash(str)
self.subst_utf_backslash(str)
end
|
.utf_to_backslash(str) ⇒ Object
34
35
36
|
# File 'lib/tk/encodedstr.rb', line 34
def self.utf_to_backslash(str)
self.utf_to_backslash_sequence(str)
end
|
.utf_to_backslash_sequence(str) ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/tk/encodedstr.rb', line 25
def self.utf_to_backslash_sequence(str)
str.unpack('U*').collect{|c|
if c <= 0xFF
c.chr
else
format('\u%X', c)
end
}.join('')
end
|