| Class | String |
| In: |
yaml/rubytypes.rb
bigdecimal/util.rb mkmf.rb kconv.rb jcode.rb |
| Parent: | Object |
Constants
| PATTERN_SJIS | = | '[\x81-\x9f\xe0-\xef][\x40-\x7e\x80-\xfc]' |
| PATTERN_EUC | = | '[\xa1-\xfe][\xa1-\xfe]' |
| PATTERN_UTF8 | = | '[\xc0-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf][\x80-\xbf]' |
| RE_SJIS | = | Regexp.new(PATTERN_SJIS, 0, 'n') |
| RE_EUC | = | Regexp.new(PATTERN_EUC, 0, 'n') |
| RE_UTF8 | = | Regexp.new(PATTERN_UTF8, 0, 'n') |
| SUCC | = | {} |
| HashCache | = | {} |
| TrPatternCache | = | {} |
| DeletePatternCache | = | {} |
| SqueezePatternCache | = | {} |
External Aliases
| succ! | -> | original_succ! |
| succ | -> | original_succ |
Public Class methods
# File yaml/rubytypes.rb, line 148
148: def String.yaml_new( klass, tag, val )
149: val = val.unpack("m")[0] if tag == "tag:yaml.org,2002:binary"
150: val = { 'str' => val } if String === val
151: if Hash === val
152: s = klass.allocate
153: # Thank you, NaHi
154: String.instance_method(:initialize).
155: bind(s).
156: call( val.delete( 'str' ) )
157: val.each { |k,v| s.instance_variable_set( k, v ) }
158: s
159: else
160: raise YAML::TypeError, "Invalid String: " + val.inspect
161: end
162: end
Public Instance methods
# File jcode.rb, line 151
151: def delete!(del)
152: return nil if del == ""
153: self.gsub!(DeletePatternCache[del] ||= /[#{_regex_quote(del)}]+/, '')
154: end
# File jcode.rb, line 209
209: def each_char
210: if block_given?
211: scan(/./m) do |x|
212: yield x
213: end
214: else
215: scan(/./m)
216: end
217: end
# File jcode.rb, line 59
59: def end_regexp
60: case $KCODE[0]
61: when ?s, ?S
62: /#{PATTERN_SJIS}$/on
63: when ?e, ?E
64: /#{PATTERN_EUC}$/on
65: when ?u, ?U
66: /#{PATTERN_UTF8}$/on
67: else
68: /.$/on
69: end
70: end
# File yaml/rubytypes.rb, line 145
145: def is_binary_data?
146: ( self.count( "^ -~", "^\r\n" ) / self.size > 0.3 || self.count( "\x00" ) > 0 ) unless empty?
147: end
# File yaml/rubytypes.rb, line 142
142: def is_complex_yaml?
143: to_yaml_style or not to_yaml_properties.empty? or self =~ /\n.+/
144: end
# File kconv.rb, line 195
195: def kconv(out_code, in_code=Kconv::AUTO)
196: Kconv::kconv(self, out_code, in_code)
197: end
# File jcode.rb, line 46
46: def mbchar?
47: case $KCODE[0]
48: when ?s, ?S
49: self =~ RE_SJIS
50: when ?e, ?E
51: self =~ RE_EUC
52: when ?u, ?U
53: self =~ RE_UTF8
54: else
55: nil
56: end
57: end
# File jcode.rb, line 171
171: def squeeze(del=nil)
172: (str = self.dup).squeeze!(del) or str
173: end
# File jcode.rb, line 160
160: def squeeze!(del=nil)
161: return nil if del == ""
162: pattern =
163: if del
164: SqueezePatternCache[del] ||= /([#{_regex_quote(del)}])\1+/
165: else
166: /(.|\n)\1+/
167: end
168: self.gsub!(pattern, '\1')
169: end
# File jcode.rb, line 78
78: def succ!
79: reg = end_regexp
80: if self =~ reg
81: succ_table = SUCC[$KCODE[0,1].downcase]
82: begin
83: self[-1] += succ_table[self[-1]]
84: self[-2] += 1 if self[-1] == 0
85: end while self !~ reg
86: self
87: else
88: original_succ!
89: end
90: end
# File yaml/rubytypes.rb, line 163
163: def to_yaml( opts = {} )
164: YAML::quick_emit( is_complex_yaml? ? object_id : nil, opts ) do |out|
165: if is_binary_data?
166: out.scalar( "tag:yaml.org,2002:binary", [self].pack("m"), :literal )
167: elsif to_yaml_properties.empty?
168: out.scalar( taguri, self, self =~ /^:/ ? :quote2 : to_yaml_style )
169: else
170: out.map( taguri, to_yaml_style ) do |map|
171: map.add( 'str', "#{self}" )
172: to_yaml_properties.each do |m|
173: map.add( m, instance_variable_get( m ) )
174: end
175: end
176: end
177: end
178: end
# File jcode.rb, line 133
133: def tr!(from, to)
134: return nil if from == ""
135: return self.delete!(from) if to == ""
136:
137: pattern = TrPatternCache[from] ||= /[#{_regex_quote(from)}]/
138: if from[0] == ?^
139: last = /.$/.match(to)[0]
140: self.gsub!(pattern, last)
141: else
142: h = HashCache[from + "1-0" + to] ||= expand_ch_hash(from, to)
143: self.gsub!(pattern) do |c| h[c] end
144: end
145: end
# File jcode.rb, line 188
188: def tr_s(from, to)
189: (str = self.dup).tr_s!(from,to) or str
190: end
# File jcode.rb, line 175
175: def tr_s!(from, to)
176: return self.delete!(from) if to.length == 0
177:
178: pattern = SqueezePatternCache[from] ||= /([#{_regex_quote(from)}])\1+/
179: if from[0] == ?^
180: last = /.$/.match(to)[0]
181: self.gsub!(pattern, last)
182: else
183: h = HashCache[from + "1-0" + to] ||= expand_ch_hash(from, to)
184: self.gsub!(pattern) do h[$1] end
185: end
186: end