opal 1.3.2 → 1.4.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintrc.js +1 -0
- data/.github/workflows/build.yml +0 -3
- data/.rubocop.yml +5 -1
- data/UNRELEASED.md +66 -2
- data/benchmark-ips/bm_truthy.rb +30 -0
- data/bin/opal-mspec +1 -3
- data/bin/opal-repl +1 -2
- data/bin/remove-filters +1 -4
- data/docs/compiled_ruby.md +10 -6
- data/exe/opal-repl +1 -3
- data/lib/opal/ast/builder.rb +1 -1
- data/lib/opal/cli.rb +2 -2
- data/lib/opal/cli_runners/nodejs.rb +9 -2
- data/lib/opal/cli_runners/source-map-support-browser.js +80 -216
- data/lib/opal/cli_runners/source-map-support-node.js +80 -216
- data/lib/opal/cli_runners/source-map-support.js +5 -1
- data/lib/opal/cli_runners/system_runner.rb +10 -4
- data/lib/opal/compiler.rb +3 -5
- data/lib/opal/fragment.rb +5 -1
- data/lib/opal/nodes/args/extract_block_arg.rb +1 -8
- data/lib/opal/nodes/args/extract_kwoptarg.rb +1 -3
- data/lib/opal/nodes/args/extract_optarg.rb +1 -3
- data/lib/opal/nodes/args/extract_post_arg.rb +2 -5
- data/lib/opal/nodes/args/extract_post_optarg.rb +2 -7
- data/lib/opal/nodes/args/initialize_iterarg.rb +1 -3
- data/lib/opal/nodes/args/prepare_post_args.rb +5 -1
- data/lib/opal/nodes/base.rb +3 -2
- data/lib/opal/nodes/call.rb +20 -9
- data/lib/opal/nodes/call_special.rb +50 -0
- data/lib/opal/nodes/class.rb +24 -15
- data/lib/opal/nodes/constants.rb +23 -5
- data/lib/opal/nodes/def.rb +20 -23
- data/lib/opal/nodes/defined.rb +5 -5
- data/lib/opal/nodes/definitions.rb +2 -2
- data/lib/opal/nodes/defs.rb +2 -5
- data/lib/opal/nodes/helpers.rb +48 -18
- data/lib/opal/nodes/if.rb +109 -8
- data/lib/opal/nodes/iter.rb +23 -16
- data/lib/opal/nodes/literal.rb +18 -4
- data/lib/opal/nodes/logic.rb +2 -1
- data/lib/opal/nodes/masgn.rb +4 -9
- data/lib/opal/nodes/module.rb +29 -19
- data/lib/opal/nodes/node_with_args.rb +1 -7
- data/lib/opal/nodes/scope.rb +54 -15
- data/lib/opal/nodes/singleton_class.rb +5 -3
- data/lib/opal/nodes/super.rb +3 -3
- data/lib/opal/nodes/top.rb +34 -31
- data/lib/opal/nodes/variables.rb +2 -2
- data/lib/opal/nodes/x_string.rb +3 -0
- data/lib/opal/nodes.rb +0 -1
- data/lib/opal/parser/patch.rb +75 -0
- data/lib/opal/parser/with_ruby_lexer.rb +1 -1
- data/lib/opal/regexp_anchors.rb +7 -7
- data/lib/opal/requires.rb +19 -0
- data/lib/opal/rewriters/pattern_matching.rb +1 -1
- data/lib/opal/rewriters/returnable_logic.rb +102 -4
- data/lib/opal/util.rb +2 -2
- data/lib/opal/version.rb +1 -1
- data/lib/opal.rb +1 -17
- data/opal/corelib/array/pack.rb +11 -11
- data/opal/corelib/array.rb +193 -152
- data/opal/corelib/basic_object.rb +14 -14
- data/opal/corelib/binding.rb +7 -7
- data/opal/corelib/boolean.rb +12 -15
- data/opal/corelib/class.rb +23 -1
- data/opal/corelib/comparable.rb +8 -8
- data/opal/corelib/complex/base.rb +2 -2
- data/opal/corelib/complex.rb +79 -88
- data/opal/corelib/constants.rb +9 -9
- data/opal/corelib/dir.rb +4 -3
- data/opal/corelib/enumerable.rb +140 -127
- data/opal/corelib/enumerator/arithmetic_sequence.rb +177 -0
- data/opal/corelib/enumerator/chain.rb +42 -0
- data/opal/corelib/enumerator/generator.rb +35 -0
- data/opal/corelib/enumerator/lazy.rb +243 -0
- data/opal/corelib/enumerator/yielder.rb +36 -0
- data/opal/corelib/enumerator.rb +45 -300
- data/opal/corelib/error/errno.rb +47 -0
- data/opal/corelib/error.rb +62 -60
- data/opal/corelib/file.rb +26 -12
- data/opal/corelib/hash.rb +98 -107
- data/opal/corelib/helpers.rb +62 -13
- data/opal/corelib/io.rb +47 -34
- data/opal/corelib/kernel/format.rb +29 -29
- data/opal/corelib/kernel.rb +86 -83
- data/opal/corelib/main.rb +14 -12
- data/opal/corelib/marshal/read_buffer.rb +15 -15
- data/opal/corelib/marshal/write_buffer.rb +45 -44
- data/opal/corelib/marshal.rb +3 -3
- data/opal/corelib/math.rb +50 -50
- data/opal/corelib/method.rb +12 -8
- data/opal/corelib/module.rb +96 -79
- data/opal/corelib/nil.rb +9 -11
- data/opal/corelib/number.rb +113 -118
- data/opal/corelib/numeric.rb +37 -33
- data/opal/corelib/object_space.rb +11 -10
- data/opal/corelib/pack_unpack/format_string_parser.rb +3 -3
- data/opal/corelib/pattern_matching/base.rb +7 -7
- data/opal/corelib/pattern_matching.rb +1 -1
- data/opal/corelib/proc.rb +15 -16
- data/opal/corelib/process/base.rb +2 -2
- data/opal/corelib/process/status.rb +21 -0
- data/opal/corelib/process.rb +5 -5
- data/opal/corelib/random/formatter.rb +11 -11
- data/opal/corelib/random/math_random.js.rb +1 -1
- data/opal/corelib/random/mersenne_twister.rb +3 -3
- data/opal/corelib/random/seedrandom.js.rb +3 -3
- data/opal/corelib/random.rb +17 -17
- data/opal/corelib/range.rb +51 -35
- data/opal/corelib/rational/base.rb +4 -4
- data/opal/corelib/rational.rb +61 -62
- data/opal/corelib/regexp.rb +47 -38
- data/opal/corelib/runtime.js +245 -139
- data/opal/corelib/string/encoding.rb +21 -21
- data/opal/corelib/string/unpack.rb +19 -14
- data/opal/corelib/string.rb +135 -128
- data/opal/corelib/struct.rb +59 -46
- data/opal/corelib/time.rb +47 -57
- data/opal/corelib/trace_point.rb +2 -2
- data/opal/corelib/unsupported.rb +31 -120
- data/opal/corelib/variables.rb +3 -3
- data/opal/opal/base.rb +9 -8
- data/opal/opal/full.rb +8 -8
- data/opal/opal/mini.rb +17 -17
- data/opal/opal.rb +17 -18
- data/opal.gemspec +1 -1
- data/spec/filters/bugs/array.rb +4 -24
- data/spec/filters/bugs/bigdecimal.rb +0 -23
- data/spec/filters/bugs/binding.rb +0 -1
- data/spec/filters/bugs/boolean.rb +3 -0
- data/spec/filters/bugs/class.rb +2 -0
- data/spec/filters/bugs/date.rb +0 -5
- data/spec/filters/bugs/encoding.rb +8 -50
- data/spec/filters/bugs/enumerable.rb +4 -1
- data/spec/filters/bugs/enumerator.rb +3 -36
- data/spec/filters/bugs/exception.rb +0 -2
- data/spec/filters/bugs/file.rb +0 -2
- data/spec/filters/bugs/float.rb +0 -3
- data/spec/filters/bugs/hash.rb +5 -3
- data/spec/filters/bugs/integer.rb +2 -3
- data/spec/filters/bugs/kernel.rb +2 -31
- data/spec/filters/bugs/language.rb +29 -49
- data/spec/filters/bugs/main.rb +0 -2
- data/spec/filters/bugs/marshal.rb +2 -3
- data/spec/filters/bugs/matrix.rb +0 -36
- data/spec/filters/bugs/module.rb +7 -61
- data/spec/filters/bugs/numeric.rb +0 -7
- data/spec/filters/bugs/objectspace.rb +1 -1
- data/spec/filters/bugs/pack_unpack.rb +0 -4
- data/spec/filters/bugs/proc.rb +0 -9
- data/spec/filters/bugs/random.rb +0 -5
- data/spec/filters/bugs/range.rb +1 -6
- data/spec/filters/bugs/regexp.rb +0 -3
- data/spec/filters/bugs/set.rb +8 -1
- data/spec/filters/bugs/string.rb +9 -34
- data/spec/filters/bugs/stringscanner.rb +8 -7
- data/spec/filters/bugs/struct.rb +2 -3
- data/spec/filters/bugs/symbol.rb +0 -1
- data/spec/filters/bugs/time.rb +0 -8
- data/spec/filters/bugs/unboundmethod.rb +0 -8
- data/spec/filters/bugs/warnings.rb +1 -7
- data/spec/filters/unsupported/freeze.rb +24 -0
- data/spec/filters/unsupported/integer.rb +1 -0
- data/spec/filters/unsupported/kernel.rb +12 -0
- data/spec/filters/unsupported/privacy.rb +3 -0
- data/spec/filters/unsupported/string.rb +2 -0
- data/spec/lib/builder_spec.rb +2 -2
- data/spec/lib/cli_spec.rb +1 -1
- data/spec/lib/compiler_spec.rb +37 -37
- data/spec/lib/simple_server_spec.rb +2 -2
- data/spec/lib/source_map/file_spec.rb +1 -1
- data/spec/opal/compiler/irb_spec.rb +2 -2
- data/spec/opal/core/kernel/puts_spec.rb +90 -0
- data/spec/opal/core/language/super_spec.rb +24 -0
- data/spec/ruby_specs +4 -2
- data/spec/support/rewriters_helper.rb +1 -1
- data/stdlib/bigdecimal.rb +7 -11
- data/stdlib/buffer/view.rb +2 -2
- data/stdlib/buffer.rb +2 -2
- data/stdlib/date.rb +5 -6
- data/stdlib/erb.rb +1 -0
- data/stdlib/js.rb +2 -1
- data/stdlib/native.rb +7 -8
- data/stdlib/nodejs/argf.rb +4 -4
- data/stdlib/nodejs/base.rb +29 -0
- data/stdlib/nodejs/dir.rb +1 -1
- data/stdlib/nodejs/env.rb +6 -9
- data/stdlib/nodejs/file.rb +23 -17
- data/stdlib/nodejs/fileutils.rb +3 -3
- data/stdlib/nodejs/io.rb +2 -20
- data/stdlib/nodejs/irb.rb +0 -0
- data/stdlib/nodejs/kernel.rb +2 -37
- data/stdlib/nodejs.rb +1 -3
- data/stdlib/opal/miniracer.rb +2 -0
- data/stdlib/opal/platform.rb +6 -13
- data/stdlib/opal/replutils.rb +16 -5
- data/stdlib/opal-parser.rb +2 -2
- data/stdlib/optparse/ac.rb +54 -0
- data/stdlib/optparse/date.rb +14 -0
- data/stdlib/optparse/kwargs.rb +22 -0
- data/stdlib/optparse/shellwords.rb +7 -0
- data/stdlib/optparse/time.rb +15 -0
- data/stdlib/optparse/uri.rb +7 -0
- data/stdlib/optparse/version.rb +69 -0
- data/stdlib/optparse.rb +2279 -0
- data/stdlib/pathname.rb +5 -6
- data/stdlib/pp.rb +18 -2
- data/stdlib/promise/v2.rb +18 -22
- data/stdlib/promise.rb +15 -21
- data/stdlib/set.rb +32 -32
- data/stdlib/shellwords.rb +240 -0
- data/stdlib/stringio.rb +3 -6
- data/stdlib/strscan.rb +5 -8
- data/stdlib/template.rb +2 -2
- data/stdlib/thread.rb +7 -9
- data/tasks/performance.rake +5 -2
- data/tasks/testing/mspec_special_calls.rb +0 -12
- data/tasks/testing.rake +55 -37
- data/test/nodejs/test_file.rb +11 -0
- metadata +55 -10
- data/lib/opal/nodes/case.rb +0 -114
data/opal/corelib/string.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
# helpers: coerce_to, respond_to
|
1
|
+
# helpers: coerce_to, respond_to, global_multiline_regexp
|
2
2
|
|
3
3
|
require 'corelib/comparable'
|
4
4
|
require 'corelib/regexp'
|
5
5
|
|
6
|
-
class String < `String`
|
7
|
-
include Comparable
|
6
|
+
class ::String < `String`
|
7
|
+
include ::Comparable
|
8
8
|
|
9
9
|
%x{
|
10
|
-
Opal.
|
10
|
+
Opal.prop(#{self}.$$prototype, '$$is_string', true);
|
11
11
|
|
12
|
-
Opal.
|
12
|
+
Opal.prop(#{self}.$$prototype, '$$cast', function(string) {
|
13
13
|
var klass = this.$$class;
|
14
14
|
if (klass.$$constructor === String) {
|
15
15
|
return string;
|
@@ -23,17 +23,15 @@ class String < `String`
|
|
23
23
|
`self.toString()`
|
24
24
|
end
|
25
25
|
|
26
|
-
alias object_id __id__
|
27
|
-
|
28
26
|
def self.try_convert(what)
|
29
|
-
Opal.coerce_to?(what, String, :to_str)
|
27
|
+
::Opal.coerce_to?(what, ::String, :to_str)
|
30
28
|
end
|
31
29
|
|
32
30
|
def self.new(*args)
|
33
31
|
%x{
|
34
32
|
var str = args[0] || "";
|
35
33
|
var opts = args[args.length-1];
|
36
|
-
str = $coerce_to(str, #{String}, 'to_str');
|
34
|
+
str = $coerce_to(str, #{::String}, 'to_str');
|
37
35
|
if (opts && opts.$$is_hash) {
|
38
36
|
if (opts.$$smap.encoding) str = str.$force_encoding(opts.$$smap.encoding);
|
39
37
|
}
|
@@ -52,7 +50,7 @@ class String < `String`
|
|
52
50
|
end
|
53
51
|
|
54
52
|
def %(data)
|
55
|
-
if Array === data
|
53
|
+
if ::Array === data
|
56
54
|
format(self, *data)
|
57
55
|
else
|
58
56
|
format(self, data)
|
@@ -61,10 +59,10 @@ class String < `String`
|
|
61
59
|
|
62
60
|
def *(count)
|
63
61
|
%x{
|
64
|
-
count = $coerce_to(count, #{Integer}, 'to_int');
|
62
|
+
count = $coerce_to(count, #{::Integer}, 'to_int');
|
65
63
|
|
66
64
|
if (count < 0) {
|
67
|
-
#{raise ArgumentError, 'negative argument'}
|
65
|
+
#{::Kernel.raise ::ArgumentError, 'negative argument'}
|
68
66
|
}
|
69
67
|
|
70
68
|
if (count === 0) {
|
@@ -79,7 +77,7 @@ class String < `String`
|
|
79
77
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat
|
80
78
|
|
81
79
|
if (string.length * count >= 1 << 28) {
|
82
|
-
#{raise RangeError, 'multiply count must not overflow maximum string size'}
|
80
|
+
#{::Kernel.raise ::RangeError, 'multiply count must not overflow maximum string size'}
|
83
81
|
}
|
84
82
|
|
85
83
|
for (;;) {
|
@@ -98,7 +96,7 @@ class String < `String`
|
|
98
96
|
end
|
99
97
|
|
100
98
|
def +(other)
|
101
|
-
other = `$coerce_to(#{other}, #{String}, 'to_str')`
|
99
|
+
other = `$coerce_to(#{other}, #{::String}, 'to_str')`
|
102
100
|
|
103
101
|
%x{
|
104
102
|
if (other == "" && self.$$class === Opal.String) return #{self};
|
@@ -141,13 +139,10 @@ class String < `String`
|
|
141
139
|
}
|
142
140
|
end
|
143
141
|
|
144
|
-
alias eql? ==
|
145
|
-
alias === ==
|
146
|
-
|
147
142
|
def =~(other)
|
148
143
|
%x{
|
149
144
|
if (other.$$is_string) {
|
150
|
-
#{raise TypeError, 'type mismatch: String given'};
|
145
|
+
#{::Kernel.raise ::TypeError, 'type mismatch: String given'};
|
151
146
|
}
|
152
147
|
|
153
148
|
return #{other =~ self};
|
@@ -156,12 +151,13 @@ class String < `String`
|
|
156
151
|
|
157
152
|
def [](index, length = undefined)
|
158
153
|
%x{
|
159
|
-
var size = self.length, exclude;
|
154
|
+
var size = self.length, exclude, range;
|
160
155
|
|
161
156
|
if (index.$$is_range) {
|
162
157
|
exclude = index.excl;
|
163
|
-
|
164
|
-
|
158
|
+
range = index;
|
159
|
+
length = index.end === nil ? -1 : $coerce_to(index.end, #{::Integer}, 'to_int');
|
160
|
+
index = index.begin === nil ? 0 : $coerce_to(index.begin, #{::Integer}, 'to_int');
|
165
161
|
|
166
162
|
if (Math.abs(index) > size) {
|
167
163
|
return nil;
|
@@ -175,7 +171,7 @@ class String < `String`
|
|
175
171
|
length += size;
|
176
172
|
}
|
177
173
|
|
178
|
-
if (!exclude) {
|
174
|
+
if (!exclude || range.end === nil) {
|
179
175
|
length += 1;
|
180
176
|
}
|
181
177
|
|
@@ -191,7 +187,7 @@ class String < `String`
|
|
191
187
|
|
192
188
|
if (index.$$is_string) {
|
193
189
|
if (length != null) {
|
194
|
-
#{raise TypeError}
|
190
|
+
#{::Kernel.raise ::TypeError}
|
195
191
|
}
|
196
192
|
return self.indexOf(index) !== -1 ? self.$$cast(index) : nil;
|
197
193
|
}
|
@@ -205,13 +201,13 @@ class String < `String`
|
|
205
201
|
return nil;
|
206
202
|
}
|
207
203
|
|
208
|
-
#{$~ = MatchData.new(`index`, `match`)}
|
204
|
+
#{$~ = ::MatchData.new(`index`, `match`)}
|
209
205
|
|
210
206
|
if (length == null) {
|
211
207
|
return self.$$cast(match[0]);
|
212
208
|
}
|
213
209
|
|
214
|
-
length = $coerce_to(length, #{Integer}, 'to_int');
|
210
|
+
length = $coerce_to(length, #{::Integer}, 'to_int');
|
215
211
|
|
216
212
|
if (length < 0 && -length < match.length) {
|
217
213
|
return self.$$cast(match[length += match.length]);
|
@@ -225,7 +221,7 @@ class String < `String`
|
|
225
221
|
}
|
226
222
|
|
227
223
|
|
228
|
-
index = $coerce_to(index, #{Integer}, 'to_int');
|
224
|
+
index = $coerce_to(index, #{::Integer}, 'to_int');
|
229
225
|
|
230
226
|
if (index < 0) {
|
231
227
|
index += size;
|
@@ -238,7 +234,7 @@ class String < `String`
|
|
238
234
|
return self.$$cast(self.substr(index, 1));
|
239
235
|
}
|
240
236
|
|
241
|
-
length = $coerce_to(length, #{Integer}, 'to_int');
|
237
|
+
length = $coerce_to(length, #{::Integer}, 'to_int');
|
242
238
|
|
243
239
|
if (length < 0) {
|
244
240
|
return nil;
|
@@ -252,8 +248,6 @@ class String < `String`
|
|
252
248
|
}
|
253
249
|
end
|
254
250
|
|
255
|
-
alias byteslice []
|
256
|
-
|
257
251
|
def b
|
258
252
|
`new String(#{self})`.force_encoding('binary')
|
259
253
|
end
|
@@ -264,7 +258,7 @@ class String < `String`
|
|
264
258
|
|
265
259
|
def casecmp(other)
|
266
260
|
return nil unless other.respond_to?(:to_str)
|
267
|
-
other = `$coerce_to(other, #{String}, 'to_str')`.to_s
|
261
|
+
other = `$coerce_to(other, #{::String}, 'to_str')`.to_s
|
268
262
|
%x{
|
269
263
|
var ascii_only = /^[\x00-\x7F]*$/;
|
270
264
|
if (ascii_only.test(self) && ascii_only.test(other)) {
|
@@ -287,11 +281,11 @@ class String < `String`
|
|
287
281
|
end
|
288
282
|
|
289
283
|
def center(width, padstr = ' ')
|
290
|
-
width = `$coerce_to(#{width}, #{Integer}, 'to_int')`
|
291
|
-
padstr = `$coerce_to(#{padstr}, #{String}, 'to_str')`.to_s
|
284
|
+
width = `$coerce_to(#{width}, #{::Integer}, 'to_int')`
|
285
|
+
padstr = `$coerce_to(#{padstr}, #{::String}, 'to_str')`.to_s
|
292
286
|
|
293
287
|
if padstr.empty?
|
294
|
-
raise ArgumentError, 'zero width padding'
|
288
|
+
::Kernel.raise ::ArgumentError, 'zero width padding'
|
295
289
|
end
|
296
290
|
|
297
291
|
return self if `width <= self.length`
|
@@ -307,7 +301,7 @@ class String < `String`
|
|
307
301
|
def chomp(separator = $/)
|
308
302
|
return self if `separator === nil || self.length === 0`
|
309
303
|
|
310
|
-
separator = Opal.coerce_to!(separator, String, :to_str).to_s
|
304
|
+
separator = ::Opal.coerce_to!(separator, ::String, :to_str).to_s
|
311
305
|
|
312
306
|
%x{
|
313
307
|
var result;
|
@@ -370,7 +364,7 @@ class String < `String`
|
|
370
364
|
def count(*sets)
|
371
365
|
%x{
|
372
366
|
if (sets.length === 0) {
|
373
|
-
#{raise ArgumentError, 'ArgumentError: wrong number of arguments (0 for 1+)'}
|
367
|
+
#{::Kernel.raise ::ArgumentError, 'ArgumentError: wrong number of arguments (0 for 1+)'}
|
374
368
|
}
|
375
369
|
var char_class = char_class_from_char_sets(sets);
|
376
370
|
if (char_class === null) {
|
@@ -383,7 +377,7 @@ class String < `String`
|
|
383
377
|
def delete(*sets)
|
384
378
|
%x{
|
385
379
|
if (sets.length === 0) {
|
386
|
-
#{raise ArgumentError, 'ArgumentError: wrong number of arguments (0 for 1+)'}
|
380
|
+
#{::Kernel.raise ::ArgumentError, 'ArgumentError: wrong number of arguments (0 for 1+)'}
|
387
381
|
}
|
388
382
|
var char_class = char_class_from_char_sets(sets);
|
389
383
|
if (char_class === null) {
|
@@ -396,7 +390,7 @@ class String < `String`
|
|
396
390
|
def delete_prefix(prefix)
|
397
391
|
%x{
|
398
392
|
if (!prefix.$$is_string) {
|
399
|
-
prefix = $coerce_to(prefix, #{String}, 'to_str');
|
393
|
+
prefix = $coerce_to(prefix, #{::String}, 'to_str');
|
400
394
|
}
|
401
395
|
|
402
396
|
if (self.slice(0, prefix.length) === prefix) {
|
@@ -410,7 +404,7 @@ class String < `String`
|
|
410
404
|
def delete_suffix(suffix)
|
411
405
|
%x{
|
412
406
|
if (!suffix.$$is_string) {
|
413
|
-
suffix = $coerce_to(suffix, #{String}, 'to_str');
|
407
|
+
suffix = $coerce_to(suffix, #{::String}, 'to_str');
|
414
408
|
}
|
415
409
|
|
416
410
|
if (self.slice(self.length - suffix.length) === suffix) {
|
@@ -425,8 +419,8 @@ class String < `String`
|
|
425
419
|
`self.$$cast(self.toLowerCase())`
|
426
420
|
end
|
427
421
|
|
428
|
-
def each_line(separator = $/, &block)
|
429
|
-
return enum_for :each_line, separator unless block_given?
|
422
|
+
def each_line(separator = $/, chomp: false, &block)
|
423
|
+
return enum_for :each_line, separator, chomp: chomp unless block_given?
|
430
424
|
|
431
425
|
%x{
|
432
426
|
if (separator === nil) {
|
@@ -435,15 +429,18 @@ class String < `String`
|
|
435
429
|
return self;
|
436
430
|
}
|
437
431
|
|
438
|
-
separator = $coerce_to(separator, #{String}, 'to_str')
|
432
|
+
separator = $coerce_to(separator, #{::String}, 'to_str');
|
439
433
|
|
440
|
-
var a, i, n, length, chomped, trailing, splitted;
|
434
|
+
var a, i, n, length, chomped, trailing, splitted, value;
|
441
435
|
|
442
436
|
if (separator.length === 0) {
|
443
|
-
for (a = self.split(/(
|
437
|
+
for (a = self.split(/((?:\r?\n){2})(?:(?:\r?\n)*)/), i = 0, n = a.length; i < n; i += 2) {
|
444
438
|
if (a[i] || a[i + 1]) {
|
445
|
-
|
446
|
-
|
439
|
+
value = (a[i] || "") + (a[i + 1] || "");
|
440
|
+
if (chomp) {
|
441
|
+
value = #{`value`.chomp("\n")};
|
442
|
+
}
|
443
|
+
Opal.yield1(block, value);
|
447
444
|
}
|
448
445
|
}
|
449
446
|
|
@@ -455,12 +452,14 @@ class String < `String`
|
|
455
452
|
splitted = chomped.split(separator);
|
456
453
|
|
457
454
|
for (i = 0, length = splitted.length; i < length; i++) {
|
455
|
+
value = splitted[i];
|
458
456
|
if (i < length - 1 || trailing) {
|
459
|
-
|
457
|
+
value += separator;
|
460
458
|
}
|
461
|
-
|
462
|
-
|
459
|
+
if (chomp) {
|
460
|
+
value = #{`value`.chomp(separator)};
|
463
461
|
}
|
462
|
+
Opal.yield1(block, value);
|
464
463
|
}
|
465
464
|
}
|
466
465
|
|
@@ -474,7 +473,7 @@ class String < `String`
|
|
474
473
|
def end_with?(*suffixes)
|
475
474
|
%x{
|
476
475
|
for (var i = 0, length = suffixes.length; i < length; i++) {
|
477
|
-
var suffix = $coerce_to(suffixes[i], #{String}, 'to_str').$to_s();
|
476
|
+
var suffix = $coerce_to(suffixes[i], #{::String}, 'to_str').$to_s();
|
478
477
|
|
479
478
|
if (self.length >= suffix.length &&
|
480
479
|
self.substr(self.length - suffix.length, suffix.length) == suffix) {
|
@@ -486,8 +485,6 @@ class String < `String`
|
|
486
485
|
false
|
487
486
|
end
|
488
487
|
|
489
|
-
alias equal? ===
|
490
|
-
|
491
488
|
def gsub(pattern, replacement = undefined, &block)
|
492
489
|
%x{
|
493
490
|
if (replacement === undefined && block === nil) {
|
@@ -497,9 +494,9 @@ class String < `String`
|
|
497
494
|
var result = '', match_data = nil, index = 0, match, _replacement;
|
498
495
|
|
499
496
|
if (pattern.$$is_regexp) {
|
500
|
-
pattern =
|
497
|
+
pattern = $global_multiline_regexp(pattern);
|
501
498
|
} else {
|
502
|
-
pattern = $coerce_to(pattern, #{String}, 'to_str');
|
499
|
+
pattern = $coerce_to(pattern, #{::String}, 'to_str');
|
503
500
|
pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gm');
|
504
501
|
}
|
505
502
|
|
@@ -513,7 +510,7 @@ class String < `String`
|
|
513
510
|
break;
|
514
511
|
}
|
515
512
|
|
516
|
-
match_data = #{MatchData.new `pattern`, `match`};
|
513
|
+
match_data = #{::MatchData.new `pattern`, `match`};
|
517
514
|
|
518
515
|
if (replacement === undefined) {
|
519
516
|
lastIndex = pattern.lastIndex;
|
@@ -525,7 +522,7 @@ class String < `String`
|
|
525
522
|
}
|
526
523
|
else {
|
527
524
|
if (!replacement.$$is_string) {
|
528
|
-
replacement = $coerce_to(replacement, #{String}, 'to_str');
|
525
|
+
replacement = $coerce_to(replacement, #{::String}, 'to_str');
|
529
526
|
}
|
530
527
|
_replacement = replacement.replace(/([\\]+)([0-9+&`'])/g, function (original, slashes, command) {
|
531
528
|
if (slashes.length % 2 === 0) {
|
@@ -573,7 +570,7 @@ class String < `String`
|
|
573
570
|
def include?(other)
|
574
571
|
%x{
|
575
572
|
if (!other.$$is_string) {
|
576
|
-
other = $coerce_to(other, #{String}, 'to_str');
|
573
|
+
other = $coerce_to(other, #{::String}, 'to_str');
|
577
574
|
}
|
578
575
|
return self.indexOf(other) !== -1;
|
579
576
|
}
|
@@ -588,7 +585,7 @@ class String < `String`
|
|
588
585
|
if (offset === undefined) {
|
589
586
|
offset = 0;
|
590
587
|
} else {
|
591
|
-
offset = $coerce_to(offset, #{Integer}, 'to_int');
|
588
|
+
offset = $coerce_to(offset, #{::Integer}, 'to_int');
|
592
589
|
if (offset < 0) {
|
593
590
|
offset += self.length;
|
594
591
|
if (offset < 0) {
|
@@ -598,7 +595,7 @@ class String < `String`
|
|
598
595
|
}
|
599
596
|
|
600
597
|
if (search.$$is_regexp) {
|
601
|
-
regex =
|
598
|
+
regex = $global_multiline_regexp(search);
|
602
599
|
while (true) {
|
603
600
|
match = regex.exec(self);
|
604
601
|
if (match === null) {
|
@@ -607,14 +604,14 @@ class String < `String`
|
|
607
604
|
break;
|
608
605
|
}
|
609
606
|
if (match.index >= offset) {
|
610
|
-
#{$~ = MatchData.new(`regex`, `match`)}
|
607
|
+
#{$~ = ::MatchData.new(`regex`, `match`)}
|
611
608
|
index = match.index;
|
612
609
|
break;
|
613
610
|
}
|
614
611
|
regex.lastIndex = match.index + 1;
|
615
612
|
}
|
616
613
|
} else {
|
617
|
-
search = $coerce_to(search, #{String}, 'to_str');
|
614
|
+
search = $coerce_to(search, #{::String}, 'to_str');
|
618
615
|
if (search.length === 0 && offset > self.length) {
|
619
616
|
index = -1;
|
620
617
|
} else {
|
@@ -660,17 +657,17 @@ class String < `String`
|
|
660
657
|
`self.toString()`
|
661
658
|
end
|
662
659
|
|
663
|
-
def lines(separator = $/, &block)
|
664
|
-
e = each_line(separator, &block)
|
660
|
+
def lines(separator = $/, chomp: false, &block)
|
661
|
+
e = each_line(separator, chomp: chomp, &block)
|
665
662
|
block ? self : e.to_a
|
666
663
|
end
|
667
664
|
|
668
665
|
def ljust(width, padstr = ' ')
|
669
|
-
width = `$coerce_to(#{width}, #{Integer}, 'to_int')`
|
670
|
-
padstr = `$coerce_to(#{padstr}, #{String}, 'to_str')`.to_s
|
666
|
+
width = `$coerce_to(#{width}, #{::Integer}, 'to_int')`
|
667
|
+
padstr = `$coerce_to(#{padstr}, #{::String}, 'to_str')`.to_s
|
671
668
|
|
672
669
|
if padstr.empty?
|
673
|
-
raise ArgumentError, 'zero width padding'
|
670
|
+
::Kernel.raise ::ArgumentError, 'zero width padding'
|
674
671
|
end
|
675
672
|
|
676
673
|
return self if `width <= self.length`
|
@@ -690,7 +687,7 @@ class String < `String`
|
|
690
687
|
end
|
691
688
|
|
692
689
|
def lstrip
|
693
|
-
`self.replace(
|
690
|
+
`self.replace(/^[\u0000\s]*/, '')`
|
694
691
|
end
|
695
692
|
|
696
693
|
def ascii_only?
|
@@ -703,11 +700,11 @@ class String < `String`
|
|
703
700
|
|
704
701
|
def match(pattern, pos = undefined, &block)
|
705
702
|
if String === pattern || pattern.respond_to?(:to_str)
|
706
|
-
pattern = Regexp.new(pattern.to_str)
|
703
|
+
pattern = ::Regexp.new(pattern.to_str)
|
707
704
|
end
|
708
705
|
|
709
|
-
unless Regexp === pattern
|
710
|
-
raise TypeError, "wrong argument type #{pattern.class} (expected Regexp)"
|
706
|
+
unless ::Regexp === pattern
|
707
|
+
::Kernel.raise ::TypeError, "wrong argument type #{pattern.class} (expected Regexp)"
|
711
708
|
end
|
712
709
|
|
713
710
|
pattern.match(self, pos, &block)
|
@@ -715,11 +712,11 @@ class String < `String`
|
|
715
712
|
|
716
713
|
def match?(pattern, pos = undefined)
|
717
714
|
if String === pattern || pattern.respond_to?(:to_str)
|
718
|
-
pattern = Regexp.new(pattern.to_str)
|
715
|
+
pattern = ::Regexp.new(pattern.to_str)
|
719
716
|
end
|
720
717
|
|
721
|
-
unless Regexp === pattern
|
722
|
-
raise TypeError, "wrong argument type #{pattern.class} (expected Regexp)"
|
718
|
+
unless ::Regexp === pattern
|
719
|
+
::Kernel.raise ::TypeError, "wrong argument type #{pattern.class} (expected Regexp)"
|
723
720
|
end
|
724
721
|
|
725
722
|
pattern.match?(self, pos)
|
@@ -858,12 +855,12 @@ class String < `String`
|
|
858
855
|
if (m === null) {
|
859
856
|
i = -1;
|
860
857
|
} else {
|
861
|
-
#{MatchData.new `sep`, `m`};
|
858
|
+
#{::MatchData.new `sep`, `m`};
|
862
859
|
sep = m[0];
|
863
860
|
i = m.index;
|
864
861
|
}
|
865
862
|
} else {
|
866
|
-
sep = $coerce_to(sep, #{String}, 'to_str');
|
863
|
+
sep = $coerce_to(sep, #{::String}, 'to_str');
|
867
864
|
i = self.indexOf(sep);
|
868
865
|
}
|
869
866
|
|
@@ -890,7 +887,7 @@ class String < `String`
|
|
890
887
|
if (offset === undefined) {
|
891
888
|
offset = self.length;
|
892
889
|
} else {
|
893
|
-
offset = $coerce_to(offset, #{Integer}, 'to_int');
|
890
|
+
offset = $coerce_to(offset, #{::Integer}, 'to_int');
|
894
891
|
if (offset < 0) {
|
895
892
|
offset += self.length;
|
896
893
|
if (offset < 0) {
|
@@ -901,7 +898,7 @@ class String < `String`
|
|
901
898
|
|
902
899
|
if (search.$$is_regexp) {
|
903
900
|
m = null;
|
904
|
-
r =
|
901
|
+
r = $global_multiline_regexp(search);
|
905
902
|
while (true) {
|
906
903
|
_m = r.exec(self);
|
907
904
|
if (_m === null || _m.index > offset) {
|
@@ -914,11 +911,11 @@ class String < `String`
|
|
914
911
|
#{$~ = nil}
|
915
912
|
i = -1;
|
916
913
|
} else {
|
917
|
-
#{MatchData.new `r`, `m`};
|
914
|
+
#{::MatchData.new `r`, `m`};
|
918
915
|
i = m.index;
|
919
916
|
}
|
920
917
|
} else {
|
921
|
-
search = $coerce_to(search, #{String}, 'to_str');
|
918
|
+
search = $coerce_to(search, #{::String}, 'to_str');
|
922
919
|
i = self.lastIndexOf(search, offset);
|
923
920
|
}
|
924
921
|
|
@@ -927,11 +924,11 @@ class String < `String`
|
|
927
924
|
end
|
928
925
|
|
929
926
|
def rjust(width, padstr = ' ')
|
930
|
-
width = `$coerce_to(#{width}, #{Integer}, 'to_int')`
|
931
|
-
padstr = `$coerce_to(#{padstr}, #{String}, 'to_str')`.to_s
|
927
|
+
width = `$coerce_to(#{width}, #{::Integer}, 'to_int')`
|
928
|
+
padstr = `$coerce_to(#{padstr}, #{::String}, 'to_str')`.to_s
|
932
929
|
|
933
930
|
if padstr.empty?
|
934
|
-
raise ArgumentError, 'zero width padding'
|
931
|
+
::Kernel.raise ::ArgumentError, 'zero width padding'
|
935
932
|
end
|
936
933
|
|
937
934
|
return self if `width <= self.length`
|
@@ -952,7 +949,7 @@ class String < `String`
|
|
952
949
|
|
953
950
|
if (sep.$$is_regexp) {
|
954
951
|
m = null;
|
955
|
-
r =
|
952
|
+
r = $global_multiline_regexp(sep);
|
956
953
|
|
957
954
|
while (true) {
|
958
955
|
_m = r.exec(self);
|
@@ -966,13 +963,13 @@ class String < `String`
|
|
966
963
|
if (m === null) {
|
967
964
|
i = -1;
|
968
965
|
} else {
|
969
|
-
#{MatchData.new `r`, `m`};
|
966
|
+
#{::MatchData.new `r`, `m`};
|
970
967
|
sep = m[0];
|
971
968
|
i = m.index;
|
972
969
|
}
|
973
970
|
|
974
971
|
} else {
|
975
|
-
sep = $coerce_to(sep, #{String}, 'to_str');
|
972
|
+
sep = $coerce_to(sep, #{::String}, 'to_str');
|
976
973
|
i = self.lastIndexOf(sep);
|
977
974
|
}
|
978
975
|
|
@@ -999,14 +996,14 @@ class String < `String`
|
|
999
996
|
match;
|
1000
997
|
|
1001
998
|
if (pattern.$$is_regexp) {
|
1002
|
-
pattern =
|
999
|
+
pattern = $global_multiline_regexp(pattern);
|
1003
1000
|
} else {
|
1004
|
-
pattern = $coerce_to(pattern, #{String}, 'to_str');
|
1001
|
+
pattern = $coerce_to(pattern, #{::String}, 'to_str');
|
1005
1002
|
pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gm');
|
1006
1003
|
}
|
1007
1004
|
|
1008
1005
|
while ((match = pattern.exec(self)) != null) {
|
1009
|
-
match_data = #{MatchData.new `pattern`, `match
|
1006
|
+
match_data = #{::MatchData.new `pattern`, `match`, no_matchdata: no_matchdata};
|
1010
1007
|
if (block === nil) {
|
1011
1008
|
match.length == 1 ? result.push(match[0]) : result.push(#{`match_data`.captures});
|
1012
1009
|
} else {
|
@@ -1023,7 +1020,14 @@ class String < `String`
|
|
1023
1020
|
}
|
1024
1021
|
end
|
1025
1022
|
|
1026
|
-
|
1023
|
+
# We redefine this method on String, as kernel.rb is in strict mode
|
1024
|
+
# so that things like Boolean don't get boxed. For String though -
|
1025
|
+
# we either need to box it to define properties on it, or run it in
|
1026
|
+
# non-strict mode. This is a mess and we need to come back to it
|
1027
|
+
# at a later time.
|
1028
|
+
def singleton_class
|
1029
|
+
`Opal.get_singleton_class(self)`
|
1030
|
+
end
|
1027
1031
|
|
1028
1032
|
def split(pattern = undefined, limit = undefined)
|
1029
1033
|
%x{
|
@@ -1034,7 +1038,7 @@ class String < `String`
|
|
1034
1038
|
if (limit === undefined) {
|
1035
1039
|
limit = 0;
|
1036
1040
|
} else {
|
1037
|
-
limit = #{Opal.coerce_to!(limit, Integer, :to_int)};
|
1041
|
+
limit = #{::Opal.coerce_to!(limit, ::Integer, :to_int)};
|
1038
1042
|
if (limit === 1) {
|
1039
1043
|
return [self];
|
1040
1044
|
}
|
@@ -1051,9 +1055,9 @@ class String < `String`
|
|
1051
1055
|
i, ii;
|
1052
1056
|
|
1053
1057
|
if (pattern.$$is_regexp) {
|
1054
|
-
pattern =
|
1058
|
+
pattern = $global_multiline_regexp(pattern);
|
1055
1059
|
} else {
|
1056
|
-
pattern = $coerce_to(pattern, #{String}, 'to_str').$to_s();
|
1060
|
+
pattern = $coerce_to(pattern, #{::String}, 'to_str').$to_s();
|
1057
1061
|
if (pattern === ' ') {
|
1058
1062
|
pattern = /\s+/gm;
|
1059
1063
|
string = string.replace(/^\s+/, '');
|
@@ -1145,13 +1149,13 @@ class String < `String`
|
|
1145
1149
|
var match = regexp.exec(self);
|
1146
1150
|
|
1147
1151
|
if (match != null && match.index === 0) {
|
1148
|
-
#{$~ = MatchData.new(`regexp`, `match`)};
|
1152
|
+
#{$~ = ::MatchData.new(`regexp`, `match`)};
|
1149
1153
|
return true;
|
1150
1154
|
} else {
|
1151
1155
|
#{$~ = nil}
|
1152
1156
|
}
|
1153
1157
|
} else {
|
1154
|
-
var prefix = $coerce_to(prefixes[i], #{String}, 'to_str').$to_s();
|
1158
|
+
var prefix = $coerce_to(prefixes[i], #{::String}, 'to_str').$to_s();
|
1155
1159
|
|
1156
1160
|
if (self.indexOf(prefix) === 0) {
|
1157
1161
|
return true;
|
@@ -1164,13 +1168,13 @@ class String < `String`
|
|
1164
1168
|
end
|
1165
1169
|
|
1166
1170
|
def strip
|
1167
|
-
`self.replace(
|
1171
|
+
`self.replace(/^[\s\u0000]*|[\s\u0000]*$/g, '')`
|
1168
1172
|
end
|
1169
1173
|
|
1170
1174
|
def sub(pattern, replacement = undefined, &block)
|
1171
1175
|
%x{
|
1172
1176
|
if (!pattern.$$is_regexp) {
|
1173
|
-
pattern = $coerce_to(pattern, #{String}, 'to_str');
|
1177
|
+
pattern = $coerce_to(pattern, #{::String}, 'to_str');
|
1174
1178
|
pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
1175
1179
|
}
|
1176
1180
|
|
@@ -1180,12 +1184,12 @@ class String < `String`
|
|
1180
1184
|
#{$~ = nil}
|
1181
1185
|
result = self.toString();
|
1182
1186
|
} else {
|
1183
|
-
#{MatchData.new `pattern`, `match`}
|
1187
|
+
#{::MatchData.new `pattern`, `match`}
|
1184
1188
|
|
1185
1189
|
if (replacement === undefined) {
|
1186
1190
|
|
1187
1191
|
if (block === nil) {
|
1188
|
-
#{raise ArgumentError, 'wrong number of arguments (1 for 2)'}
|
1192
|
+
#{::Kernel.raise ::ArgumentError, 'wrong number of arguments (1 for 2)'}
|
1189
1193
|
}
|
1190
1194
|
result = self.slice(0, match.index) + block(match[0]) + self.slice(match.index + match[0].length);
|
1191
1195
|
|
@@ -1195,7 +1199,7 @@ class String < `String`
|
|
1195
1199
|
|
1196
1200
|
} else {
|
1197
1201
|
|
1198
|
-
replacement = $coerce_to(replacement, #{String}, 'to_str');
|
1202
|
+
replacement = $coerce_to(replacement, #{::String}, 'to_str');
|
1199
1203
|
|
1200
1204
|
replacement = replacement.replace(/([\\]+)([0-9+&`'])/g, function (original, slashes, command) {
|
1201
1205
|
if (slashes.length % 2 === 0) {
|
@@ -1224,11 +1228,9 @@ class String < `String`
|
|
1224
1228
|
}
|
1225
1229
|
end
|
1226
1230
|
|
1227
|
-
alias succ next
|
1228
|
-
|
1229
1231
|
def sum(n = 16)
|
1230
1232
|
%x{
|
1231
|
-
n = $coerce_to(n, #{Integer}, 'to_int');
|
1233
|
+
n = $coerce_to(n, #{::Integer}, 'to_int');
|
1232
1234
|
|
1233
1235
|
var result = 0,
|
1234
1236
|
length = self.length,
|
@@ -1281,10 +1283,10 @@ class String < `String`
|
|
1281
1283
|
%x{
|
1282
1284
|
var result,
|
1283
1285
|
string = self.toLowerCase(),
|
1284
|
-
radix = $coerce_to(base, #{Integer}, 'to_int');
|
1286
|
+
radix = $coerce_to(base, #{::Integer}, 'to_int');
|
1285
1287
|
|
1286
1288
|
if (radix === 1 || radix < 0 || radix > 36) {
|
1287
|
-
#{raise ArgumentError, "invalid radix #{`radix`}"}
|
1289
|
+
#{::Kernel.raise ::ArgumentError, "invalid radix #{`radix`}"}
|
1288
1290
|
}
|
1289
1291
|
|
1290
1292
|
if (/^\s*_/.test(string)) {
|
@@ -1339,10 +1341,10 @@ class String < `String`
|
|
1339
1341
|
def to_proc
|
1340
1342
|
method_name = '$' + `self.valueOf()`
|
1341
1343
|
|
1342
|
-
proc do |*args, &block|
|
1344
|
+
::Kernel.proc do |*args, &block|
|
1343
1345
|
%x{
|
1344
1346
|
if (args.length === 0) {
|
1345
|
-
#{raise ArgumentError, 'no receiver given'}
|
1347
|
+
#{::Kernel.raise ::ArgumentError, 'no receiver given'}
|
1346
1348
|
}
|
1347
1349
|
|
1348
1350
|
var recv = args[0];
|
@@ -1372,14 +1374,10 @@ class String < `String`
|
|
1372
1374
|
`self.toString()`
|
1373
1375
|
end
|
1374
1376
|
|
1375
|
-
alias to_str to_s
|
1376
|
-
|
1377
|
-
alias to_sym intern
|
1378
|
-
|
1379
1377
|
def tr(from, to)
|
1380
1378
|
%x{
|
1381
|
-
from = $coerce_to(from, #{String}, 'to_str').$to_s();
|
1382
|
-
to = $coerce_to(to, #{String}, 'to_str').$to_s();
|
1379
|
+
from = $coerce_to(from, #{::String}, 'to_str').$to_s();
|
1380
|
+
to = $coerce_to(to, #{::String}, 'to_str').$to_s();
|
1383
1381
|
|
1384
1382
|
if (from.length == 0 || from === to) {
|
1385
1383
|
return self;
|
@@ -1426,7 +1424,7 @@ class String < `String`
|
|
1426
1424
|
start = last_from.charCodeAt(0);
|
1427
1425
|
end = ch.charCodeAt(0);
|
1428
1426
|
if (start > end) {
|
1429
|
-
#{raise ArgumentError, "invalid range \"#{`String.fromCharCode(start)`}-#{`String.fromCharCode(end)`}\" in string transliteration"}
|
1427
|
+
#{::Kernel.raise ::ArgumentError, "invalid range \"#{`String.fromCharCode(start)`}-#{`String.fromCharCode(end)`}\" in string transliteration"}
|
1430
1428
|
}
|
1431
1429
|
for (c = start + 1; c < end; c++) {
|
1432
1430
|
from_chars_expanded.push(String.fromCharCode(c));
|
@@ -1475,7 +1473,7 @@ class String < `String`
|
|
1475
1473
|
start = last_to.charCodeAt(0);
|
1476
1474
|
end = ch.charCodeAt(0);
|
1477
1475
|
if (start > end) {
|
1478
|
-
#{raise ArgumentError, "invalid range \"#{`String.fromCharCode(start)`}-#{`String.fromCharCode(end)`}\" in string transliteration"}
|
1476
|
+
#{::Kernel.raise ::ArgumentError, "invalid range \"#{`String.fromCharCode(start)`}-#{`String.fromCharCode(end)`}\" in string transliteration"}
|
1479
1477
|
}
|
1480
1478
|
for (c = start + 1; c < end; c++) {
|
1481
1479
|
to_chars_expanded.push(String.fromCharCode(c));
|
@@ -1523,8 +1521,8 @@ class String < `String`
|
|
1523
1521
|
|
1524
1522
|
def tr_s(from, to)
|
1525
1523
|
%x{
|
1526
|
-
from = $coerce_to(from, #{String}, 'to_str').$to_s();
|
1527
|
-
to = $coerce_to(to, #{String}, 'to_str').$to_s();
|
1524
|
+
from = $coerce_to(from, #{::String}, 'to_str').$to_s();
|
1525
|
+
to = $coerce_to(to, #{::String}, 'to_str').$to_s();
|
1528
1526
|
|
1529
1527
|
if (from.length == 0) {
|
1530
1528
|
return self;
|
@@ -1571,7 +1569,7 @@ class String < `String`
|
|
1571
1569
|
start = last_from.charCodeAt(0);
|
1572
1570
|
end = ch.charCodeAt(0);
|
1573
1571
|
if (start > end) {
|
1574
|
-
#{raise ArgumentError, "invalid range \"#{`String.fromCharCode(start)`}-#{`String.fromCharCode(end)`}\" in string transliteration"}
|
1572
|
+
#{::Kernel.raise ::ArgumentError, "invalid range \"#{`String.fromCharCode(start)`}-#{`String.fromCharCode(end)`}\" in string transliteration"}
|
1575
1573
|
}
|
1576
1574
|
for (c = start + 1; c < end; c++) {
|
1577
1575
|
from_chars_expanded.push(String.fromCharCode(c));
|
@@ -1620,7 +1618,7 @@ class String < `String`
|
|
1620
1618
|
start = last_from.charCodeAt(0);
|
1621
1619
|
end = ch.charCodeAt(0);
|
1622
1620
|
if (start > end) {
|
1623
|
-
#{raise ArgumentError, "invalid range \"#{`String.fromCharCode(start)`}-#{`String.fromCharCode(end)`}\" in string transliteration"}
|
1621
|
+
#{::Kernel.raise ::ArgumentError, "invalid range \"#{`String.fromCharCode(start)`}-#{`String.fromCharCode(end)`}\" in string transliteration"}
|
1624
1622
|
}
|
1625
1623
|
for (c = start + 1; c < end; c++) {
|
1626
1624
|
to_chars_expanded.push(String.fromCharCode(c));
|
@@ -1693,7 +1691,7 @@ class String < `String`
|
|
1693
1691
|
%x{
|
1694
1692
|
var a, b, s = self.toString();
|
1695
1693
|
|
1696
|
-
stop = $coerce_to(stop, #{String}, 'to_str');
|
1694
|
+
stop = $coerce_to(stop, #{::String}, 'to_str');
|
1697
1695
|
|
1698
1696
|
if (s.length === 1 && stop.length === 1) {
|
1699
1697
|
|
@@ -1758,7 +1756,7 @@ class String < `String`
|
|
1758
1756
|
char_code_from = set.charCodeAt(i - 1);
|
1759
1757
|
char_code_upto = set.charCodeAt(i + 1);
|
1760
1758
|
if (char_code_from > char_code_upto) {
|
1761
|
-
#{raise ArgumentError, "invalid range \"#{`char_code_from`}-#{`char_code_upto`}\" in string transliteration"}
|
1759
|
+
#{::Kernel.raise ::ArgumentError, "invalid range \"#{`char_code_from`}-#{`char_code_upto`}\" in string transliteration"}
|
1762
1760
|
}
|
1763
1761
|
for (char_code = char_code_from + 1; char_code < char_code_upto + 1; char_code++) {
|
1764
1762
|
result += String.fromCharCode(char_code);
|
@@ -1794,7 +1792,7 @@ class String < `String`
|
|
1794
1792
|
neg_intersection = '';
|
1795
1793
|
|
1796
1794
|
for (i = 0, len = sets.length; i < len; i++) {
|
1797
|
-
set = $coerce_to(sets[i], #{String}, 'to_str');
|
1795
|
+
set = $coerce_to(sets[i], #{::String}, 'to_str');
|
1798
1796
|
neg = (set.charAt(0) === '^' && set.length > 1);
|
1799
1797
|
set = explode_sequences_in_character_set(neg ? set.slice(1) : set);
|
1800
1798
|
if (neg) {
|
@@ -1817,11 +1815,11 @@ class String < `String`
|
|
1817
1815
|
}
|
1818
1816
|
|
1819
1817
|
if (pos_intersection.length > 0) {
|
1820
|
-
return '[' + #{Regexp.escape(`pos_intersection`)} + ']';
|
1818
|
+
return '[' + #{::Regexp.escape(`pos_intersection`)} + ']';
|
1821
1819
|
}
|
1822
1820
|
|
1823
1821
|
if (neg_intersection.length > 0) {
|
1824
|
-
return '[^' + #{Regexp.escape(`neg_intersection`)} + ']';
|
1822
|
+
return '[^' + #{::Regexp.escape(`neg_intersection`)} + ']';
|
1825
1823
|
}
|
1826
1824
|
|
1827
1825
|
return null;
|
@@ -1837,7 +1835,7 @@ class String < `String`
|
|
1837
1835
|
end
|
1838
1836
|
|
1839
1837
|
def unicode_normalize(form = :nfc)
|
1840
|
-
raise ArgumentError, "Invalid normalization form #{form}" unless %i[nfc nfd nfkc nfkd].include?(form)
|
1838
|
+
::Kernel.raise ::ArgumentError, "Invalid normalization form #{form}" unless %i[nfc nfd nfkc nfkd].include?(form)
|
1841
1839
|
`self.normalize(#{form.upcase})`
|
1842
1840
|
end
|
1843
1841
|
|
@@ -1846,11 +1844,11 @@ class String < `String`
|
|
1846
1844
|
end
|
1847
1845
|
|
1848
1846
|
def unpack(format)
|
1849
|
-
raise "To use String#unpack, you must first require 'corelib/string/unpack'."
|
1847
|
+
::Kernel.raise "To use String#unpack, you must first require 'corelib/string/unpack'."
|
1850
1848
|
end
|
1851
1849
|
|
1852
1850
|
def unpack1(format)
|
1853
|
-
raise "To use String#unpack1, you must first require 'corelib/string/unpack'."
|
1851
|
+
::Kernel.raise "To use String#unpack1, you must first require 'corelib/string/unpack'."
|
1854
1852
|
end
|
1855
1853
|
|
1856
1854
|
def freeze
|
@@ -1861,8 +1859,6 @@ class String < `String`
|
|
1861
1859
|
}
|
1862
1860
|
end
|
1863
1861
|
|
1864
|
-
alias +@ dup
|
1865
|
-
|
1866
1862
|
def -@
|
1867
1863
|
%x{
|
1868
1864
|
if (typeof self === 'string') return self;
|
@@ -1876,7 +1872,18 @@ class String < `String`
|
|
1876
1872
|
`typeof self === 'string' || self.$$frozen === true`
|
1877
1873
|
end
|
1878
1874
|
|
1879
|
-
|
1875
|
+
alias +@ dup
|
1876
|
+
alias === ==
|
1877
|
+
alias byteslice []
|
1878
|
+
alias eql? ==
|
1879
|
+
alias equal? ===
|
1880
|
+
alias object_id __id__
|
1881
|
+
alias slice []
|
1882
|
+
alias succ next
|
1883
|
+
alias to_str to_s
|
1884
|
+
alias to_sym intern
|
1885
|
+
|
1886
|
+
::Opal.pristine self, :initialize
|
1880
1887
|
end
|
1881
1888
|
|
1882
1889
|
Symbol = String
|