opal 0.8.1 → 0.9.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -2
- data/.gitmodules +3 -3
- data/.jshintrc +17 -20
- data/.travis.yml +22 -11
- data/CHANGELOG.md +51 -1
- data/CODE_OF_CONDUCT.md +15 -0
- data/CONTRIBUTING.md +125 -9
- data/Gemfile +1 -1
- data/Guardfile +2 -2
- data/README.md +95 -29
- data/Rakefile +1 -1
- data/benchmark/benchmarks +103 -0
- data/benchmark/bm_array_flatten.rb +9 -0
- data/benchmark/bm_array_intersection_numbers.rb +7 -0
- data/benchmark/bm_array_intersection_objects.rb +7 -0
- data/benchmark/bm_array_intersection_strings.rb +7 -0
- data/benchmark/bm_array_join_ary.rb +9 -0
- data/benchmark/bm_array_minus_numbers.rb +7 -0
- data/benchmark/bm_array_minus_objects.rb +7 -0
- data/benchmark/bm_array_minus_strings.rb +7 -0
- data/benchmark/bm_array_union_numbers.rb +7 -0
- data/benchmark/bm_array_union_objects.rb +7 -0
- data/benchmark/bm_array_union_strings.rb +7 -0
- data/benchmark/bm_array_uniq_bang_numbers.rb +5 -0
- data/benchmark/bm_array_uniq_bang_objects.rb +5 -0
- data/benchmark/bm_array_uniq_bang_strings.rb +5 -0
- data/benchmark/bm_array_uniq_numbers.rb +5 -0
- data/benchmark/bm_array_uniq_objects.rb +5 -0
- data/benchmark/bm_array_uniq_strings.rb +5 -0
- data/benchmark/bm_dispatch_bind_table.rb +57 -0
- data/benchmark/bm_dispatch_code_gen.rb +65 -0
- data/benchmark/bm_dispatch_code_gen_if.rb +64 -0
- data/benchmark/bm_dispatch_hardcoded.rb +44 -0
- data/benchmark/bm_dispatch_send.rb +38 -0
- data/benchmark/bm_dispatch_send_table.rb +57 -0
- data/benchmark/bm_hash_assoc_object.rb +11 -0
- data/benchmark/bm_hash_assoc_string.rb +9 -0
- data/benchmark/bm_hash_clone_object.rb +9 -0
- data/benchmark/bm_hash_clone_string.rb +9 -0
- data/benchmark/bm_hash_delete_object.rb +11 -0
- data/benchmark/bm_hash_delete_string.rb +9 -0
- data/benchmark/bm_hash_each_key_object.rb +9 -0
- data/benchmark/bm_hash_each_key_string.rb +9 -0
- data/benchmark/bm_hash_each_object.rb +9 -0
- data/benchmark/bm_hash_each_string.rb +9 -0
- data/benchmark/bm_hash_each_value_object.rb +9 -0
- data/benchmark/bm_hash_each_value_string.rb +9 -0
- data/benchmark/bm_hash_element_reference_object.rb +11 -0
- data/benchmark/bm_hash_element_reference_string.rb +9 -0
- data/benchmark/bm_hash_element_set_object.rb +5 -0
- data/benchmark/bm_hash_element_set_string.rb +5 -0
- data/benchmark/bm_hash_equal_value_object.rb +14 -0
- data/benchmark/bm_hash_equal_value_string.rb +11 -0
- data/benchmark/bm_hash_fetch_object.rb +11 -0
- data/benchmark/bm_hash_fetch_string.rb +9 -0
- data/benchmark/bm_hash_flatten_object.rb +9 -0
- data/benchmark/bm_hash_flatten_string.rb +9 -0
- data/benchmark/bm_hash_has_key_object.rb +11 -0
- data/benchmark/bm_hash_has_key_string.rb +9 -0
- data/benchmark/bm_hash_has_value_object.rb +9 -0
- data/benchmark/bm_hash_has_value_string.rb +9 -0
- data/benchmark/bm_hash_hash_object.rb +9 -0
- data/benchmark/bm_hash_hash_string.rb +9 -0
- data/benchmark/bm_hash_inspect_object.rb +9 -0
- data/benchmark/bm_hash_inspect_string.rb +9 -0
- data/benchmark/bm_hash_invert_object.rb +9 -0
- data/benchmark/bm_hash_invert_string.rb +9 -0
- data/benchmark/bm_hash_keep_if_object.rb +9 -0
- data/benchmark/bm_hash_keep_if_string.rb +9 -0
- data/benchmark/bm_hash_key_object.rb +9 -0
- data/benchmark/bm_hash_key_string.rb +9 -0
- data/benchmark/bm_hash_keys_object.rb +9 -0
- data/benchmark/bm_hash_keys_string.rb +9 -0
- data/benchmark/bm_hash_literal_mixed_large.rb +3 -0
- data/benchmark/bm_hash_literal_mixed_small.rb +3 -0
- data/benchmark/bm_hash_literal_object_large.rb +4 -0
- data/benchmark/bm_hash_literal_object_small.rb +3 -0
- data/benchmark/bm_hash_literal_string_large.rb +4 -0
- data/benchmark/bm_hash_literal_string_small.rb +3 -0
- data/benchmark/bm_hash_merge_object.rb +22 -0
- data/benchmark/bm_hash_merge_string.rb +18 -0
- data/benchmark/bm_hash_rassoc_object.rb +9 -0
- data/benchmark/bm_hash_rassoc_string.rb +9 -0
- data/benchmark/bm_hash_rehash_object.rb +9 -0
- data/benchmark/bm_hash_rehash_string.rb +9 -0
- data/benchmark/bm_hash_reject_bang_object.rb +9 -0
- data/benchmark/bm_hash_reject_bang_string.rb +9 -0
- data/benchmark/bm_hash_reject_object.rb +9 -0
- data/benchmark/bm_hash_reject_string.rb +9 -0
- data/benchmark/bm_hash_replace_object.rb +18 -0
- data/benchmark/bm_hash_replace_string.rb +14 -0
- data/benchmark/bm_hash_select_bang_object.rb +9 -0
- data/benchmark/bm_hash_select_bang_string.rb +9 -0
- data/benchmark/bm_hash_select_object.rb +9 -0
- data/benchmark/bm_hash_select_string.rb +9 -0
- data/benchmark/bm_hash_shift_object.rb +10 -0
- data/benchmark/bm_hash_shift_string.rb +10 -0
- data/benchmark/bm_hash_to_a_object.rb +9 -0
- data/benchmark/bm_hash_to_a_string.rb +9 -0
- data/benchmark/bm_hash_to_h_object.rb +10 -0
- data/benchmark/bm_hash_to_h_string.rb +10 -0
- data/benchmark/bm_hash_values_object.rb +9 -0
- data/benchmark/bm_hash_values_string.rb +9 -0
- data/benchmark/run.rb +48 -0
- data/bin/opal-mspec +1 -1
- data/bin/opal-repl +4 -4
- data/docs/compiled_ruby.md +214 -56
- data/docs/configuring_gems.md +2 -2
- data/docs/faq.md +2 -2
- data/docs/getting_started.md +19 -2
- data/docs/jquery.md +5 -5
- data/docs/opal_parser.md +53 -0
- data/docs/unsupported_features.md +2 -2
- data/docs/upgrading.md +22 -0
- data/docs/using_sprockets.md +15 -0
- data/examples/rack/config.ru +13 -0
- data/examples/sinatra/config.ru +4 -5
- data/lib/mspec/opal/runner.rb +54 -11
- data/lib/opal.rb +1 -1
- data/lib/opal/builder.rb +1 -1
- data/lib/opal/builder_processors.rb +1 -1
- data/lib/opal/cli.rb +17 -13
- data/lib/opal/cli_options.rb +1 -1
- data/lib/opal/compiler.rb +12 -0
- data/lib/opal/config.rb +4 -0
- data/lib/opal/nodes/arglist.rb +5 -7
- data/lib/opal/nodes/call.rb +6 -1
- data/lib/opal/nodes/call_special.rb +74 -0
- data/lib/opal/nodes/def.rb +35 -28
- data/lib/opal/nodes/definitions.rb +3 -5
- data/lib/opal/nodes/for.rb +13 -0
- data/lib/opal/nodes/helpers.rb +15 -1
- data/lib/opal/nodes/if.rb +5 -5
- data/lib/opal/nodes/iter.rb +6 -1
- data/lib/opal/nodes/literal.rb +1 -1
- data/lib/opal/nodes/logic.rb +2 -2
- data/lib/opal/nodes/masgn.rb +1 -2
- data/lib/opal/nodes/module.rb +2 -1
- data/lib/opal/nodes/rescue.rb +10 -1
- data/lib/opal/nodes/scope.rb +8 -2
- data/lib/opal/nodes/singleton_class.rb +1 -1
- data/lib/opal/nodes/top.rb +11 -0
- data/lib/opal/nodes/variables.rb +4 -4
- data/lib/opal/parser.rb +21 -3
- data/lib/opal/parser/grammar.rb +3115 -2961
- data/lib/opal/parser/grammar.y +29 -6
- data/lib/opal/parser/lexer.rb +18 -8
- data/lib/opal/sprockets.rb +85 -0
- data/lib/opal/sprockets/processor.rb +11 -35
- data/lib/opal/sprockets/server.rb +3 -15
- data/lib/opal/version.rb +2 -2
- data/opal.gemspec +4 -4
- data/opal/README.md +9 -0
- data/opal/corelib/array.rb +433 -181
- data/opal/corelib/basic_object.rb +48 -4
- data/opal/corelib/boolean.rb +15 -6
- data/opal/corelib/class.rb +6 -5
- data/opal/corelib/comparable.rb +12 -0
- data/opal/corelib/complex.rb +282 -0
- data/opal/corelib/constants.rb +9 -0
- data/opal/corelib/enumerable.rb +83 -34
- data/opal/corelib/enumerator.rb +3 -1
- data/opal/corelib/error.rb +49 -10
- data/opal/corelib/file.rb +1 -0
- data/opal/corelib/hash.rb +353 -577
- data/opal/corelib/helpers.rb +20 -0
- data/opal/corelib/kernel.rb +114 -59
- data/opal/corelib/math.rb +470 -0
- data/opal/corelib/method.rb +11 -2
- data/opal/corelib/module.rb +96 -96
- data/opal/corelib/{nil_class.rb → nil.rb} +20 -1
- data/opal/corelib/number.rb +751 -0
- data/opal/corelib/numeric.rb +77 -437
- data/opal/corelib/proc.rb +81 -1
- data/opal/corelib/process.rb +27 -0
- data/opal/corelib/rational.rb +358 -0
- data/opal/corelib/regexp.rb +156 -27
- data/opal/corelib/runtime.js +724 -335
- data/opal/corelib/string.rb +93 -104
- data/opal/corelib/string/encoding.rb +177 -0
- data/opal/corelib/string/inheritance.rb +2 -0
- data/opal/corelib/struct.rb +105 -18
- data/opal/corelib/time.rb +267 -146
- data/opal/corelib/unsupported.rb +216 -0
- data/opal/corelib/variables.rb +0 -6
- data/opal/opal.rb +8 -22
- data/opal/opal/base.rb +9 -0
- data/opal/opal/mini.rb +17 -0
- data/spec/README.md +1 -1
- data/spec/filters/bugs/array.rb +38 -136
- data/spec/filters/bugs/{basic_object.rb → basicobject.rb} +14 -15
- data/spec/filters/bugs/class.rb +6 -12
- data/spec/filters/bugs/complex.rb +3 -0
- data/spec/filters/bugs/date.rb +162 -10
- data/spec/filters/bugs/enumerable.rb +31 -58
- data/spec/filters/bugs/enumerator.rb +42 -0
- data/spec/filters/bugs/exception.rb +66 -10
- data/spec/filters/bugs/float.rb +17 -0
- data/spec/filters/bugs/hash.rb +11 -97
- data/spec/filters/bugs/inheritance.rb +5 -0
- data/spec/filters/bugs/integer.rb +28 -0
- data/spec/filters/bugs/kernel.rb +304 -12
- data/spec/filters/bugs/language.rb +133 -399
- data/spec/filters/bugs/language_opal.rb +88 -0
- data/spec/filters/bugs/module.rb +203 -62
- data/spec/filters/bugs/numeric.rb +32 -0
- data/spec/filters/bugs/proc.rb +39 -0
- data/spec/filters/bugs/range.rb +148 -0
- data/spec/filters/bugs/regexp.rb +168 -0
- data/spec/filters/bugs/set.rb +46 -3
- data/spec/filters/bugs/singleton.rb +1 -2
- data/spec/filters/bugs/string.rb +59 -90
- data/spec/filters/bugs/strscan.rb +80 -0
- data/spec/filters/bugs/struct.rb +10 -20
- data/spec/filters/bugs/time.rb +17 -184
- data/spec/filters/bugs/unboundmethod.rb +22 -0
- data/spec/filters/unsupported/array.rb +163 -0
- data/spec/filters/unsupported/basicobject.rb +14 -0
- data/spec/filters/unsupported/bignum.rb +46 -0
- data/spec/filters/unsupported/class.rb +4 -0
- data/spec/filters/unsupported/delegator.rb +5 -0
- data/spec/filters/unsupported/enumerable.rb +11 -0
- data/spec/filters/unsupported/enumerator.rb +8 -9
- data/spec/filters/unsupported/fixnum.rb +14 -0
- data/spec/filters/unsupported/float.rb +41 -7
- data/spec/filters/unsupported/freeze.rb +45 -0
- data/spec/filters/unsupported/hash.rb +50 -0
- data/spec/filters/unsupported/integer.rb +3 -0
- data/spec/filters/unsupported/kernel.rb +31 -0
- data/spec/filters/unsupported/language.rb +17 -0
- data/spec/filters/unsupported/matchdata.rb +30 -0
- data/spec/filters/unsupported/math.rb +3 -0
- data/spec/filters/unsupported/module.rb +5 -3
- data/spec/filters/unsupported/pathname.rb +3 -0
- data/spec/filters/unsupported/privacy.rb +136 -0
- data/spec/filters/unsupported/proc.rb +3 -0
- data/spec/filters/unsupported/regexp.rb +59 -0
- data/spec/filters/unsupported/set.rb +4 -0
- data/spec/filters/unsupported/{marshal.rb → singleton.rb} +4 -2
- data/spec/filters/unsupported/{mutable_strings.rb → string.rb} +456 -336
- data/spec/filters/unsupported/struct.rb +3 -0
- data/spec/filters/unsupported/symbol.rb +5 -0
- data/spec/filters/unsupported/taint.rb +16 -0
- data/spec/filters/unsupported/thread.rb +5 -0
- data/spec/filters/unsupported/time.rb +197 -16
- data/spec/lib/cli_spec.rb +14 -4
- data/spec/lib/compiler_spec.rb +9 -1
- data/spec/lib/parser/call_spec.rb +18 -0
- data/spec/lib/parser/not_spec.rb +2 -8
- data/spec/lib/sprockets_spec.rb +24 -0
- data/spec/opal/core/array/intersection_spec.rb +38 -0
- data/spec/opal/core/array/minus_spec.rb +38 -0
- data/spec/opal/core/array/union_spec.rb +38 -0
- data/spec/opal/core/array/uniq_spec.rb +49 -0
- data/spec/opal/core/exception_spec.rb +7 -0
- data/spec/opal/core/fixtures/require_tree_with_dot/file 1.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_with_dot/file 2.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_with_dot/file 3.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_with_dot/index.rb +3 -0
- data/spec/opal/core/hash/internals_spec.rb +332 -0
- data/spec/opal/core/helpers_spec.rb +14 -0
- data/spec/opal/core/kernel/freeze_spec.rb +1 -1
- data/spec/opal/core/kernel/raise_spec.rb +13 -0
- data/spec/opal/core/kernel/require_tree_spec.rb +9 -0
- data/spec/opal/core/language/class_spec.rb +55 -0
- data/spec/opal/core/language/fixtures/send.rb +1 -0
- data/spec/opal/core/language/keyword_arguments_spec.rb +11 -0
- data/spec/opal/core/language/send_spec.rb +5 -0
- data/spec/opal/core/method/to_proc_spec.rb +28 -0
- data/spec/opal/core/module/name_spec.rb +0 -17
- data/spec/opal/core/runtime/bridged_classes_spec.rb +2 -2
- data/spec/opal/core/runtime/eval_spec.rb +1 -1
- data/spec/opal/core/runtime/method_missing_spec.rb +6 -0
- data/spec/opal/core/runtime_spec.rb +51 -0
- data/spec/opal/stdlib/js_spec.rb +66 -0
- data/spec/opal/stdlib/native/hash_spec.rb +36 -0
- data/spec/rubyspecs +152 -273
- data/spec/spec_helper.rb +10 -11
- data/stdlib/base64.rb +9 -9
- data/stdlib/benchmark.rb +551 -4
- data/stdlib/console.rb +94 -0
- data/stdlib/date.rb +1 -1
- data/stdlib/encoding.rb +1 -170
- data/stdlib/js.rb +56 -0
- data/stdlib/json.rb +9 -14
- data/stdlib/math.rb +1 -370
- data/stdlib/native.rb +133 -63
- data/stdlib/nodejs/file.rb +5 -0
- data/stdlib/nodejs/fileutils.rb +13 -6
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/README.md +1 -1
- data/stdlib/opal-parser.rb +1 -2
- data/stdlib/ostruct.rb +65 -6
- data/stdlib/pp.rb +2 -4
- data/stdlib/rbconfig.rb +1 -3
- data/stdlib/strscan.rb +164 -28
- data/tasks/benchmarking.rake +88 -0
- data/tasks/testing.rake +181 -55
- data/{lib/mspec/opal/special_calls.rb → tasks/testing/mspec_special_calls.rb} +1 -1
- data/{lib/mspec/opal/sprockets.js → tasks/testing/phantomjs1-sprockets.js} +17 -6
- data/test/opal/test_keyword.rb +590 -0
- data/vendored-minitest/minitest.rb +2 -2
- data/vendored-minitest/test/unit.rb +5 -0
- metadata +229 -62
- data/benchmarks/operators.rb +0 -11
- data/benchmarks/prova.js.rb +0 -13
- data/docs/libraries.md +0 -36
- data/lib/mspec/opal/new.html.erb +0 -1
- data/lib/mspec/opal/rake_task.rb +0 -248
- data/opal/corelib/match_data.rb +0 -128
- data/spec/filters/bugs/math.rb +0 -95
- data/spec/filters/bugs/nil.rb +0 -7
- data/spec/filters/bugs/opal.rb +0 -9
- data/spec/filters/bugs/regular_expressions.rb +0 -41
- data/spec/filters/bugs/stringscanner.rb +0 -33
- data/spec/filters/unsupported/encoding.rb +0 -102
- data/spec/filters/unsupported/frozen.rb +0 -92
- data/spec/filters/unsupported/hash_compare_by_identity.rb +0 -16
- data/spec/filters/unsupported/integer_size.rb +0 -59
- data/spec/filters/unsupported/method_added.rb +0 -10
- data/spec/filters/unsupported/private_constants.rb +0 -30
- data/spec/filters/unsupported/private_methods.rb +0 -55
- data/spec/filters/unsupported/random.rb +0 -4
- data/spec/filters/unsupported/rational_numbers.rb +0 -4
- data/spec/filters/unsupported/regular_expressions.rb +0 -137
- data/spec/filters/unsupported/ruby_exe.rb +0 -5
- data/spec/filters/unsupported/symbols.rb +0 -17
- data/spec/filters/unsupported/tainted.rb +0 -180
- data/spec/filters/unsupported/trusted.rb +0 -88
- data/stdlib/process.rb +0 -10
- data/tasks/documenting.rake +0 -37
data/opal/corelib/string.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'corelib/comparable'
|
2
|
+
require 'corelib/regexp'
|
2
3
|
|
3
|
-
class String
|
4
|
+
class String < `String`
|
4
5
|
include Comparable
|
5
6
|
|
6
7
|
`def.$$is_string = true`
|
@@ -8,6 +9,7 @@ class String
|
|
8
9
|
def __id__
|
9
10
|
`self.toString()`
|
10
11
|
end
|
12
|
+
|
11
13
|
alias object_id __id__
|
12
14
|
|
13
15
|
def self.try_convert(what)
|
@@ -99,10 +101,6 @@ class String
|
|
99
101
|
end
|
100
102
|
end
|
101
103
|
|
102
|
-
def <<(other)
|
103
|
-
raise NotImplementedError, '#<< not supported. Mutable String methods are not supported in Opal.'
|
104
|
-
end
|
105
|
-
|
106
104
|
def ==(other)
|
107
105
|
%x{
|
108
106
|
if (other.$$is_string) {
|
@@ -130,12 +128,12 @@ class String
|
|
130
128
|
|
131
129
|
def [](index, length = undefined)
|
132
130
|
%x{
|
133
|
-
var size = self.length;
|
131
|
+
var size = self.length, exclude;
|
134
132
|
|
135
133
|
if (index.$$is_range) {
|
136
|
-
|
137
|
-
|
138
|
-
|
134
|
+
exclude = index.exclude;
|
135
|
+
length = #{Opal.coerce_to(`index.end`, Integer, :to_int)};
|
136
|
+
index = #{Opal.coerce_to(`index.begin`, Integer, :to_int)};
|
139
137
|
|
140
138
|
if (Math.abs(index) > size) {
|
141
139
|
return nil;
|
@@ -226,12 +224,12 @@ class String
|
|
226
224
|
}
|
227
225
|
end
|
228
226
|
|
227
|
+
alias byteslice []
|
228
|
+
|
229
229
|
def capitalize
|
230
230
|
`self.charAt(0).toUpperCase() + self.substr(1).toLowerCase()`
|
231
231
|
end
|
232
232
|
|
233
|
-
alias capitalize! <<
|
234
|
-
|
235
233
|
def casecmp(other)
|
236
234
|
other = Opal.coerce_to(other, String, :to_str).to_s
|
237
235
|
%x{
|
@@ -292,8 +290,6 @@ class String
|
|
292
290
|
self
|
293
291
|
end
|
294
292
|
|
295
|
-
alias chomp! <<
|
296
|
-
|
297
293
|
def chop
|
298
294
|
%x{
|
299
295
|
var length = self.length;
|
@@ -311,14 +307,13 @@ class String
|
|
311
307
|
}
|
312
308
|
end
|
313
309
|
|
314
|
-
alias chop! <<
|
315
|
-
|
316
310
|
def chr
|
317
311
|
`self.charAt(0)`
|
318
312
|
end
|
319
313
|
|
320
314
|
def clone
|
321
315
|
copy = `self.slice()`
|
316
|
+
copy.copy_singleton_methods(self)
|
322
317
|
copy.initialize_clone(self)
|
323
318
|
copy
|
324
319
|
end
|
@@ -355,56 +350,79 @@ class String
|
|
355
350
|
}
|
356
351
|
end
|
357
352
|
|
358
|
-
alias dup clone
|
359
|
-
|
360
353
|
def downcase
|
361
354
|
`self.toLowerCase()`
|
362
355
|
end
|
363
356
|
|
364
|
-
alias downcase! <<
|
365
|
-
|
366
357
|
def each_char(&block)
|
367
|
-
return enum_for
|
358
|
+
return enum_for(:each_char){self.size} unless block_given?
|
368
359
|
|
369
360
|
%x{
|
370
361
|
for (var i = 0, length = self.length; i < length; i++) {
|
371
|
-
|
362
|
+
var value = Opal.yield1(block, self.charAt(i));
|
363
|
+
|
364
|
+
if (value === $breaker) {
|
365
|
+
return $breaker.$v;
|
366
|
+
}
|
372
367
|
}
|
373
368
|
}
|
374
369
|
|
375
370
|
self
|
376
371
|
end
|
377
372
|
|
378
|
-
def each_line(separator =
|
373
|
+
def each_line(separator = $/, &block)
|
379
374
|
return enum_for :each_line, separator unless block_given?
|
380
375
|
|
381
376
|
%x{
|
377
|
+
var value;
|
378
|
+
|
382
379
|
if (separator === nil) {
|
383
|
-
|
384
|
-
|
380
|
+
value = Opal.yield1(block, self);
|
381
|
+
|
382
|
+
if (value === $breaker) {
|
383
|
+
return value.$v;
|
384
|
+
}
|
385
|
+
else {
|
386
|
+
return self;
|
387
|
+
}
|
385
388
|
}
|
386
389
|
|
387
390
|
separator = #{Opal.coerce_to(`separator`, String, :to_str)}
|
388
391
|
|
392
|
+
var a, i, n, length, chomped, trailing, splitted;
|
393
|
+
|
389
394
|
if (separator.length === 0) {
|
390
|
-
for (
|
395
|
+
for (a = self.split(/(\n{2,})/), i = 0, n = a.length; i < n; i += 2) {
|
391
396
|
if (a[i] || a[i + 1]) {
|
392
|
-
|
397
|
+
value = Opal.yield1(block, (a[i] || "") + (a[i + 1] || ""));
|
398
|
+
|
399
|
+
if (value === $breaker) {
|
400
|
+
return value.$v;
|
401
|
+
}
|
393
402
|
}
|
394
403
|
}
|
404
|
+
|
395
405
|
return self;
|
396
406
|
}
|
397
407
|
|
398
|
-
|
399
|
-
|
400
|
-
|
408
|
+
chomped = #{chomp(separator)};
|
409
|
+
trailing = self.length != chomped.length;
|
410
|
+
splitted = chomped.split(separator);
|
401
411
|
|
402
|
-
for (
|
412
|
+
for (i = 0, length = splitted.length; i < length; i++) {
|
403
413
|
if (i < length - 1 || trailing) {
|
404
|
-
|
414
|
+
value = Opal.yield1(block, splitted[i] + separator);
|
415
|
+
|
416
|
+
if (value === $breaker) {
|
417
|
+
return value.$v;
|
418
|
+
}
|
405
419
|
}
|
406
420
|
else {
|
407
|
-
|
421
|
+
value = Opal.yield1(block, splitted[i]);
|
422
|
+
|
423
|
+
if (value === $breaker) {
|
424
|
+
return value.$v;
|
425
|
+
}
|
408
426
|
}
|
409
427
|
}
|
410
428
|
}
|
@@ -436,6 +454,10 @@ class String
|
|
436
454
|
|
437
455
|
def gsub(pattern, replacement = undefined, &block)
|
438
456
|
%x{
|
457
|
+
if (replacement === undefined && block === nil) {
|
458
|
+
#{return enum_for :gsub, pattern}
|
459
|
+
}
|
460
|
+
|
439
461
|
var result = '', match_data = nil, index = 0, match, _replacement;
|
440
462
|
|
441
463
|
if (pattern.$$is_regexp) {
|
@@ -457,9 +479,6 @@ class String
|
|
457
479
|
match_data = #{MatchData.new `pattern`, `match`};
|
458
480
|
|
459
481
|
if (replacement === undefined) {
|
460
|
-
if (block === nil) {
|
461
|
-
#{raise ArgumentError, 'wrong number of arguments (1 for 2)'}
|
462
|
-
}
|
463
482
|
_replacement = block(match[0]);
|
464
483
|
}
|
465
484
|
else if (replacement.$$is_hash) {
|
@@ -504,8 +523,6 @@ class String
|
|
504
523
|
}
|
505
524
|
end
|
506
525
|
|
507
|
-
alias gsub! <<
|
508
|
-
|
509
526
|
def hash
|
510
527
|
`self.toString()`
|
511
528
|
end
|
@@ -638,8 +655,6 @@ class String
|
|
638
655
|
`self.replace(/^\s*/, '')`
|
639
656
|
end
|
640
657
|
|
641
|
-
alias lstrip! <<
|
642
|
-
|
643
658
|
def match(pattern, pos = undefined, &block)
|
644
659
|
if String === pattern || pattern.respond_to?(:to_str)
|
645
660
|
pattern = Regexp.new(pattern.to_str)
|
@@ -722,8 +737,6 @@ class String
|
|
722
737
|
}
|
723
738
|
end
|
724
739
|
|
725
|
-
alias next! <<
|
726
|
-
|
727
740
|
def oct
|
728
741
|
%x{
|
729
742
|
var result,
|
@@ -805,8 +818,6 @@ class String
|
|
805
818
|
`self.split('').reverse().join('')`
|
806
819
|
end
|
807
820
|
|
808
|
-
alias reverse! <<
|
809
|
-
|
810
821
|
def rindex(search, offset = undefined)
|
811
822
|
%x{
|
812
823
|
var i, m, r, _m;
|
@@ -950,7 +961,6 @@ class String
|
|
950
961
|
alias size length
|
951
962
|
|
952
963
|
alias slice []
|
953
|
-
alias slice! <<
|
954
964
|
|
955
965
|
def split(pattern = undefined, limit = undefined)
|
956
966
|
%x{
|
@@ -1050,8 +1060,6 @@ class String
|
|
1050
1060
|
}
|
1051
1061
|
end
|
1052
1062
|
|
1053
|
-
alias squeeze! <<
|
1054
|
-
|
1055
1063
|
def start_with?(*prefixes)
|
1056
1064
|
%x{
|
1057
1065
|
for (var i = 0, length = prefixes.length; i < length; i++) {
|
@@ -1070,8 +1078,6 @@ class String
|
|
1070
1078
|
`self.replace(/^\s*/, '').replace(/[\s\u0000]*$/, '')`
|
1071
1079
|
end
|
1072
1080
|
|
1073
|
-
alias strip! <<
|
1074
|
-
|
1075
1081
|
def sub(pattern, replacement = undefined, &block)
|
1076
1082
|
%x{
|
1077
1083
|
if (!pattern.$$is_regexp) {
|
@@ -1124,10 +1130,7 @@ class String
|
|
1124
1130
|
}
|
1125
1131
|
end
|
1126
1132
|
|
1127
|
-
alias sub! <<
|
1128
|
-
|
1129
1133
|
alias succ next
|
1130
|
-
alias succ! <<
|
1131
1134
|
|
1132
1135
|
def sum(n = 16)
|
1133
1136
|
%x{
|
@@ -1163,8 +1166,6 @@ class String
|
|
1163
1166
|
}
|
1164
1167
|
end
|
1165
1168
|
|
1166
|
-
alias swapcase! <<
|
1167
|
-
|
1168
1169
|
def to_f
|
1169
1170
|
%x{
|
1170
1171
|
if (self.charAt(0) === '_') {
|
@@ -1268,6 +1269,7 @@ class String
|
|
1268
1269
|
return self;
|
1269
1270
|
}
|
1270
1271
|
|
1272
|
+
var i, in_range, c, ch, start, end, length;
|
1271
1273
|
var subs = {};
|
1272
1274
|
var from_chars = from.split('');
|
1273
1275
|
var from_length = from_chars.length;
|
@@ -1285,9 +1287,9 @@ class String
|
|
1285
1287
|
|
1286
1288
|
var from_chars_expanded = [];
|
1287
1289
|
var last_from = null;
|
1288
|
-
|
1289
|
-
for (
|
1290
|
-
|
1290
|
+
in_range = false;
|
1291
|
+
for (i = 0; i < from_length; i++) {
|
1292
|
+
ch = from_chars[i];
|
1291
1293
|
if (last_from == null) {
|
1292
1294
|
last_from = ch;
|
1293
1295
|
from_chars_expanded.push(ch);
|
@@ -1305,12 +1307,12 @@ class String
|
|
1305
1307
|
}
|
1306
1308
|
}
|
1307
1309
|
else if (in_range) {
|
1308
|
-
|
1309
|
-
|
1310
|
+
start = last_from.charCodeAt(0);
|
1311
|
+
end = ch.charCodeAt(0);
|
1310
1312
|
if (start > end) {
|
1311
1313
|
#{raise ArgumentError, "invalid range \"#{`String.fromCharCode(start)`}-#{`String.fromCharCode(end)`}\" in string transliteration"}
|
1312
1314
|
}
|
1313
|
-
for (
|
1315
|
+
for (c = start + 1; c < end; c++) {
|
1314
1316
|
from_chars_expanded.push(String.fromCharCode(c));
|
1315
1317
|
}
|
1316
1318
|
from_chars_expanded.push(ch);
|
@@ -1326,7 +1328,7 @@ class String
|
|
1326
1328
|
from_length = from_chars.length;
|
1327
1329
|
|
1328
1330
|
if (inverse) {
|
1329
|
-
for (
|
1331
|
+
for (i = 0; i < from_length; i++) {
|
1330
1332
|
subs[from_chars[i]] = true;
|
1331
1333
|
}
|
1332
1334
|
}
|
@@ -1334,9 +1336,9 @@ class String
|
|
1334
1336
|
if (to_length > 0) {
|
1335
1337
|
var to_chars_expanded = [];
|
1336
1338
|
var last_to = null;
|
1337
|
-
|
1338
|
-
for (
|
1339
|
-
|
1339
|
+
in_range = false;
|
1340
|
+
for (i = 0; i < to_length; i++) {
|
1341
|
+
ch = to_chars[i];
|
1340
1342
|
if (last_from == null) {
|
1341
1343
|
last_from = ch;
|
1342
1344
|
to_chars_expanded.push(ch);
|
@@ -1354,12 +1356,12 @@ class String
|
|
1354
1356
|
}
|
1355
1357
|
}
|
1356
1358
|
else if (in_range) {
|
1357
|
-
|
1358
|
-
|
1359
|
+
start = last_from.charCodeAt(0);
|
1360
|
+
end = ch.charCodeAt(0);
|
1359
1361
|
if (start > end) {
|
1360
1362
|
#{raise ArgumentError, "invalid range \"#{`String.fromCharCode(start)`}-#{`String.fromCharCode(end)`}\" in string transliteration"}
|
1361
1363
|
}
|
1362
|
-
for (
|
1364
|
+
for (c = start + 1; c < end; c++) {
|
1363
1365
|
to_chars_expanded.push(String.fromCharCode(c));
|
1364
1366
|
}
|
1365
1367
|
to_chars_expanded.push(ch);
|
@@ -1378,19 +1380,19 @@ class String
|
|
1378
1380
|
var length_diff = from_length - to_length;
|
1379
1381
|
if (length_diff > 0) {
|
1380
1382
|
var pad_char = (to_length > 0 ? to_chars[to_length - 1] : '');
|
1381
|
-
for (
|
1383
|
+
for (i = 0; i < length_diff; i++) {
|
1382
1384
|
to_chars.push(pad_char);
|
1383
1385
|
}
|
1384
1386
|
}
|
1385
1387
|
|
1386
|
-
for (
|
1388
|
+
for (i = 0; i < from_length; i++) {
|
1387
1389
|
subs[from_chars[i]] = to_chars[i];
|
1388
1390
|
}
|
1389
1391
|
}
|
1390
1392
|
|
1391
1393
|
var new_str = ''
|
1392
|
-
for (
|
1393
|
-
|
1394
|
+
for (i = 0, length = self.length; i < length; i++) {
|
1395
|
+
ch = self.charAt(i);
|
1394
1396
|
var sub = subs[ch];
|
1395
1397
|
if (inverse) {
|
1396
1398
|
new_str += (sub == null ? global_sub : ch);
|
@@ -1403,8 +1405,6 @@ class String
|
|
1403
1405
|
}
|
1404
1406
|
end
|
1405
1407
|
|
1406
|
-
alias tr! <<
|
1407
|
-
|
1408
1408
|
def tr_s(from, to)
|
1409
1409
|
from = Opal.coerce_to(from, String, :to_str).to_s
|
1410
1410
|
to = Opal.coerce_to(to, String, :to_str).to_s
|
@@ -1413,6 +1413,7 @@ class String
|
|
1413
1413
|
return self;
|
1414
1414
|
}
|
1415
1415
|
|
1416
|
+
var i, in_range, c, ch, start, end, length;
|
1416
1417
|
var subs = {};
|
1417
1418
|
var from_chars = from.split('');
|
1418
1419
|
var from_length = from_chars.length;
|
@@ -1430,9 +1431,9 @@ class String
|
|
1430
1431
|
|
1431
1432
|
var from_chars_expanded = [];
|
1432
1433
|
var last_from = null;
|
1433
|
-
|
1434
|
-
for (
|
1435
|
-
|
1434
|
+
in_range = false;
|
1435
|
+
for (i = 0; i < from_length; i++) {
|
1436
|
+
ch = from_chars[i];
|
1436
1437
|
if (last_from == null) {
|
1437
1438
|
last_from = ch;
|
1438
1439
|
from_chars_expanded.push(ch);
|
@@ -1450,12 +1451,12 @@ class String
|
|
1450
1451
|
}
|
1451
1452
|
}
|
1452
1453
|
else if (in_range) {
|
1453
|
-
|
1454
|
-
|
1454
|
+
start = last_from.charCodeAt(0);
|
1455
|
+
end = ch.charCodeAt(0);
|
1455
1456
|
if (start > end) {
|
1456
1457
|
#{raise ArgumentError, "invalid range \"#{`String.fromCharCode(start)`}-#{`String.fromCharCode(end)`}\" in string transliteration"}
|
1457
1458
|
}
|
1458
|
-
for (
|
1459
|
+
for (c = start + 1; c < end; c++) {
|
1459
1460
|
from_chars_expanded.push(String.fromCharCode(c));
|
1460
1461
|
}
|
1461
1462
|
from_chars_expanded.push(ch);
|
@@ -1471,7 +1472,7 @@ class String
|
|
1471
1472
|
from_length = from_chars.length;
|
1472
1473
|
|
1473
1474
|
if (inverse) {
|
1474
|
-
for (
|
1475
|
+
for (i = 0; i < from_length; i++) {
|
1475
1476
|
subs[from_chars[i]] = true;
|
1476
1477
|
}
|
1477
1478
|
}
|
@@ -1479,9 +1480,9 @@ class String
|
|
1479
1480
|
if (to_length > 0) {
|
1480
1481
|
var to_chars_expanded = [];
|
1481
1482
|
var last_to = null;
|
1482
|
-
|
1483
|
-
for (
|
1484
|
-
|
1483
|
+
in_range = false;
|
1484
|
+
for (i = 0; i < to_length; i++) {
|
1485
|
+
ch = to_chars[i];
|
1485
1486
|
if (last_from == null) {
|
1486
1487
|
last_from = ch;
|
1487
1488
|
to_chars_expanded.push(ch);
|
@@ -1499,12 +1500,12 @@ class String
|
|
1499
1500
|
}
|
1500
1501
|
}
|
1501
1502
|
else if (in_range) {
|
1502
|
-
|
1503
|
-
|
1503
|
+
start = last_from.charCodeAt(0);
|
1504
|
+
end = ch.charCodeAt(0);
|
1504
1505
|
if (start > end) {
|
1505
1506
|
#{raise ArgumentError, "invalid range \"#{`String.fromCharCode(start)`}-#{`String.fromCharCode(end)`}\" in string transliteration"}
|
1506
1507
|
}
|
1507
|
-
for (
|
1508
|
+
for (c = start + 1; c < end; c++) {
|
1508
1509
|
to_chars_expanded.push(String.fromCharCode(c));
|
1509
1510
|
}
|
1510
1511
|
to_chars_expanded.push(ch);
|
@@ -1523,19 +1524,19 @@ class String
|
|
1523
1524
|
var length_diff = from_length - to_length;
|
1524
1525
|
if (length_diff > 0) {
|
1525
1526
|
var pad_char = (to_length > 0 ? to_chars[to_length - 1] : '');
|
1526
|
-
for (
|
1527
|
+
for (i = 0; i < length_diff; i++) {
|
1527
1528
|
to_chars.push(pad_char);
|
1528
1529
|
}
|
1529
1530
|
}
|
1530
1531
|
|
1531
|
-
for (
|
1532
|
+
for (i = 0; i < from_length; i++) {
|
1532
1533
|
subs[from_chars[i]] = to_chars[i];
|
1533
1534
|
}
|
1534
1535
|
}
|
1535
1536
|
var new_str = ''
|
1536
1537
|
var last_substitute = null
|
1537
|
-
for (
|
1538
|
-
|
1538
|
+
for (i = 0, length = self.length; i < length; i++) {
|
1539
|
+
ch = self.charAt(i);
|
1539
1540
|
var sub = subs[ch]
|
1540
1541
|
if (inverse) {
|
1541
1542
|
if (sub == null) {
|
@@ -1566,22 +1567,10 @@ class String
|
|
1566
1567
|
}
|
1567
1568
|
end
|
1568
1569
|
|
1569
|
-
alias tr_s! <<
|
1570
|
-
|
1571
1570
|
def upcase
|
1572
1571
|
`self.toUpperCase()`
|
1573
1572
|
end
|
1574
1573
|
|
1575
|
-
alias upcase! <<
|
1576
|
-
|
1577
|
-
def freeze
|
1578
|
-
self
|
1579
|
-
end
|
1580
|
-
|
1581
|
-
def frozen?
|
1582
|
-
true
|
1583
|
-
end
|
1584
|
-
|
1585
1574
|
def upto(stop, excl = false, &block)
|
1586
1575
|
return enum_for :upto, stop, excl unless block_given?
|
1587
1576
|
stop = Opal.coerce_to(stop, String, :to_str)
|
@@ -1601,10 +1590,10 @@ class String
|
|
1601
1590
|
a += 1;
|
1602
1591
|
}
|
1603
1592
|
|
1604
|
-
} else if (parseInt(s).toString() === s && parseInt(stop).toString() === stop) {
|
1593
|
+
} else if (parseInt(s, 10).toString() === s && parseInt(stop, 10).toString() === stop) {
|
1605
1594
|
|
1606
|
-
a = parseInt(s);
|
1607
|
-
b = parseInt(stop);
|
1595
|
+
a = parseInt(s, 10);
|
1596
|
+
b = parseInt(stop, 10);
|
1608
1597
|
|
1609
1598
|
while (a <= b) {
|
1610
1599
|
if (excl && a === b) {
|