opal-wedge 0.9.0.dev
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.gitmodules +7 -0
- data/.inch.yml +19 -0
- data/.jshintrc +48 -0
- data/.rspec +3 -0
- data/.spectator +2 -0
- data/.spectator-mspec +3 -0
- data/.travis.yml +60 -0
- data/.yardopts +6 -0
- data/CHANGELOG.md +571 -0
- data/CODE_OF_CONDUCT.md +15 -0
- data/CONTRIBUTING.md +192 -0
- data/Gemfile +26 -0
- data/Guardfile +77 -0
- data/LICENSE +19 -0
- data/README.md +167 -0
- data/Rakefile +15 -0
- data/benchmark/benchmarks +103 -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_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 +37 -0
- data/bin/opal +27 -0
- data/bin/opal-build +77 -0
- data/bin/opal-mspec +10 -0
- data/bin/opal-repl +72 -0
- data/config.ru +14 -0
- data/docs/compiler_directives.md +127 -0
- data/examples/rack/.gitignore +1 -0
- data/examples/rack/Gemfile +3 -0
- data/examples/rack/app/application.rb +13 -0
- data/examples/rack/app/user.rb +22 -0
- data/examples/rack/config.ru +20 -0
- data/examples/rack/index.html.erb +10 -0
- data/examples/sinatra/Gemfile +5 -0
- data/examples/sinatra/app/application.rb +7 -0
- data/examples/sinatra/config.ru +38 -0
- data/lib/mspec/opal/main.rb.erb +9 -0
- data/lib/mspec/opal/new.html.erb +1 -0
- data/lib/mspec/opal/rake_task.rb +248 -0
- data/lib/mspec/opal/runner.rb +281 -0
- data/lib/mspec/opal/special_calls.rb +44 -0
- data/lib/mspec/opal/sprockets.js +57 -0
- data/lib/opal-wedge.rb +4 -0
- data/lib/opal.rb +11 -0
- data/lib/opal/builder.rb +161 -0
- data/lib/opal/builder_processors.rb +149 -0
- data/lib/opal/cli.rb +162 -0
- data/lib/opal/cli_options.rb +158 -0
- data/lib/opal/cli_runners.rb +11 -0
- data/lib/opal/cli_runners/apple_script.rb +65 -0
- data/lib/opal/cli_runners/nodejs.rb +63 -0
- data/lib/opal/cli_runners/phantom.js +44 -0
- data/lib/opal/cli_runners/phantomjs.rb +28 -0
- data/lib/opal/cli_runners/server.rb +56 -0
- data/lib/opal/compiler.rb +381 -0
- data/lib/opal/config.rb +48 -0
- data/lib/opal/erb.rb +84 -0
- data/lib/opal/fragment.rb +53 -0
- data/lib/opal/hike_path_finder.rb +18 -0
- data/lib/opal/nodes.rb +26 -0
- data/lib/opal/nodes/arglist.rb +56 -0
- data/lib/opal/nodes/array.rb +54 -0
- data/lib/opal/nodes/base.rb +151 -0
- data/lib/opal/nodes/call.rb +290 -0
- data/lib/opal/nodes/call_special.rb +252 -0
- data/lib/opal/nodes/case.rb +96 -0
- data/lib/opal/nodes/class.rb +42 -0
- data/lib/opal/nodes/constants.rb +78 -0
- data/lib/opal/nodes/def.rb +281 -0
- data/lib/opal/nodes/defined.rb +113 -0
- data/lib/opal/nodes/definitions.rb +168 -0
- data/lib/opal/nodes/for.rb +48 -0
- data/lib/opal/nodes/hash.rb +67 -0
- data/lib/opal/nodes/helpers.rb +116 -0
- data/lib/opal/nodes/if.rb +81 -0
- data/lib/opal/nodes/iter.rb +136 -0
- data/lib/opal/nodes/literal.rb +247 -0
- data/lib/opal/nodes/logic.rb +217 -0
- data/lib/opal/nodes/masgn.rb +62 -0
- data/lib/opal/nodes/module.rb +45 -0
- data/lib/opal/nodes/rescue.rb +143 -0
- data/lib/opal/nodes/runtime_helpers.rb +45 -0
- data/lib/opal/nodes/scope.rb +281 -0
- data/lib/opal/nodes/singleton_class.rb +26 -0
- data/lib/opal/nodes/super.rb +97 -0
- data/lib/opal/nodes/top.rb +103 -0
- data/lib/opal/nodes/variables.rb +191 -0
- data/lib/opal/nodes/while.rb +65 -0
- data/lib/opal/nodes/yield.rb +95 -0
- data/lib/opal/parser.rb +742 -0
- data/lib/opal/parser/grammar.rb +5723 -0
- data/lib/opal/parser/grammar.y +1787 -0
- data/lib/opal/parser/keywords.rb +66 -0
- data/lib/opal/parser/lexer.rb +1260 -0
- data/lib/opal/parser/parser_scope.rb +28 -0
- data/lib/opal/parser/sexp.rb +81 -0
- data/lib/opal/path_reader.rb +35 -0
- data/lib/opal/paths.rb +55 -0
- data/lib/opal/regexp_anchors.rb +5 -0
- data/lib/opal/source_map.rb +70 -0
- data/lib/opal/sprockets.rb +3 -0
- data/lib/opal/sprockets/cache_key_fix.rb +17 -0
- data/lib/opal/sprockets/environment.rb +31 -0
- data/lib/opal/sprockets/erb.rb +23 -0
- data/lib/opal/sprockets/path_reader.rb +36 -0
- data/lib/opal/sprockets/processor.rb +167 -0
- data/lib/opal/sprockets/server.rb +160 -0
- data/lib/opal/sprockets/source_map_header_patch.rb +41 -0
- data/lib/opal/sprockets/source_map_server.rb +115 -0
- data/lib/opal/util.rb +69 -0
- data/lib/opal/version.rb +5 -0
- data/lib/tilt/opal.rb +54 -0
- data/opal.gemspec +37 -0
- data/opal/README.md +6 -0
- data/opal/corelib/array.rb +2073 -0
- data/opal/corelib/array/inheritance.rb +127 -0
- data/opal/corelib/basic_object.rb +82 -0
- data/opal/corelib/boolean.rb +47 -0
- data/opal/corelib/class.rb +55 -0
- data/opal/corelib/comparable.rb +57 -0
- data/opal/corelib/complex.rb +3 -0
- data/opal/corelib/dir.rb +20 -0
- data/opal/corelib/enumerable.rb +1138 -0
- data/opal/corelib/enumerator.rb +426 -0
- data/opal/corelib/error.rb +77 -0
- data/opal/corelib/file.rb +59 -0
- data/opal/corelib/hash.rb +951 -0
- data/opal/corelib/helpers.rb +102 -0
- data/opal/corelib/io.rb +73 -0
- data/opal/corelib/kernel.rb +1124 -0
- data/opal/corelib/main.rb +7 -0
- data/opal/corelib/match_data.rb +128 -0
- data/opal/corelib/method.rb +62 -0
- data/opal/corelib/module.rb +553 -0
- data/opal/corelib/nil_class.rb +57 -0
- data/opal/corelib/numeric.rb +564 -0
- data/opal/corelib/proc.rb +105 -0
- data/opal/corelib/process.rb +27 -0
- data/opal/corelib/range.rb +116 -0
- data/opal/corelib/rational.rb +3 -0
- data/opal/corelib/regexp.rb +203 -0
- data/opal/corelib/runtime.js +1637 -0
- data/opal/corelib/string.rb +1762 -0
- data/opal/corelib/string/inheritance.rb +117 -0
- data/opal/corelib/struct.rb +159 -0
- data/opal/corelib/time.rb +746 -0
- data/opal/corelib/variables.rb +28 -0
- data/opal/opal.rb +33 -0
- data/spec/README.md +8 -0
- data/spec/filters/bugs/array.rb +77 -0
- data/spec/filters/bugs/basicobject.rb +33 -0
- data/spec/filters/bugs/class.rb +15 -0
- data/spec/filters/bugs/comparable.rb +4 -0
- data/spec/filters/bugs/date.rb +173 -0
- data/spec/filters/bugs/enumerable.rb +62 -0
- data/spec/filters/bugs/enumerator.rb +45 -0
- data/spec/filters/bugs/exception.rb +84 -0
- data/spec/filters/bugs/fixnum.rb +35 -0
- data/spec/filters/bugs/float.rb +100 -0
- data/spec/filters/bugs/hash.rb +17 -0
- data/spec/filters/bugs/integer.rb +63 -0
- data/spec/filters/bugs/kernel.rb +395 -0
- data/spec/filters/bugs/language.rb +246 -0
- data/spec/filters/bugs/math.rb +89 -0
- data/spec/filters/bugs/method.rb +5 -0
- data/spec/filters/bugs/module.rb +372 -0
- data/spec/filters/bugs/nil.rb +7 -0
- data/spec/filters/bugs/numeric.rb +123 -0
- data/spec/filters/bugs/proc.rb +65 -0
- data/spec/filters/bugs/range.rb +148 -0
- data/spec/filters/bugs/regexp.rb +252 -0
- data/spec/filters/bugs/set.rb +51 -0
- data/spec/filters/bugs/singleton.rb +6 -0
- data/spec/filters/bugs/string.rb +99 -0
- data/spec/filters/bugs/strscan.rb +106 -0
- data/spec/filters/bugs/struct.rb +22 -0
- data/spec/filters/bugs/time.rb +28 -0
- data/spec/filters/bugs/unboundmethod.rb +22 -0
- data/spec/filters/unsupported/array.rb +176 -0
- data/spec/filters/unsupported/basicobject.rb +12 -0
- data/spec/filters/unsupported/class.rb +4 -0
- data/spec/filters/unsupported/delegator.rb +5 -0
- data/spec/filters/unsupported/enumerable.rb +8 -0
- data/spec/filters/unsupported/enumerator.rb +13 -0
- data/spec/filters/unsupported/fixnum.rb +15 -0
- data/spec/filters/unsupported/float.rb +6 -0
- data/spec/filters/unsupported/hash.rb +55 -0
- data/spec/filters/unsupported/integer.rb +3 -0
- data/spec/filters/unsupported/kernel.rb +22 -0
- data/spec/filters/unsupported/language.rb +31 -0
- data/spec/filters/unsupported/matchdata.rb +33 -0
- data/spec/filters/unsupported/math.rb +3 -0
- data/spec/filters/unsupported/module.rb +36 -0
- data/spec/filters/unsupported/pathname.rb +3 -0
- data/spec/filters/unsupported/regexp.rb +94 -0
- data/spec/filters/unsupported/set.rb +4 -0
- data/spec/filters/unsupported/singleton.rb +6 -0
- data/spec/filters/unsupported/string.rb +538 -0
- data/spec/filters/unsupported/struct.rb +3 -0
- data/spec/filters/unsupported/time.rb +208 -0
- data/spec/lib/builder_processors_spec.rb +27 -0
- data/spec/lib/builder_spec.rb +72 -0
- data/spec/lib/cli_spec.rb +150 -0
- data/spec/lib/compiler/pre_processed_conditionals_spec.rb +87 -0
- data/spec/lib/compiler_spec.rb +131 -0
- data/spec/lib/dependency_resolver_spec.rb +40 -0
- data/spec/lib/fixtures/complex_sprockets.js.rb.erb +4 -0
- data/spec/lib/fixtures/file_with_directives.js +2 -0
- data/spec/lib/fixtures/jst_file.js.jst +1 -0
- data/spec/lib/fixtures/no_requires.rb +1 -0
- data/spec/lib/fixtures/opal_file.rb +2 -0
- data/spec/lib/fixtures/require_tree_test.rb +3 -0
- data/spec/lib/fixtures/required_file.js +1 -0
- data/spec/lib/fixtures/required_tree_test/required_file1.rb +1 -0
- data/spec/lib/fixtures/required_tree_test/required_file2.rb +1 -0
- data/spec/lib/fixtures/requires.rb +7 -0
- data/spec/lib/fixtures/source_map.rb +1 -0
- data/spec/lib/fixtures/source_map/subfolder/other_file.rb +1 -0
- data/spec/lib/fixtures/sprockets_file.js.rb +3 -0
- data/spec/lib/fixtures/sprockets_require_tree_test.rb +3 -0
- data/spec/lib/hike_path_finder_spec.rb +23 -0
- data/spec/lib/lexer_spec.rb +110 -0
- data/spec/lib/parser/alias_spec.rb +26 -0
- data/spec/lib/parser/and_spec.rb +13 -0
- data/spec/lib/parser/attrasgn_spec.rb +28 -0
- data/spec/lib/parser/begin_spec.rb +42 -0
- data/spec/lib/parser/block_spec.rb +12 -0
- data/spec/lib/parser/break_spec.rb +17 -0
- data/spec/lib/parser/call_spec.rb +165 -0
- data/spec/lib/parser/class_spec.rb +35 -0
- data/spec/lib/parser/comments_spec.rb +11 -0
- data/spec/lib/parser/def_spec.rb +80 -0
- data/spec/lib/parser/if_spec.rb +26 -0
- data/spec/lib/parser/iter_spec.rb +59 -0
- data/spec/lib/parser/lambda_spec.rb +64 -0
- data/spec/lib/parser/literal_spec.rb +118 -0
- data/spec/lib/parser/masgn_spec.rb +37 -0
- data/spec/lib/parser/module_spec.rb +27 -0
- data/spec/lib/parser/not_spec.rb +21 -0
- data/spec/lib/parser/op_asgn1_spec.rb +23 -0
- data/spec/lib/parser/op_asgn2_spec.rb +23 -0
- data/spec/lib/parser/or_spec.rb +13 -0
- data/spec/lib/parser/return_spec.rb +17 -0
- data/spec/lib/parser/sclass_spec.rb +21 -0
- data/spec/lib/parser/string_spec.rb +276 -0
- data/spec/lib/parser/super_spec.rb +20 -0
- data/spec/lib/parser/unary_spec.rb +48 -0
- data/spec/lib/parser/undef_spec.rb +15 -0
- data/spec/lib/parser/unless_spec.rb +13 -0
- data/spec/lib/parser/variables_spec.rb +92 -0
- data/spec/lib/parser/while_spec.rb +15 -0
- data/spec/lib/parser/yield_spec.rb +20 -0
- data/spec/lib/path_reader_spec.rb +36 -0
- data/spec/lib/shared/path_finder_shared.rb +19 -0
- data/spec/lib/shared/path_reader_shared.rb +31 -0
- data/spec/lib/spec_helper.rb +9 -0
- data/spec/lib/sprockets/erb_spec.rb +38 -0
- data/spec/lib/sprockets/path_reader_spec.rb +41 -0
- data/spec/lib/sprockets/processor_spec.rb +67 -0
- data/spec/lib/sprockets/server_spec.rb +102 -0
- data/spec/lib/tilt/opal_spec.rb +37 -0
- data/spec/opal/compiler/irb_spec.rb +44 -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/select_spec.rb +14 -0
- data/spec/opal/core/array/set_range_to_array_spec.rb +7 -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/date_spec.rb +177 -0
- data/spec/opal/core/enumerable/all_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/any_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/collect_break_spec.rb +13 -0
- data/spec/opal/core/enumerable/count_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/detect_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/drop_while_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/each_slice_break.rb +6 -0
- data/spec/opal/core/enumerable/each_with_index_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/each_with_object_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/find_all_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/find_index_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/grep_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/max_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/max_by_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/min_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/min_by_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/none_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/one_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/reduce_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/take_while_break_spec.rb +5 -0
- data/spec/opal/core/exception_spec.rb +13 -0
- data/spec/opal/core/fixtures/class.rb +124 -0
- data/spec/opal/core/fixtures/class_variables.rb +0 -0
- data/spec/opal/core/fixtures/constants.rb +33 -0
- data/spec/opal/core/fixtures/require_tree_files/file 1.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 2.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 3.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 4.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 5.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/nested/nested 1.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/nested/nested 2.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/other/other 1.rb +1 -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/has_value_spec.rb +13 -0
- data/spec/opal/core/hash/internals_spec.rb +332 -0
- data/spec/opal/core/kernel/Array_spec.rb +10 -0
- data/spec/opal/core/kernel/block_given_spec.rb +30 -0
- data/spec/opal/core/kernel/class_spec.rb +6 -0
- data/spec/opal/core/kernel/define_singleton_method_spec.rb +21 -0
- data/spec/opal/core/kernel/equal_value_spec.rb +12 -0
- data/spec/opal/core/kernel/extend_spec.rb +21 -0
- data/spec/opal/core/kernel/format_spec.rb +122 -0
- data/spec/opal/core/kernel/freeze_spec.rb +15 -0
- data/spec/opal/core/kernel/instance_eval_spec.rb +28 -0
- data/spec/opal/core/kernel/instance_variable_defined_spec.rb +15 -0
- data/spec/opal/core/kernel/instance_variable_get_spec.rb +14 -0
- data/spec/opal/core/kernel/instance_variable_set_spec.rb +10 -0
- data/spec/opal/core/kernel/loop_spec.rb +23 -0
- data/spec/opal/core/kernel/match_spec.rb +5 -0
- data/spec/opal/core/kernel/method_spec.rb +31 -0
- data/spec/opal/core/kernel/methods_spec.rb +25 -0
- data/spec/opal/core/kernel/nil_spec.rb +7 -0
- data/spec/opal/core/kernel/p_spec.rb +15 -0
- data/spec/opal/core/kernel/printf_spec.rb +11 -0
- data/spec/opal/core/kernel/proc_spec.rb +13 -0
- data/spec/opal/core/kernel/rand_spec.rb +23 -0
- data/spec/opal/core/kernel/require_tree_spec.rb +18 -0
- data/spec/opal/core/kernel/respond_to_spec.rb +41 -0
- data/spec/opal/core/kernel/send_spec.rb +56 -0
- data/spec/opal/core/kernel/sprintf_spec.rb +5 -0
- data/spec/opal/core/language/block_spec.rb +538 -0
- data/spec/opal/core/language/fixtures/array.rb +11 -0
- data/spec/opal/core/language/fixtures/block.rb +57 -0
- data/spec/opal/core/language/fixtures/break.rb +240 -0
- data/spec/opal/core/language/fixtures/ensure.rb +72 -0
- data/spec/opal/core/language/fixtures/literal_lambda.rb +7 -0
- data/spec/opal/core/language/fixtures/metaclass.rb +33 -0
- data/spec/opal/core/language/fixtures/module.rb +24 -0
- data/spec/opal/core/language/fixtures/next.rb +128 -0
- data/spec/opal/core/language/fixtures/return.rb +118 -0
- data/spec/opal/core/language/fixtures/send.rb +110 -0
- data/spec/opal/core/language/fixtures/send_1.9.rb +22 -0
- data/spec/opal/core/language/fixtures/super.rb +308 -0
- data/spec/opal/core/language/fixtures/variables.rb +58 -0
- data/spec/opal/core/language/fixtures/yield.rb +28 -0
- data/spec/opal/core/language/predefined_spec.rb +138 -0
- data/spec/opal/core/language/proc_spec.rb +263 -0
- data/spec/opal/core/language/regexp_spec.rb +20 -0
- data/spec/opal/core/language/send_spec.rb +225 -0
- data/spec/opal/core/language/string_spec.rb +44 -0
- data/spec/opal/core/language/variables_spec.rb +1366 -0
- data/spec/opal/core/language/versions/array_1.9.rb +39 -0
- data/spec/opal/core/language/versions/block_1.9.rb +0 -0
- data/spec/opal/core/language/versions/break_1.9.rb +0 -0
- data/spec/opal/core/language/versions/case_1.9.rb +20 -0
- data/spec/opal/core/language/versions/def_2_0_spec.rb +62 -0
- data/spec/opal/core/language/versions/hash_1.9.rb +18 -0
- data/spec/opal/core/language/versions/literal_lambda_1.9.rb +143 -0
- data/spec/opal/core/language/versions/not_1.9.rb +22 -0
- data/spec/opal/core/language/versions/send_1.9.rb +241 -0
- data/spec/opal/core/language/versions/symbol_1.9.rb +15 -0
- data/spec/opal/core/language/versions/variables_1.9.rb +8 -0
- data/spec/opal/core/language_spec.rb +23 -0
- data/spec/opal/core/method/to_proc_spec.rb +28 -0
- data/spec/opal/core/module/alias_method_spec.rb +28 -0
- data/spec/opal/core/module/ancestors_spec.rb +11 -0
- data/spec/opal/core/module/append_features_spec.rb +14 -0
- data/spec/opal/core/module/attr_accessor_spec.rb +26 -0
- data/spec/opal/core/module/const_defined_spec.rb +85 -0
- data/spec/opal/core/module/const_get_spec.rb +85 -0
- data/spec/opal/core/module/const_missing_spec.rb +17 -0
- data/spec/opal/core/module/const_set_spec.rb +64 -0
- data/spec/opal/core/module/constants_spec.rb +49 -0
- data/spec/opal/core/module/fixtures/classes.rb +434 -0
- data/spec/opal/core/module/method_defined_spec.rb +48 -0
- data/spec/opal/core/module/module_function_spec.rb +25 -0
- data/spec/opal/core/module/name_spec.rb +52 -0
- data/spec/opal/core/module/public_method_defined_spec.rb +18 -0
- data/spec/opal/core/module/remove_const_spec.rb +22 -0
- data/spec/opal/core/module/undef_method_spec.rb +66 -0
- data/spec/opal/core/numeric/bit_and_spec.rb +7 -0
- data/spec/opal/core/numeric/bit_or_spec.rb +8 -0
- data/spec/opal/core/numeric/bit_xor_spec.rb +6 -0
- data/spec/opal/core/numeric/ceil_spec.rb +8 -0
- data/spec/opal/core/numeric/chr_spec.rb +8 -0
- data/spec/opal/core/numeric/comparison_spec.rb +24 -0
- data/spec/opal/core/numeric/complement_spec.rb +8 -0
- data/spec/opal/core/numeric/divide_spec.rb +10 -0
- data/spec/opal/core/numeric/eql_spec.rb +9 -0
- data/spec/opal/core/numeric/exponent_spec.rb +33 -0
- data/spec/opal/core/numeric/floor_spec.rb +8 -0
- data/spec/opal/core/numeric/gt_spec.rb +11 -0
- data/spec/opal/core/numeric/gte_spec.rb +12 -0
- data/spec/opal/core/numeric/integer_spec.rb +9 -0
- data/spec/opal/core/numeric/left_shift_spec.rb +21 -0
- data/spec/opal/core/numeric/lt_spec.rb +11 -0
- data/spec/opal/core/numeric/lte_spec.rb +12 -0
- data/spec/opal/core/numeric/minus_spec.rb +8 -0
- data/spec/opal/core/numeric/modulo_spec.rb +19 -0
- data/spec/opal/core/numeric/multiply_spec.rb +9 -0
- data/spec/opal/core/numeric/next_spec.rb +9 -0
- data/spec/opal/core/numeric/ord_spec.rb +9 -0
- data/spec/opal/core/numeric/plus_spec.rb +8 -0
- data/spec/opal/core/numeric/pred_spec.rb +7 -0
- data/spec/opal/core/numeric/right_shift_spec.rb +25 -0
- data/spec/opal/core/numeric/step_spec.rb +11 -0
- data/spec/opal/core/numeric/succ_spec.rb +9 -0
- data/spec/opal/core/numeric/times_spec.rb +36 -0
- data/spec/opal/core/numeric/to_f_spec.rb +7 -0
- data/spec/opal/core/numeric/to_i_spec.rb +7 -0
- data/spec/opal/core/numeric/to_json_spec.rb +8 -0
- data/spec/opal/core/numeric/to_s_spec.rb +26 -0
- data/spec/opal/core/numeric/uminus_spec.rb +9 -0
- data/spec/opal/core/numeric/upto_spec.rb +19 -0
- data/spec/opal/core/numeric/zero_spec.rb +7 -0
- data/spec/opal/core/object_id_spec.rb +56 -0
- data/spec/opal/core/proc/call_spec.rb +21 -0
- data/spec/opal/core/proc/element_reference_spec.rb +21 -0
- data/spec/opal/core/proc/proc_tricks_spec.rb +7 -0
- data/spec/opal/core/runtime/begin_spec.rb +39 -0
- data/spec/opal/core/runtime/block_send_spec.rb +28 -0
- data/spec/opal/core/runtime/block_spec.rb +23 -0
- data/spec/opal/core/runtime/bridged_classes_spec.rb +111 -0
- data/spec/opal/core/runtime/constants_spec.rb +13 -0
- data/spec/opal/core/runtime/donate_spec.rb +53 -0
- data/spec/opal/core/runtime/eval_spec.rb +5 -0
- data/spec/opal/core/runtime/main_methods_spec.rb +27 -0
- data/spec/opal/core/runtime/method_missing_spec.rb +62 -0
- data/spec/opal/core/runtime/method_spec.rb +31 -0
- data/spec/opal/core/runtime/operator_call_spec.rb +13 -0
- data/spec/opal/core/runtime/paren_spec.rb +14 -0
- data/spec/opal/core/runtime/rescue_spec.rb +38 -0
- data/spec/opal/core/runtime/return_spec.rb +38 -0
- data/spec/opal/core/runtime/send_spec.rb +34 -0
- data/spec/opal/core/runtime/singleton_class_spec.rb +13 -0
- data/spec/opal/core/runtime/super_spec.rb +212 -0
- data/spec/opal/core/runtime/truthy_spec.rb +23 -0
- data/spec/opal/core/runtime/variables_spec.rb +20 -0
- data/spec/opal/core/runtime_spec.rb +58 -0
- data/spec/opal/core/source_map_spec.rb +15 -0
- data/spec/opal/core/string_spec.rb +11 -0
- data/spec/opal/stdlib/erb/erb_spec.rb +30 -0
- data/spec/opal/stdlib/erb/inline_block.opalerb +3 -0
- data/spec/opal/stdlib/erb/quoted.opalerb +1 -0
- data/spec/opal/stdlib/erb/simple.opalerb +1 -0
- data/spec/opal/stdlib/js_spec.rb +66 -0
- data/spec/opal/stdlib/json/ext_spec.rb +48 -0
- data/spec/opal/stdlib/json/parse_spec.rb +33 -0
- data/spec/opal/stdlib/native/alias_native_spec.rb +27 -0
- data/spec/opal/stdlib/native/each_spec.rb +13 -0
- data/spec/opal/stdlib/native/element_reference_spec.rb +16 -0
- data/spec/opal/stdlib/native/exposure_spec.rb +33 -0
- data/spec/opal/stdlib/native/ext_spec.rb +19 -0
- data/spec/opal/stdlib/native/initialize_spec.rb +17 -0
- data/spec/opal/stdlib/native/method_missing_spec.rb +51 -0
- data/spec/opal/stdlib/native/native_alias_spec.rb +19 -0
- data/spec/opal/stdlib/native/native_class_spec.rb +18 -0
- data/spec/opal/stdlib/native/native_module_spec.rb +13 -0
- data/spec/opal/stdlib/native/native_reader_spec.rb +22 -0
- data/spec/opal/stdlib/native/native_writer_spec.rb +30 -0
- data/spec/opal/stdlib/native/new_spec.rb +8 -0
- data/spec/opal/stdlib/promise/always_spec.rb +30 -0
- data/spec/opal/stdlib/promise/error_spec.rb +15 -0
- data/spec/opal/stdlib/promise/rescue_spec.rb +44 -0
- data/spec/opal/stdlib/promise/then_spec.rb +71 -0
- data/spec/opal/stdlib/promise/trace_spec.rb +52 -0
- data/spec/opal/stdlib/promise/value_spec.rb +15 -0
- data/spec/opal/stdlib/promise/when_spec.rb +34 -0
- data/spec/opal/stdlib/template/paths_spec.rb +10 -0
- data/spec/opal/stdlib/thread/mutex_spec.rb +40 -0
- data/spec/opal/stdlib/thread/thread_queue_spec.rb +32 -0
- data/spec/opal/stdlib/thread/thread_spec.rb +60 -0
- data/spec/rubyspecs +144 -0
- data/spec/spec_helper.rb +53 -0
- data/spec/support/mspec_rspec_adapter.rb +33 -0
- data/spec/support/parser_helpers.rb +37 -0
- data/stdlib/README.md +3 -0
- data/stdlib/base64.rb +152 -0
- data/stdlib/benchmark.rb +557 -0
- data/stdlib/buffer.rb +41 -0
- data/stdlib/buffer/array.rb +66 -0
- data/stdlib/buffer/view.rb +70 -0
- data/stdlib/date.rb +248 -0
- data/stdlib/delegate.rb +29 -0
- data/stdlib/dir.rb +1 -0
- data/stdlib/encoding.rb +170 -0
- data/stdlib/enumerator.rb +1 -0
- data/stdlib/erb.rb +16 -0
- data/stdlib/file.rb +1 -0
- data/stdlib/fileutils.rb +0 -0
- data/stdlib/forwardable.rb +71 -0
- data/stdlib/iconv.rb +0 -0
- data/stdlib/js.rb +56 -0
- data/stdlib/json.rb +190 -0
- data/stdlib/math.rb +370 -0
- data/stdlib/native.rb +530 -0
- data/stdlib/nodejs.rb +7 -0
- data/stdlib/nodejs/dir.rb +13 -0
- data/stdlib/nodejs/file.rb +98 -0
- data/stdlib/nodejs/fileutils.rb +26 -0
- data/stdlib/nodejs/io.rb +2 -0
- data/stdlib/nodejs/irb.rb +45 -0
- data/stdlib/nodejs/kernel.rb +33 -0
- data/stdlib/nodejs/node_modules/.bin/js-yaml +140 -0
- data/stdlib/nodejs/node_modules/glob/LICENSE +15 -0
- data/stdlib/nodejs/node_modules/glob/README.md +357 -0
- data/stdlib/nodejs/node_modules/glob/common.js +177 -0
- data/stdlib/nodejs/node_modules/glob/glob.js +649 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/inflight/.eslintrc +17 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/inflight/LICENSE +15 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/inflight/README.md +37 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/inflight/inflight.js +44 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/LICENSE +15 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/README.md +36 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/package.json +52 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/test/basic.js +51 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/wrappy.js +33 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/inflight/package.json +61 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/inflight/test.js +97 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/inherits/LICENSE +16 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/inherits/README.md +42 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/inherits/inherits.js +1 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/inherits/inherits_browser.js +23 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/inherits/package.json +51 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/inherits/test.js +25 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/.npmignore +1 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/.travis.yml +4 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/LICENSE +23 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/README.md +216 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/benchmark.js +15 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/browser.js +1181 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/minimatch.js +845 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/.npmignore +2 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/.travis.yml +3 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/README.md +121 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/example.js +8 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/index.js +191 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/.npmignore +2 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/.travis.yml +4 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/Makefile +6 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/README.md +80 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/example.js +5 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/index.js +38 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/package.json +73 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/test/balanced.js +56 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/.travis.yml +4 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/LICENSE +18 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/README.markdown +62 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/example/map.js +6 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/index.js +13 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/package.json +83 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/test/map.js +39 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/package.json +75 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/bash-comparison.js +32 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/bash-results.txt +1075 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/cases.txt +182 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/dollar.js +9 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/empty-option.js +10 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/generate.sh +24 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/negative-increment.js +15 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/nested.js +16 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/order.js +10 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/pad.js +13 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/same-type.js +7 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/sequence.js +50 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/package.json +60 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/test/basic.js +399 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/test/brace-expand.js +45 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/test/defaults.js +274 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/test/extglob-ending-with-state-char.js +8 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/once/LICENSE +27 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/once/README.md +51 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/LICENSE +15 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/README.md +36 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/package.json +52 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/test/basic.js +51 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/wrappy.js +33 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/once/once.js +21 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/once/package.json +60 -0
- data/stdlib/nodejs/node_modules/glob/node_modules/once/test/once.js +23 -0
- data/stdlib/nodejs/node_modules/glob/package.json +72 -0
- data/stdlib/nodejs/node_modules/glob/sync.js +409 -0
- data/stdlib/nodejs/node_modules/js-yaml/HISTORY.md +277 -0
- data/stdlib/nodejs/node_modules/js-yaml/LICENSE +21 -0
- data/stdlib/nodejs/node_modules/js-yaml/README.md +288 -0
- data/stdlib/nodejs/node_modules/js-yaml/bin/js-yaml.js +140 -0
- data/stdlib/nodejs/node_modules/js-yaml/bower.json +23 -0
- data/stdlib/nodejs/node_modules/js-yaml/dist/js-yaml.js +3666 -0
- data/stdlib/nodejs/node_modules/js-yaml/dist/js-yaml.min.js +3 -0
- data/stdlib/nodejs/node_modules/js-yaml/examples/custom_types.js +102 -0
- data/stdlib/nodejs/node_modules/js-yaml/examples/custom_types.yml +18 -0
- data/stdlib/nodejs/node_modules/js-yaml/examples/dumper.js +31 -0
- data/stdlib/nodejs/node_modules/js-yaml/examples/dumper.json +22 -0
- data/stdlib/nodejs/node_modules/js-yaml/examples/sample_document.js +18 -0
- data/stdlib/nodejs/node_modules/js-yaml/examples/sample_document.yml +197 -0
- data/stdlib/nodejs/node_modules/js-yaml/index.js +7 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml.js +39 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/common.js +62 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/dumper.js +554 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/exception.js +25 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/loader.js +1581 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/mark.js +78 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema.js +103 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema/core.js +18 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema/default_full.js +25 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema/default_safe.js +28 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema/failsafe.js +17 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema/json.js +25 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type.js +61 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/binary.js +133 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/bool.js +37 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/float.js +110 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/int.js +183 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/js/function.js +85 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/js/regexp.js +84 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/js/undefined.js +27 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/map.js +8 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/merge.js +12 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/null.js +36 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/omap.js +56 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/pairs.js +61 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/seq.js +8 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/set.js +33 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/str.js +8 -0
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/timestamp.js +98 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/.bin/esparse +117 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/.bin/esvalidate +177 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/HISTORY.md +115 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/LICENSE +21 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/README.md +239 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/arguments.js +36 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/choice.js +22 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/constants.js +59 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/help.js +13 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/nargs.js +33 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/parents.js +28 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/prefix_chars.js +23 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/sub_commands.js +49 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/sum.js +35 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/testformatters.js +270 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/index.js +1 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action.js +146 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/append.js +55 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/append/constant.js +47 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/count.js +40 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/help.js +48 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/store.js +50 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/store/constant.js +43 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/store/false.js +27 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/store/true.js +26 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/subparsers.js +148 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/version.js +50 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action_container.js +481 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/argparse.js +14 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/argument/error.js +50 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/argument/exclusive.js +54 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/argument/group.js +75 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/argument_parser.js +1168 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/const.js +18 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/help/added_formatters.js +88 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/help/formatter.js +798 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/namespace.js +77 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/.npmignore +2 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/.travis.yml +8 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/README.markdown +825 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/bower.json +33 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/component.json +11 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/foo.js +10 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/gulpfile.js +26 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/lib/underscore.string.js +673 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/libpeerconnection.log +0 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/package.json +107 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore/LICENSE +23 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore/README.md +22 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore/package.json +69 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore/underscore-min.js +6 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore/underscore.js +1415 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/package.json +62 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/README.md +73 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/bin/esparse.js +117 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/bin/esvalidate.js +177 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/esprima.js +3908 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/package.json +69 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/test/compat.js +239 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/test/reflect.js +422 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/test/run.js +66 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/test/runner.js +387 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/test/test.js +20238 -0
- data/stdlib/nodejs/node_modules/js-yaml/package.json +83 -0
- data/stdlib/nodejs/package.json +6 -0
- data/stdlib/nodejs/require.rb +30 -0
- data/stdlib/nodejs/rubygems.rb +68 -0
- data/stdlib/nodejs/yaml.rb +11 -0
- data/stdlib/observer.rb +202 -0
- data/stdlib/opal-parser.rb +54 -0
- data/stdlib/opal-source-maps.rb +2 -0
- data/stdlib/ostruct.rb +69 -0
- data/stdlib/pathname.rb +55 -0
- data/stdlib/phantomjs.rb +3 -0
- data/stdlib/pp.rb +35 -0
- data/stdlib/promise.rb +427 -0
- data/stdlib/racc/parser.rb +215 -0
- data/stdlib/rbconfig.rb +18 -0
- data/stdlib/securerandom.rb +12 -0
- data/stdlib/set.rb +170 -0
- data/stdlib/singleton.rb +40 -0
- data/stdlib/source_map.rb +5 -0
- data/stdlib/source_map/map.rb +220 -0
- data/stdlib/source_map/mapping.rb +26 -0
- data/stdlib/source_map/offset.rb +88 -0
- data/stdlib/source_map/version.rb +3 -0
- data/stdlib/source_map/vlq.rb +98 -0
- data/stdlib/sourcemap.rb +1 -0
- data/stdlib/stringio.rb +181 -0
- data/stdlib/strscan.rb +166 -0
- data/stdlib/template.rb +46 -0
- data/stdlib/thread.rb +164 -0
- data/stdlib/time.rb +9 -0
- data/stdlib/yaml.rb +1 -0
- data/tasks/benchmarking.rake +88 -0
- data/tasks/building.rake +58 -0
- data/tasks/documenting.rake +37 -0
- data/tasks/github.rake +19 -0
- data/tasks/linting.rake +18 -0
- data/tasks/testing.rake +125 -0
- data/vendored-minitest/minitest.rb +780 -0
- data/vendored-minitest/minitest/assertions.rb +662 -0
- data/vendored-minitest/minitest/autorun.rb +12 -0
- data/vendored-minitest/minitest/benchmark.rb +426 -0
- data/vendored-minitest/minitest/expectations.rb +281 -0
- data/vendored-minitest/minitest/hell.rb +11 -0
- data/vendored-minitest/minitest/mock.rb +220 -0
- data/vendored-minitest/minitest/parallel.rb +65 -0
- data/vendored-minitest/minitest/pride.rb +4 -0
- data/vendored-minitest/minitest/pride_plugin.rb +142 -0
- data/vendored-minitest/minitest/spec.rb +310 -0
- data/vendored-minitest/minitest/test.rb +293 -0
- data/vendored-minitest/minitest/unit.rb +45 -0
- data/vendored-minitest/test/unit.rb +28 -0
- metadata +1058 -0
@@ -0,0 +1,1762 @@
|
|
1
|
+
require 'corelib/comparable'
|
2
|
+
|
3
|
+
class String
|
4
|
+
include Comparable
|
5
|
+
|
6
|
+
`def.$$is_string = true`
|
7
|
+
|
8
|
+
`var MUT_STR_ERR_MSG = 'String#%s not supported. Mutable String methods are not supported in Opal.'`
|
9
|
+
|
10
|
+
def __id__
|
11
|
+
`self.toString()`
|
12
|
+
end
|
13
|
+
alias object_id __id__
|
14
|
+
|
15
|
+
def self.try_convert(what)
|
16
|
+
Opal.coerce_to?(what, String, :to_str)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.new(str = '')
|
20
|
+
str = Opal.coerce_to(str, String, :to_str)
|
21
|
+
`new String(str)`
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(str = undefined)
|
25
|
+
%x{
|
26
|
+
if (str === undefined) {
|
27
|
+
return self;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
raise NotImplementedError, 'Mutable strings are not supported in Opal.'
|
31
|
+
end
|
32
|
+
|
33
|
+
def %(data)
|
34
|
+
if Array === data
|
35
|
+
format(self, *data)
|
36
|
+
else
|
37
|
+
format(self, data)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def *(count)
|
42
|
+
%x{
|
43
|
+
count = #{Opal.coerce_to(`count`, Integer, :to_int)};
|
44
|
+
|
45
|
+
if (count < 0) {
|
46
|
+
#{raise ArgumentError, 'negative argument'}
|
47
|
+
}
|
48
|
+
|
49
|
+
if (count === 0) {
|
50
|
+
return '';
|
51
|
+
}
|
52
|
+
|
53
|
+
var result = '',
|
54
|
+
string = self.toString();
|
55
|
+
|
56
|
+
// All credit for the bit-twiddling magic code below goes to Mozilla
|
57
|
+
// polyfill implementation of String.prototype.repeat() posted here:
|
58
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat
|
59
|
+
|
60
|
+
if (string.length * count >= 1 << 28) {
|
61
|
+
#{raise RangeError, 'multiply count must not overflow maximum string size'}
|
62
|
+
}
|
63
|
+
|
64
|
+
for (;;) {
|
65
|
+
if ((count & 1) === 1) {
|
66
|
+
result += string;
|
67
|
+
}
|
68
|
+
count >>>= 1;
|
69
|
+
if (count === 0) {
|
70
|
+
break;
|
71
|
+
}
|
72
|
+
string += string;
|
73
|
+
}
|
74
|
+
|
75
|
+
return result;
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
def +(other)
|
80
|
+
other = Opal.coerce_to other, String, :to_str
|
81
|
+
|
82
|
+
`self + #{other.to_s}`
|
83
|
+
end
|
84
|
+
|
85
|
+
def <=>(other)
|
86
|
+
if other.respond_to? :to_str
|
87
|
+
other = other.to_str.to_s
|
88
|
+
|
89
|
+
`self > other ? 1 : (self < other ? -1 : 0)`
|
90
|
+
else
|
91
|
+
%x{
|
92
|
+
var cmp = #{other <=> self};
|
93
|
+
|
94
|
+
if (cmp === nil) {
|
95
|
+
return nil;
|
96
|
+
}
|
97
|
+
else {
|
98
|
+
return cmp > 0 ? -1 : (cmp < 0 ? 1 : 0);
|
99
|
+
}
|
100
|
+
}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def <<(other)
|
105
|
+
raise NotImplementedError, `MUT_STR_ERR_MSG` % '<<'
|
106
|
+
end
|
107
|
+
|
108
|
+
def ==(other)
|
109
|
+
%x{
|
110
|
+
if (other.$$is_string) {
|
111
|
+
return self.toString() === other.toString();
|
112
|
+
}
|
113
|
+
if (#{Opal.respond_to? `other`, :to_str}) {
|
114
|
+
return #{other == self};
|
115
|
+
}
|
116
|
+
return false;
|
117
|
+
}
|
118
|
+
end
|
119
|
+
|
120
|
+
alias eql? ==
|
121
|
+
alias === ==
|
122
|
+
|
123
|
+
def =~(other)
|
124
|
+
%x{
|
125
|
+
if (other.$$is_string) {
|
126
|
+
#{raise TypeError, 'type mismatch: String given'};
|
127
|
+
}
|
128
|
+
|
129
|
+
return #{other =~ self};
|
130
|
+
}
|
131
|
+
end
|
132
|
+
|
133
|
+
def [](index, length = undefined)
|
134
|
+
%x{
|
135
|
+
var size = self.length, exclude;
|
136
|
+
|
137
|
+
if (index.$$is_range) {
|
138
|
+
exclude = index.exclude;
|
139
|
+
length = #{Opal.coerce_to(`index.end`, Integer, :to_int)};
|
140
|
+
index = #{Opal.coerce_to(`index.begin`, Integer, :to_int)};
|
141
|
+
|
142
|
+
if (Math.abs(index) > size) {
|
143
|
+
return nil;
|
144
|
+
}
|
145
|
+
|
146
|
+
if (index < 0) {
|
147
|
+
index += size;
|
148
|
+
}
|
149
|
+
|
150
|
+
if (length < 0) {
|
151
|
+
length += size;
|
152
|
+
}
|
153
|
+
|
154
|
+
if (!exclude) {
|
155
|
+
length += 1;
|
156
|
+
}
|
157
|
+
|
158
|
+
length = length - index;
|
159
|
+
|
160
|
+
if (length < 0) {
|
161
|
+
length = 0;
|
162
|
+
}
|
163
|
+
|
164
|
+
return self.substr(index, length);
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
if (index.$$is_string) {
|
169
|
+
if (length != null) {
|
170
|
+
#{raise TypeError}
|
171
|
+
}
|
172
|
+
return self.indexOf(index) !== -1 ? index : nil;
|
173
|
+
}
|
174
|
+
|
175
|
+
|
176
|
+
if (index.$$is_regexp) {
|
177
|
+
var match = self.match(index);
|
178
|
+
|
179
|
+
if (match === null) {
|
180
|
+
#{$~ = nil}
|
181
|
+
return nil;
|
182
|
+
}
|
183
|
+
|
184
|
+
#{$~ = MatchData.new(`index`, `match`)}
|
185
|
+
|
186
|
+
if (length == null) {
|
187
|
+
return match[0];
|
188
|
+
}
|
189
|
+
|
190
|
+
length = #{Opal.coerce_to(`length`, Integer, :to_int)};
|
191
|
+
|
192
|
+
if (length < 0 && -length < match.length) {
|
193
|
+
return match[length += match.length];
|
194
|
+
}
|
195
|
+
|
196
|
+
if (length >= 0 && length < match.length) {
|
197
|
+
return match[length];
|
198
|
+
}
|
199
|
+
|
200
|
+
return nil;
|
201
|
+
}
|
202
|
+
|
203
|
+
|
204
|
+
index = #{Opal.coerce_to(`index`, Integer, :to_int)};
|
205
|
+
|
206
|
+
if (index < 0) {
|
207
|
+
index += size;
|
208
|
+
}
|
209
|
+
|
210
|
+
if (length == null) {
|
211
|
+
if (index >= size || index < 0) {
|
212
|
+
return nil;
|
213
|
+
}
|
214
|
+
return self.substr(index, 1);
|
215
|
+
}
|
216
|
+
|
217
|
+
length = #{Opal.coerce_to(`length`, Integer, :to_int)};
|
218
|
+
|
219
|
+
if (length < 0) {
|
220
|
+
return nil;
|
221
|
+
}
|
222
|
+
|
223
|
+
if (index > size || index < 0) {
|
224
|
+
return nil;
|
225
|
+
}
|
226
|
+
|
227
|
+
return self.substr(index, length);
|
228
|
+
}
|
229
|
+
end
|
230
|
+
|
231
|
+
def capitalize
|
232
|
+
`self.charAt(0).toUpperCase() + self.substr(1).toLowerCase()`
|
233
|
+
end
|
234
|
+
|
235
|
+
def capitalize!(other)
|
236
|
+
raise NotImplementedError, `MUT_STR_ERR_MSG` % 'capitalize!'
|
237
|
+
end
|
238
|
+
|
239
|
+
def casecmp(other)
|
240
|
+
other = Opal.coerce_to(other, String, :to_str).to_s
|
241
|
+
%x{
|
242
|
+
var ascii_only = /^[\x00-\x7F]*$/;
|
243
|
+
if (ascii_only.test(self) && ascii_only.test(other)) {
|
244
|
+
self = self.toLowerCase();
|
245
|
+
other = other.toLowerCase();
|
246
|
+
}
|
247
|
+
}
|
248
|
+
self <=> other
|
249
|
+
end
|
250
|
+
|
251
|
+
def center(width, padstr = ' ')
|
252
|
+
width = Opal.coerce_to(width, Integer, :to_int)
|
253
|
+
padstr = Opal.coerce_to(padstr, String, :to_str).to_s
|
254
|
+
|
255
|
+
if padstr.empty?
|
256
|
+
raise ArgumentError, 'zero width padding'
|
257
|
+
end
|
258
|
+
|
259
|
+
return self if `width <= self.length`
|
260
|
+
|
261
|
+
%x{
|
262
|
+
var ljustified = #{ljust ((width + @length) / 2).ceil, padstr},
|
263
|
+
rjustified = #{rjust ((width + @length) / 2).floor, padstr};
|
264
|
+
|
265
|
+
return rjustified + ljustified.slice(self.length);
|
266
|
+
}
|
267
|
+
end
|
268
|
+
|
269
|
+
def chars(&block)
|
270
|
+
return each_char.to_a unless block
|
271
|
+
|
272
|
+
each_char(&block)
|
273
|
+
end
|
274
|
+
|
275
|
+
def chomp(separator = $/)
|
276
|
+
return self if `separator === nil || self.length === 0`
|
277
|
+
|
278
|
+
separator = Opal.coerce_to!(separator, String, :to_str).to_s
|
279
|
+
|
280
|
+
%x{
|
281
|
+
if (separator === "\n") {
|
282
|
+
return self.replace(/\r?\n?$/, '');
|
283
|
+
}
|
284
|
+
else if (separator === "") {
|
285
|
+
return self.replace(/(\r?\n)+$/, '');
|
286
|
+
}
|
287
|
+
else if (self.length > separator.length) {
|
288
|
+
var tail = self.substr(self.length - separator.length, separator.length);
|
289
|
+
|
290
|
+
if (tail === separator) {
|
291
|
+
return self.substr(0, self.length - separator.length);
|
292
|
+
}
|
293
|
+
}
|
294
|
+
}
|
295
|
+
|
296
|
+
self
|
297
|
+
end
|
298
|
+
|
299
|
+
def chomp!(other)
|
300
|
+
raise NotImplementedError, `MUT_STR_ERR_MSG` % 'chomp!'
|
301
|
+
end
|
302
|
+
|
303
|
+
def chop
|
304
|
+
%x{
|
305
|
+
var length = self.length;
|
306
|
+
|
307
|
+
if (length <= 1) {
|
308
|
+
return "";
|
309
|
+
}
|
310
|
+
|
311
|
+
if (self.charAt(length - 1) === "\n" && self.charAt(length - 2) === "\r") {
|
312
|
+
return self.substr(0, length - 2);
|
313
|
+
}
|
314
|
+
else {
|
315
|
+
return self.substr(0, length - 1);
|
316
|
+
}
|
317
|
+
}
|
318
|
+
end
|
319
|
+
|
320
|
+
def chop!(other)
|
321
|
+
raise NotImplementedError, `MUT_STR_ERR_MSG` % 'chop!'
|
322
|
+
end
|
323
|
+
|
324
|
+
def chr
|
325
|
+
`self.charAt(0)`
|
326
|
+
end
|
327
|
+
|
328
|
+
def clone
|
329
|
+
copy = `self.slice()`
|
330
|
+
copy.initialize_clone(self)
|
331
|
+
copy
|
332
|
+
end
|
333
|
+
|
334
|
+
def dup
|
335
|
+
copy = `self.slice()`
|
336
|
+
copy.initialize_dup(self)
|
337
|
+
copy
|
338
|
+
end
|
339
|
+
|
340
|
+
def count(*sets)
|
341
|
+
%x{
|
342
|
+
if (sets.length === 0) {
|
343
|
+
#{raise ArgumentError, "ArgumentError: wrong number of arguments (0 for 1+)"}
|
344
|
+
}
|
345
|
+
var char_class = char_class_from_char_sets(sets);
|
346
|
+
if (char_class === null) {
|
347
|
+
return 0;
|
348
|
+
}
|
349
|
+
return self.length - self.replace(new RegExp(char_class, 'g'), '').length;
|
350
|
+
}
|
351
|
+
end
|
352
|
+
|
353
|
+
def delete(*sets)
|
354
|
+
%x{
|
355
|
+
if (sets.length === 0) {
|
356
|
+
#{raise ArgumentError, "ArgumentError: wrong number of arguments (0 for 1+)"}
|
357
|
+
}
|
358
|
+
var char_class = char_class_from_char_sets(sets);
|
359
|
+
if (char_class === null) {
|
360
|
+
return self;
|
361
|
+
}
|
362
|
+
return self.replace(new RegExp(char_class, 'g'), '');
|
363
|
+
}
|
364
|
+
end
|
365
|
+
|
366
|
+
alias dup clone
|
367
|
+
|
368
|
+
def downcase
|
369
|
+
`self.toLowerCase()`
|
370
|
+
end
|
371
|
+
|
372
|
+
def downcase!(other)
|
373
|
+
raise NotImplementedError, `MUT_STR_ERR_MSG` % 'downcase!'
|
374
|
+
end
|
375
|
+
|
376
|
+
def each_char(&block)
|
377
|
+
return enum_for(:each_char){self.size} unless block_given?
|
378
|
+
|
379
|
+
%x{
|
380
|
+
for (var i = 0, length = self.length; i < length; i++) {
|
381
|
+
#{yield `self.charAt(i)`};
|
382
|
+
}
|
383
|
+
}
|
384
|
+
|
385
|
+
self
|
386
|
+
end
|
387
|
+
|
388
|
+
def each_line(separator = $/)
|
389
|
+
return enum_for :each_line, separator unless block_given?
|
390
|
+
|
391
|
+
%x{
|
392
|
+
if (separator === nil) {
|
393
|
+
#{yield self};
|
394
|
+
return self;
|
395
|
+
}
|
396
|
+
|
397
|
+
separator = #{Opal.coerce_to(`separator`, String, :to_str)}
|
398
|
+
|
399
|
+
var a, i, n, length, chomped, trailing, splitted;
|
400
|
+
|
401
|
+
if (separator.length === 0) {
|
402
|
+
for (a = self.split(/(\n{2,})/), i = 0, n = a.length; i < n; i += 2) {
|
403
|
+
if (a[i] || a[i + 1]) {
|
404
|
+
#{yield `(a[i] || "") + (a[i + 1] || "")`};
|
405
|
+
}
|
406
|
+
}
|
407
|
+
return self;
|
408
|
+
}
|
409
|
+
|
410
|
+
chomped = #{chomp(separator)};
|
411
|
+
trailing = self.length != chomped.length;
|
412
|
+
splitted = chomped.split(separator);
|
413
|
+
|
414
|
+
for (i = 0, length = splitted.length; i < length; i++) {
|
415
|
+
if (i < length - 1 || trailing) {
|
416
|
+
#{yield `splitted[i] + separator`};
|
417
|
+
}
|
418
|
+
else {
|
419
|
+
#{yield `splitted[i]`};
|
420
|
+
}
|
421
|
+
}
|
422
|
+
}
|
423
|
+
|
424
|
+
self
|
425
|
+
end
|
426
|
+
|
427
|
+
def empty?
|
428
|
+
`self.length === 0`
|
429
|
+
end
|
430
|
+
|
431
|
+
def end_with?(*suffixes)
|
432
|
+
%x{
|
433
|
+
for (var i = 0, length = suffixes.length; i < length; i++) {
|
434
|
+
var suffix = #{Opal.coerce_to(`suffixes[i]`, String, :to_str).to_s};
|
435
|
+
|
436
|
+
if (self.length >= suffix.length &&
|
437
|
+
self.substr(self.length - suffix.length, suffix.length) == suffix) {
|
438
|
+
return true;
|
439
|
+
}
|
440
|
+
}
|
441
|
+
}
|
442
|
+
|
443
|
+
false
|
444
|
+
end
|
445
|
+
|
446
|
+
alias eql? ==
|
447
|
+
alias equal? ===
|
448
|
+
|
449
|
+
def gsub(pattern, replacement = undefined, &block)
|
450
|
+
%x{
|
451
|
+
if (replacement === undefined && block === nil) {
|
452
|
+
#{return enum_for :gsub, pattern}
|
453
|
+
}
|
454
|
+
|
455
|
+
var result = '', match_data = nil, index = 0, match, _replacement;
|
456
|
+
|
457
|
+
if (pattern.$$is_regexp) {
|
458
|
+
pattern = new RegExp(pattern.source, 'gm' + (pattern.ignoreCase ? 'i' : ''));
|
459
|
+
} else {
|
460
|
+
pattern = #{Opal.coerce_to(`pattern`, String, :to_str)};
|
461
|
+
pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gm');
|
462
|
+
}
|
463
|
+
|
464
|
+
while (true) {
|
465
|
+
match = pattern.exec(self);
|
466
|
+
|
467
|
+
if (match === null) {
|
468
|
+
#{$~ = nil}
|
469
|
+
result += self.slice(index);
|
470
|
+
break;
|
471
|
+
}
|
472
|
+
|
473
|
+
match_data = #{MatchData.new `pattern`, `match`};
|
474
|
+
|
475
|
+
if (replacement === undefined) {
|
476
|
+
_replacement = block(match[0]);
|
477
|
+
}
|
478
|
+
else if (replacement.$$is_hash) {
|
479
|
+
_replacement = #{`replacement`[`match[0]`].to_s};
|
480
|
+
}
|
481
|
+
else {
|
482
|
+
if (!replacement.$$is_string) {
|
483
|
+
replacement = #{Opal.coerce_to(`replacement`, String, :to_str)};
|
484
|
+
}
|
485
|
+
_replacement = replacement.replace(/([\\]+)([0-9+&`'])/g, function (original, slashes, command) {
|
486
|
+
if (slashes.length % 2 === 0) {
|
487
|
+
return original;
|
488
|
+
}
|
489
|
+
switch (command) {
|
490
|
+
case "+":
|
491
|
+
for (var i = match.length - 1; i > 0; i--) {
|
492
|
+
if (match[i] !== undefined) {
|
493
|
+
return slashes.slice(1) + match[i];
|
494
|
+
}
|
495
|
+
}
|
496
|
+
return '';
|
497
|
+
case "&": return slashes.slice(1) + match[0];
|
498
|
+
case "`": return slashes.slice(1) + self.slice(0, match.index);
|
499
|
+
case "'": return slashes.slice(1) + self.slice(match.index + match[0].length);
|
500
|
+
default: return slashes.slice(1) + (match[command] || '');
|
501
|
+
}
|
502
|
+
}).replace(/\\\\/g, '\\');
|
503
|
+
}
|
504
|
+
|
505
|
+
if (pattern.lastIndex === match.index) {
|
506
|
+
result += (_replacement + self.slice(index, match.index + 1))
|
507
|
+
pattern.lastIndex += 1;
|
508
|
+
}
|
509
|
+
else {
|
510
|
+
result += (self.slice(index, match.index) + _replacement)
|
511
|
+
}
|
512
|
+
index = pattern.lastIndex;
|
513
|
+
}
|
514
|
+
|
515
|
+
#{$~ = `match_data`}
|
516
|
+
return result;
|
517
|
+
}
|
518
|
+
end
|
519
|
+
|
520
|
+
def gsub!(other)
|
521
|
+
raise NotImplementedError, `MUT_STR_ERR_MSG` % 'gsub!'
|
522
|
+
end
|
523
|
+
|
524
|
+
def hash
|
525
|
+
`self.toString()`
|
526
|
+
end
|
527
|
+
|
528
|
+
def hex
|
529
|
+
to_i 16
|
530
|
+
end
|
531
|
+
|
532
|
+
def include?(other)
|
533
|
+
%x{
|
534
|
+
if (other.$$is_string) {
|
535
|
+
return self.indexOf(other) !== -1;
|
536
|
+
}
|
537
|
+
}
|
538
|
+
|
539
|
+
unless other.respond_to? :to_str
|
540
|
+
raise TypeError, "no implicit conversion of #{other.class} into String"
|
541
|
+
end
|
542
|
+
|
543
|
+
`self.indexOf(#{other.to_str}) !== -1`
|
544
|
+
end
|
545
|
+
|
546
|
+
def index(search, offset = undefined)
|
547
|
+
%x{
|
548
|
+
var index,
|
549
|
+
match,
|
550
|
+
regex;
|
551
|
+
|
552
|
+
if (offset === undefined) {
|
553
|
+
offset = 0;
|
554
|
+
} else {
|
555
|
+
offset = #{Opal.coerce_to(`offset`, Integer, :to_int)};
|
556
|
+
if (offset < 0) {
|
557
|
+
offset += self.length;
|
558
|
+
if (offset < 0) {
|
559
|
+
return nil;
|
560
|
+
}
|
561
|
+
}
|
562
|
+
}
|
563
|
+
|
564
|
+
if (search.$$is_regexp) {
|
565
|
+
regex = new RegExp(search.source, 'gm' + (search.ignoreCase ? 'i' : ''));
|
566
|
+
while (true) {
|
567
|
+
match = regex.exec(self);
|
568
|
+
if (match === null) {
|
569
|
+
#{$~ = nil};
|
570
|
+
index = -1;
|
571
|
+
break;
|
572
|
+
}
|
573
|
+
if (match.index >= offset) {
|
574
|
+
#{$~ = MatchData.new(`regex`, `match`)}
|
575
|
+
index = match.index;
|
576
|
+
break;
|
577
|
+
}
|
578
|
+
regex.lastIndex = match.index + 1;
|
579
|
+
}
|
580
|
+
} else {
|
581
|
+
search = #{Opal.coerce_to(`search`, String, :to_str)};
|
582
|
+
if (search.length === 0 && offset > self.length) {
|
583
|
+
index = -1;
|
584
|
+
} else {
|
585
|
+
index = self.indexOf(search, offset);
|
586
|
+
}
|
587
|
+
}
|
588
|
+
|
589
|
+
return index === -1 ? nil : index;
|
590
|
+
}
|
591
|
+
end
|
592
|
+
|
593
|
+
def inspect
|
594
|
+
%x{
|
595
|
+
var escapable = /[\\\"\x00-\x1f\x7f-\x9f\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
596
|
+
meta = {
|
597
|
+
'\u0007': '\\a',
|
598
|
+
'\u001b': '\\e',
|
599
|
+
'\b': '\\b',
|
600
|
+
'\t': '\\t',
|
601
|
+
'\n': '\\n',
|
602
|
+
'\f': '\\f',
|
603
|
+
'\r': '\\r',
|
604
|
+
'\v': '\\v',
|
605
|
+
'"' : '\\"',
|
606
|
+
'\\': '\\\\'
|
607
|
+
},
|
608
|
+
escaped = self.replace(escapable, function (chr) {
|
609
|
+
return meta[chr] || '\\u' + ('0000' + chr.charCodeAt(0).toString(16).toUpperCase()).slice(-4);
|
610
|
+
});
|
611
|
+
return '"' + escaped.replace(/\#[\$\@\{]/g, '\\$&') + '"';
|
612
|
+
}
|
613
|
+
end
|
614
|
+
|
615
|
+
def intern
|
616
|
+
self
|
617
|
+
end
|
618
|
+
|
619
|
+
def lines(separator = $/, &block)
|
620
|
+
e = each_line(separator, &block)
|
621
|
+
block ? self : e.to_a
|
622
|
+
end
|
623
|
+
|
624
|
+
def length
|
625
|
+
`self.length`
|
626
|
+
end
|
627
|
+
|
628
|
+
def ljust(width, padstr = ' ')
|
629
|
+
width = Opal.coerce_to(width, Integer, :to_int)
|
630
|
+
padstr = Opal.coerce_to(padstr, String, :to_str).to_s
|
631
|
+
|
632
|
+
if padstr.empty?
|
633
|
+
raise ArgumentError, 'zero width padding'
|
634
|
+
end
|
635
|
+
|
636
|
+
return self if `width <= self.length`
|
637
|
+
|
638
|
+
%x{
|
639
|
+
var index = -1,
|
640
|
+
result = "";
|
641
|
+
|
642
|
+
width -= self.length;
|
643
|
+
|
644
|
+
while (++index < width) {
|
645
|
+
result += padstr;
|
646
|
+
}
|
647
|
+
|
648
|
+
return self + result.slice(0, width);
|
649
|
+
}
|
650
|
+
end
|
651
|
+
|
652
|
+
def lstrip
|
653
|
+
`self.replace(/^\s*/, '')`
|
654
|
+
end
|
655
|
+
|
656
|
+
def lstrip!(other)
|
657
|
+
raise NotImplementedError, `MUT_STR_ERR_MSG` % 'lstrip!'
|
658
|
+
end
|
659
|
+
|
660
|
+
def match(pattern, pos = undefined, &block)
|
661
|
+
if String === pattern || pattern.respond_to?(:to_str)
|
662
|
+
pattern = Regexp.new(pattern.to_str)
|
663
|
+
end
|
664
|
+
|
665
|
+
unless Regexp === pattern
|
666
|
+
raise TypeError, "wrong argument type #{pattern.class} (expected Regexp)"
|
667
|
+
end
|
668
|
+
|
669
|
+
pattern.match(self, pos, &block)
|
670
|
+
end
|
671
|
+
|
672
|
+
def next
|
673
|
+
%x{
|
674
|
+
var i = self.length;
|
675
|
+
if (i === 0) {
|
676
|
+
return '';
|
677
|
+
}
|
678
|
+
var result = self;
|
679
|
+
var first_alphanum_char_index = self.search(/[a-zA-Z0-9]/);
|
680
|
+
var carry = false;
|
681
|
+
var code;
|
682
|
+
while (i--) {
|
683
|
+
code = self.charCodeAt(i);
|
684
|
+
if ((code >= 48 && code <= 57) ||
|
685
|
+
(code >= 65 && code <= 90) ||
|
686
|
+
(code >= 97 && code <= 122)) {
|
687
|
+
switch (code) {
|
688
|
+
case 57:
|
689
|
+
carry = true;
|
690
|
+
code = 48;
|
691
|
+
break;
|
692
|
+
case 90:
|
693
|
+
carry = true;
|
694
|
+
code = 65;
|
695
|
+
break;
|
696
|
+
case 122:
|
697
|
+
carry = true;
|
698
|
+
code = 97;
|
699
|
+
break;
|
700
|
+
default:
|
701
|
+
carry = false;
|
702
|
+
code += 1;
|
703
|
+
}
|
704
|
+
} else {
|
705
|
+
if (first_alphanum_char_index === -1) {
|
706
|
+
if (code === 255) {
|
707
|
+
carry = true;
|
708
|
+
code = 0;
|
709
|
+
} else {
|
710
|
+
carry = false;
|
711
|
+
code += 1;
|
712
|
+
}
|
713
|
+
} else {
|
714
|
+
carry = true;
|
715
|
+
}
|
716
|
+
}
|
717
|
+
result = result.slice(0, i) + String.fromCharCode(code) + result.slice(i + 1);
|
718
|
+
if (carry && (i === 0 || i === first_alphanum_char_index)) {
|
719
|
+
switch (code) {
|
720
|
+
case 65:
|
721
|
+
break;
|
722
|
+
case 97:
|
723
|
+
break;
|
724
|
+
default:
|
725
|
+
code += 1;
|
726
|
+
}
|
727
|
+
if (i === 0) {
|
728
|
+
result = String.fromCharCode(code) + result;
|
729
|
+
} else {
|
730
|
+
result = result.slice(0, i) + String.fromCharCode(code) + result.slice(i);
|
731
|
+
}
|
732
|
+
carry = false;
|
733
|
+
}
|
734
|
+
if (!carry) {
|
735
|
+
break;
|
736
|
+
}
|
737
|
+
}
|
738
|
+
return result;
|
739
|
+
}
|
740
|
+
end
|
741
|
+
|
742
|
+
def next!(other)
|
743
|
+
raise NotImplementedError, `MUT_STR_ERR_MSG` % 'next!'
|
744
|
+
end
|
745
|
+
|
746
|
+
def oct
|
747
|
+
%x{
|
748
|
+
var result,
|
749
|
+
string = self,
|
750
|
+
radix = 8;
|
751
|
+
|
752
|
+
if (/^\s*_/.test(string)) {
|
753
|
+
return 0;
|
754
|
+
}
|
755
|
+
|
756
|
+
string = string.replace(/^(\s*[+-]?)(0[bodx]?)(.+)$/i, function (original, head, flag, tail) {
|
757
|
+
switch (tail.charAt(0)) {
|
758
|
+
case '+':
|
759
|
+
case '-':
|
760
|
+
return original;
|
761
|
+
case '0':
|
762
|
+
if (tail.charAt(1) === 'x' && flag === '0x') {
|
763
|
+
return original;
|
764
|
+
}
|
765
|
+
}
|
766
|
+
switch (flag) {
|
767
|
+
case '0b':
|
768
|
+
radix = 2;
|
769
|
+
break;
|
770
|
+
case '0':
|
771
|
+
case '0o':
|
772
|
+
radix = 8;
|
773
|
+
break;
|
774
|
+
case '0d':
|
775
|
+
radix = 10;
|
776
|
+
break;
|
777
|
+
case '0x':
|
778
|
+
radix = 16;
|
779
|
+
break;
|
780
|
+
}
|
781
|
+
return head + tail;
|
782
|
+
});
|
783
|
+
|
784
|
+
result = parseInt(string.replace(/_(?!_)/g, ''), radix);
|
785
|
+
return isNaN(result) ? 0 : result;
|
786
|
+
}
|
787
|
+
end
|
788
|
+
|
789
|
+
def ord
|
790
|
+
`self.charCodeAt(0)`
|
791
|
+
end
|
792
|
+
|
793
|
+
def partition(sep)
|
794
|
+
%x{
|
795
|
+
var i, m;
|
796
|
+
|
797
|
+
if (sep.$$is_regexp) {
|
798
|
+
m = sep.exec(self);
|
799
|
+
if (m === null) {
|
800
|
+
i = -1;
|
801
|
+
} else {
|
802
|
+
#{MatchData.new `sep`, `m`};
|
803
|
+
sep = m[0];
|
804
|
+
i = m.index;
|
805
|
+
}
|
806
|
+
} else {
|
807
|
+
sep = #{Opal.coerce_to(`sep`, String, :to_str)};
|
808
|
+
i = self.indexOf(sep);
|
809
|
+
}
|
810
|
+
|
811
|
+
if (i === -1) {
|
812
|
+
return [self, '', ''];
|
813
|
+
}
|
814
|
+
|
815
|
+
return [
|
816
|
+
self.slice(0, i),
|
817
|
+
self.slice(i, i + sep.length),
|
818
|
+
self.slice(i + sep.length)
|
819
|
+
];
|
820
|
+
}
|
821
|
+
end
|
822
|
+
|
823
|
+
def reverse
|
824
|
+
`self.split('').reverse().join('')`
|
825
|
+
end
|
826
|
+
|
827
|
+
def reverse!(other)
|
828
|
+
raise NotImplementedError, `MUT_STR_ERR_MSG` % 'reverse!'
|
829
|
+
end
|
830
|
+
|
831
|
+
def rindex(search, offset = undefined)
|
832
|
+
%x{
|
833
|
+
var i, m, r, _m;
|
834
|
+
|
835
|
+
if (offset === undefined) {
|
836
|
+
offset = self.length;
|
837
|
+
} else {
|
838
|
+
offset = #{Opal.coerce_to(`offset`, Integer, :to_int)};
|
839
|
+
if (offset < 0) {
|
840
|
+
offset += self.length;
|
841
|
+
if (offset < 0) {
|
842
|
+
return nil;
|
843
|
+
}
|
844
|
+
}
|
845
|
+
}
|
846
|
+
|
847
|
+
if (search.$$is_regexp) {
|
848
|
+
m = null;
|
849
|
+
r = new RegExp(search.source, 'gm' + (search.ignoreCase ? 'i' : ''));
|
850
|
+
while (true) {
|
851
|
+
_m = r.exec(self);
|
852
|
+
if (_m === null || _m.index > offset) {
|
853
|
+
break;
|
854
|
+
}
|
855
|
+
m = _m;
|
856
|
+
r.lastIndex = m.index + 1;
|
857
|
+
}
|
858
|
+
if (m === null) {
|
859
|
+
#{$~ = nil}
|
860
|
+
i = -1;
|
861
|
+
} else {
|
862
|
+
#{MatchData.new `r`, `m`};
|
863
|
+
i = m.index;
|
864
|
+
}
|
865
|
+
} else {
|
866
|
+
search = #{Opal.coerce_to(`search`, String, :to_str)};
|
867
|
+
i = self.lastIndexOf(search, offset);
|
868
|
+
}
|
869
|
+
|
870
|
+
return i === -1 ? nil : i;
|
871
|
+
}
|
872
|
+
end
|
873
|
+
|
874
|
+
def rjust(width, padstr = ' ')
|
875
|
+
width = Opal.coerce_to(width, Integer, :to_int)
|
876
|
+
padstr = Opal.coerce_to(padstr, String, :to_str).to_s
|
877
|
+
|
878
|
+
if padstr.empty?
|
879
|
+
raise ArgumentError, 'zero width padding'
|
880
|
+
end
|
881
|
+
|
882
|
+
return self if `width <= self.length`
|
883
|
+
|
884
|
+
%x{
|
885
|
+
var chars = Math.floor(width - self.length),
|
886
|
+
patterns = Math.floor(chars / padstr.length),
|
887
|
+
result = Array(patterns + 1).join(padstr),
|
888
|
+
remaining = chars - result.length;
|
889
|
+
|
890
|
+
return result + padstr.slice(0, remaining) + self;
|
891
|
+
}
|
892
|
+
end
|
893
|
+
|
894
|
+
def rpartition(sep)
|
895
|
+
%x{
|
896
|
+
var i, m, r, _m;
|
897
|
+
|
898
|
+
if (sep.$$is_regexp) {
|
899
|
+
m = null;
|
900
|
+
r = new RegExp(sep.source, 'gm' + (sep.ignoreCase ? 'i' : ''));
|
901
|
+
|
902
|
+
while (true) {
|
903
|
+
_m = r.exec(self);
|
904
|
+
if (_m === null) {
|
905
|
+
break;
|
906
|
+
}
|
907
|
+
m = _m;
|
908
|
+
r.lastIndex = m.index + 1;
|
909
|
+
}
|
910
|
+
|
911
|
+
if (m === null) {
|
912
|
+
i = -1;
|
913
|
+
} else {
|
914
|
+
#{MatchData.new `r`, `m`};
|
915
|
+
sep = m[0];
|
916
|
+
i = m.index;
|
917
|
+
}
|
918
|
+
|
919
|
+
} else {
|
920
|
+
sep = #{Opal.coerce_to(`sep`, String, :to_str)};
|
921
|
+
i = self.lastIndexOf(sep);
|
922
|
+
}
|
923
|
+
|
924
|
+
if (i === -1) {
|
925
|
+
return ['', '', self];
|
926
|
+
}
|
927
|
+
|
928
|
+
return [
|
929
|
+
self.slice(0, i),
|
930
|
+
self.slice(i, i + sep.length),
|
931
|
+
self.slice(i + sep.length)
|
932
|
+
];
|
933
|
+
}
|
934
|
+
end
|
935
|
+
|
936
|
+
def rstrip
|
937
|
+
`self.replace(/[\s\u0000]*$/, '')`
|
938
|
+
end
|
939
|
+
|
940
|
+
def scan(pattern, &block)
|
941
|
+
%x{
|
942
|
+
var result = [],
|
943
|
+
match_data = nil,
|
944
|
+
match;
|
945
|
+
|
946
|
+
if (pattern.$$is_regexp) {
|
947
|
+
pattern = new RegExp(pattern.source, 'gm' + (pattern.ignoreCase ? 'i' : ''));
|
948
|
+
} else {
|
949
|
+
pattern = #{Opal.coerce_to(`pattern`, String, :to_str)};
|
950
|
+
pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gm');
|
951
|
+
}
|
952
|
+
|
953
|
+
while ((match = pattern.exec(self)) != null) {
|
954
|
+
match_data = #{MatchData.new `pattern`, `match`};
|
955
|
+
if (block === nil) {
|
956
|
+
match.length == 1 ? result.push(match[0]) : result.push(#{`match_data`.captures});
|
957
|
+
} else {
|
958
|
+
match.length == 1 ? block(match[0]) : block.call(self, #{`match_data`.captures});
|
959
|
+
}
|
960
|
+
if (pattern.lastIndex === match.index) {
|
961
|
+
pattern.lastIndex += 1;
|
962
|
+
}
|
963
|
+
}
|
964
|
+
|
965
|
+
#{$~ = `match_data`}
|
966
|
+
|
967
|
+
return (block !== nil ? self : result);
|
968
|
+
}
|
969
|
+
end
|
970
|
+
|
971
|
+
alias size length
|
972
|
+
|
973
|
+
alias slice []
|
974
|
+
|
975
|
+
def slice!(other)
|
976
|
+
raise NotImplementedError, `MUT_STR_ERR_MSG` % 'slice!'
|
977
|
+
end
|
978
|
+
|
979
|
+
def split(pattern = undefined, limit = undefined)
|
980
|
+
%x{
|
981
|
+
if (self.length === 0) {
|
982
|
+
return [];
|
983
|
+
}
|
984
|
+
|
985
|
+
if (limit === undefined) {
|
986
|
+
limit = 0;
|
987
|
+
} else {
|
988
|
+
limit = #{Opal.coerce_to!(limit, Integer, :to_int)};
|
989
|
+
if (limit === 1) {
|
990
|
+
return [self];
|
991
|
+
}
|
992
|
+
}
|
993
|
+
|
994
|
+
if (pattern === undefined || pattern === nil) {
|
995
|
+
pattern = #{$; || ' '};
|
996
|
+
}
|
997
|
+
|
998
|
+
var result = [],
|
999
|
+
string = self.toString(),
|
1000
|
+
index = 0,
|
1001
|
+
match,
|
1002
|
+
i;
|
1003
|
+
|
1004
|
+
if (pattern.$$is_regexp) {
|
1005
|
+
pattern = new RegExp(pattern.source, 'gm' + (pattern.ignoreCase ? 'i' : ''));
|
1006
|
+
} else {
|
1007
|
+
pattern = #{Opal.coerce_to(pattern, String, :to_str).to_s};
|
1008
|
+
if (pattern === ' ') {
|
1009
|
+
pattern = /\s+/gm;
|
1010
|
+
string = string.replace(/^\s+/, '');
|
1011
|
+
} else {
|
1012
|
+
pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gm');
|
1013
|
+
}
|
1014
|
+
}
|
1015
|
+
|
1016
|
+
result = string.split(pattern);
|
1017
|
+
|
1018
|
+
if (result.length === 1 && result[0] === string) {
|
1019
|
+
return result;
|
1020
|
+
}
|
1021
|
+
|
1022
|
+
while ((i = result.indexOf(undefined)) !== -1) {
|
1023
|
+
result.splice(i, 1);
|
1024
|
+
}
|
1025
|
+
|
1026
|
+
if (limit === 0) {
|
1027
|
+
while (result[result.length - 1] === '') {
|
1028
|
+
result.length -= 1;
|
1029
|
+
}
|
1030
|
+
return result;
|
1031
|
+
}
|
1032
|
+
|
1033
|
+
match = pattern.exec(string);
|
1034
|
+
|
1035
|
+
if (limit < 0) {
|
1036
|
+
if (match !== null && match[0] === '' && pattern.source.indexOf('(?=') === -1) {
|
1037
|
+
for (i = 0; i < match.length; i++) {
|
1038
|
+
result.push('');
|
1039
|
+
}
|
1040
|
+
}
|
1041
|
+
return result;
|
1042
|
+
}
|
1043
|
+
|
1044
|
+
if (match !== null && match[0] === '') {
|
1045
|
+
result.splice(limit - 1, result.length - 1, result.slice(limit - 1).join(''));
|
1046
|
+
return result;
|
1047
|
+
}
|
1048
|
+
|
1049
|
+
i = 0;
|
1050
|
+
while (match !== null) {
|
1051
|
+
i++;
|
1052
|
+
index = pattern.lastIndex;
|
1053
|
+
if (i + 1 === limit) {
|
1054
|
+
break;
|
1055
|
+
}
|
1056
|
+
match = pattern.exec(string);
|
1057
|
+
}
|
1058
|
+
|
1059
|
+
result.splice(limit - 1, result.length - 1, string.slice(index));
|
1060
|
+
return result;
|
1061
|
+
}
|
1062
|
+
end
|
1063
|
+
|
1064
|
+
def squeeze(*sets)
|
1065
|
+
%x{
|
1066
|
+
if (sets.length === 0) {
|
1067
|
+
return self.replace(/(.)\1+/g, '$1');
|
1068
|
+
}
|
1069
|
+
var char_class = char_class_from_char_sets(sets);
|
1070
|
+
if (char_class === null) {
|
1071
|
+
return self;
|
1072
|
+
}
|
1073
|
+
return self.replace(new RegExp('(' + char_class + ')\\1+', 'g'), '$1');
|
1074
|
+
}
|
1075
|
+
end
|
1076
|
+
|
1077
|
+
def squeeze!(other)
|
1078
|
+
raise NotImplementedError, `MUT_STR_ERR_MSG` % 'squeeze!'
|
1079
|
+
end
|
1080
|
+
|
1081
|
+
def start_with?(*prefixes)
|
1082
|
+
%x{
|
1083
|
+
for (var i = 0, length = prefixes.length; i < length; i++) {
|
1084
|
+
var prefix = #{Opal.coerce_to(`prefixes[i]`, String, :to_str).to_s};
|
1085
|
+
|
1086
|
+
if (self.indexOf(prefix) === 0) {
|
1087
|
+
return true;
|
1088
|
+
}
|
1089
|
+
}
|
1090
|
+
|
1091
|
+
return false;
|
1092
|
+
}
|
1093
|
+
end
|
1094
|
+
|
1095
|
+
def strip
|
1096
|
+
`self.replace(/^\s*/, '').replace(/[\s\u0000]*$/, '')`
|
1097
|
+
end
|
1098
|
+
|
1099
|
+
def strip!(other)
|
1100
|
+
raise NotImplementedError, `MUT_STR_ERR_MSG` % 'strip!'
|
1101
|
+
end
|
1102
|
+
|
1103
|
+
def sub(pattern, replacement = undefined, &block)
|
1104
|
+
%x{
|
1105
|
+
if (!pattern.$$is_regexp) {
|
1106
|
+
pattern = #{Opal.coerce_to(`pattern`, String, :to_str)};
|
1107
|
+
pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
1108
|
+
}
|
1109
|
+
|
1110
|
+
var result = pattern.exec(self);
|
1111
|
+
|
1112
|
+
if (result === null) {
|
1113
|
+
#{$~ = nil}
|
1114
|
+
return self.toString();
|
1115
|
+
}
|
1116
|
+
|
1117
|
+
#{MatchData.new `pattern`, `result`}
|
1118
|
+
|
1119
|
+
if (replacement === undefined) {
|
1120
|
+
if (block === nil) {
|
1121
|
+
#{raise ArgumentError, 'wrong number of arguments (1 for 2)'}
|
1122
|
+
}
|
1123
|
+
return self.slice(0, result.index) + block(result[0]) + self.slice(result.index + result[0].length);
|
1124
|
+
}
|
1125
|
+
|
1126
|
+
if (replacement.$$is_hash) {
|
1127
|
+
return self.slice(0, result.index) + #{`replacement`[`result[0]`].to_s} + self.slice(result.index + result[0].length);
|
1128
|
+
}
|
1129
|
+
|
1130
|
+
replacement = #{Opal.coerce_to(`replacement`, String, :to_str)};
|
1131
|
+
|
1132
|
+
replacement = replacement.replace(/([\\]+)([0-9+&`'])/g, function (original, slashes, command) {
|
1133
|
+
if (slashes.length % 2 === 0) {
|
1134
|
+
return original;
|
1135
|
+
}
|
1136
|
+
switch (command) {
|
1137
|
+
case "+":
|
1138
|
+
for (var i = result.length - 1; i > 0; i--) {
|
1139
|
+
if (result[i] !== undefined) {
|
1140
|
+
return slashes.slice(1) + result[i];
|
1141
|
+
}
|
1142
|
+
}
|
1143
|
+
return '';
|
1144
|
+
case "&": return slashes.slice(1) + result[0];
|
1145
|
+
case "`": return slashes.slice(1) + self.slice(0, result.index);
|
1146
|
+
case "'": return slashes.slice(1) + self.slice(result.index + result[0].length);
|
1147
|
+
default: return slashes.slice(1) + (result[command] || '');
|
1148
|
+
}
|
1149
|
+
}).replace(/\\\\/g, '\\');
|
1150
|
+
|
1151
|
+
return self.slice(0, result.index) + replacement + self.slice(result.index + result[0].length);
|
1152
|
+
}
|
1153
|
+
end
|
1154
|
+
|
1155
|
+
def sub!(other)
|
1156
|
+
raise NotImplementedError, `MUT_STR_ERR_MSG` % 'sub!'
|
1157
|
+
end
|
1158
|
+
|
1159
|
+
alias succ next
|
1160
|
+
|
1161
|
+
def succ!(other)
|
1162
|
+
raise NotImplementedError, `MUT_STR_ERR_MSG` % 'succ!'
|
1163
|
+
end
|
1164
|
+
|
1165
|
+
def sum(n = 16)
|
1166
|
+
%x{
|
1167
|
+
n = #{Opal.coerce_to(`n`, Integer, :to_int)};
|
1168
|
+
|
1169
|
+
var result = 0,
|
1170
|
+
length = self.length,
|
1171
|
+
i = 0;
|
1172
|
+
|
1173
|
+
for (; i < length; i++) {
|
1174
|
+
result += self.charCodeAt(i);
|
1175
|
+
}
|
1176
|
+
|
1177
|
+
if (n <= 0) {
|
1178
|
+
return result;
|
1179
|
+
}
|
1180
|
+
|
1181
|
+
return result & (Math.pow(2, n) - 1);
|
1182
|
+
}
|
1183
|
+
end
|
1184
|
+
|
1185
|
+
def swapcase
|
1186
|
+
%x{
|
1187
|
+
var str = self.replace(/([a-z]+)|([A-Z]+)/g, function($0,$1,$2) {
|
1188
|
+
return $1 ? $0.toUpperCase() : $0.toLowerCase();
|
1189
|
+
});
|
1190
|
+
|
1191
|
+
if (self.constructor === String) {
|
1192
|
+
return str;
|
1193
|
+
}
|
1194
|
+
|
1195
|
+
return #{self.class.new `str`};
|
1196
|
+
}
|
1197
|
+
end
|
1198
|
+
|
1199
|
+
def swapcase!(other)
|
1200
|
+
raise NotImplementedError, `MUT_STR_ERR_MSG` % 'swapcase!'
|
1201
|
+
end
|
1202
|
+
|
1203
|
+
def to_f
|
1204
|
+
%x{
|
1205
|
+
if (self.charAt(0) === '_') {
|
1206
|
+
return 0;
|
1207
|
+
}
|
1208
|
+
|
1209
|
+
var result = parseFloat(self.replace(/_/g, ''));
|
1210
|
+
|
1211
|
+
if (isNaN(result) || result == Infinity || result == -Infinity) {
|
1212
|
+
return 0;
|
1213
|
+
}
|
1214
|
+
else {
|
1215
|
+
return result;
|
1216
|
+
}
|
1217
|
+
}
|
1218
|
+
end
|
1219
|
+
|
1220
|
+
def to_i(base = 10)
|
1221
|
+
%x{
|
1222
|
+
var result,
|
1223
|
+
string = self.toLowerCase(),
|
1224
|
+
radix = #{Opal.coerce_to(`base`, Integer, :to_int)};
|
1225
|
+
|
1226
|
+
if (radix === 1 || radix < 0 || radix > 36) {
|
1227
|
+
#{raise ArgumentError, "invalid radix #{`radix`}"}
|
1228
|
+
}
|
1229
|
+
|
1230
|
+
if (/^\s*_/.test(string)) {
|
1231
|
+
return 0;
|
1232
|
+
}
|
1233
|
+
|
1234
|
+
string = string.replace(/^(\s*[+-]?)(0[bodx]?)(.+)$/, function (original, head, flag, tail) {
|
1235
|
+
switch (tail.charAt(0)) {
|
1236
|
+
case '+':
|
1237
|
+
case '-':
|
1238
|
+
return original;
|
1239
|
+
case '0':
|
1240
|
+
if (tail.charAt(1) === 'x' && flag === '0x' && (radix === 0 || radix === 16)) {
|
1241
|
+
return original;
|
1242
|
+
}
|
1243
|
+
}
|
1244
|
+
switch (flag) {
|
1245
|
+
case '0b':
|
1246
|
+
if (radix === 0 || radix === 2) {
|
1247
|
+
radix = 2;
|
1248
|
+
return head + tail;
|
1249
|
+
}
|
1250
|
+
break;
|
1251
|
+
case '0':
|
1252
|
+
case '0o':
|
1253
|
+
if (radix === 0 || radix === 8) {
|
1254
|
+
radix = 8;
|
1255
|
+
return head + tail;
|
1256
|
+
}
|
1257
|
+
break;
|
1258
|
+
case '0d':
|
1259
|
+
if (radix === 0 || radix === 10) {
|
1260
|
+
radix = 10;
|
1261
|
+
return head + tail;
|
1262
|
+
}
|
1263
|
+
break;
|
1264
|
+
case '0x':
|
1265
|
+
if (radix === 0 || radix === 16) {
|
1266
|
+
radix = 16;
|
1267
|
+
return head + tail;
|
1268
|
+
}
|
1269
|
+
break;
|
1270
|
+
}
|
1271
|
+
return original
|
1272
|
+
});
|
1273
|
+
|
1274
|
+
result = parseInt(string.replace(/_(?!_)/g, ''), radix);
|
1275
|
+
return isNaN(result) ? 0 : result;
|
1276
|
+
}
|
1277
|
+
end
|
1278
|
+
|
1279
|
+
def to_proc
|
1280
|
+
# Give name to self in case this proc is passed to instance_eval
|
1281
|
+
sym = self
|
1282
|
+
|
1283
|
+
proc do |*args, &block|
|
1284
|
+
raise ArgumentError, "no receiver given" if args.empty?
|
1285
|
+
obj = args.shift
|
1286
|
+
obj.__send__(sym, *args, &block)
|
1287
|
+
end
|
1288
|
+
end
|
1289
|
+
|
1290
|
+
def to_s
|
1291
|
+
`self.toString()`
|
1292
|
+
end
|
1293
|
+
|
1294
|
+
alias to_str to_s
|
1295
|
+
|
1296
|
+
alias to_sym intern
|
1297
|
+
|
1298
|
+
def tr(from, to)
|
1299
|
+
from = Opal.coerce_to(from, String, :to_str).to_s
|
1300
|
+
to = Opal.coerce_to(to, String, :to_str).to_s
|
1301
|
+
%x{
|
1302
|
+
if (from.length == 0 || from === to) {
|
1303
|
+
return self;
|
1304
|
+
}
|
1305
|
+
|
1306
|
+
var i, in_range, c, ch, start, end, length;
|
1307
|
+
var subs = {};
|
1308
|
+
var from_chars = from.split('');
|
1309
|
+
var from_length = from_chars.length;
|
1310
|
+
var to_chars = to.split('');
|
1311
|
+
var to_length = to_chars.length;
|
1312
|
+
|
1313
|
+
var inverse = false;
|
1314
|
+
var global_sub = null;
|
1315
|
+
if (from_chars[0] === '^' && from_chars.length > 1) {
|
1316
|
+
inverse = true;
|
1317
|
+
from_chars.shift();
|
1318
|
+
global_sub = to_chars[to_length - 1]
|
1319
|
+
from_length -= 1;
|
1320
|
+
}
|
1321
|
+
|
1322
|
+
var from_chars_expanded = [];
|
1323
|
+
var last_from = null;
|
1324
|
+
in_range = false;
|
1325
|
+
for (i = 0; i < from_length; i++) {
|
1326
|
+
ch = from_chars[i];
|
1327
|
+
if (last_from == null) {
|
1328
|
+
last_from = ch;
|
1329
|
+
from_chars_expanded.push(ch);
|
1330
|
+
}
|
1331
|
+
else if (ch === '-') {
|
1332
|
+
if (last_from === '-') {
|
1333
|
+
from_chars_expanded.push('-');
|
1334
|
+
from_chars_expanded.push('-');
|
1335
|
+
}
|
1336
|
+
else if (i == from_length - 1) {
|
1337
|
+
from_chars_expanded.push('-');
|
1338
|
+
}
|
1339
|
+
else {
|
1340
|
+
in_range = true;
|
1341
|
+
}
|
1342
|
+
}
|
1343
|
+
else if (in_range) {
|
1344
|
+
start = last_from.charCodeAt(0);
|
1345
|
+
end = ch.charCodeAt(0);
|
1346
|
+
if (start > end) {
|
1347
|
+
#{raise ArgumentError, "invalid range \"#{`String.fromCharCode(start)`}-#{`String.fromCharCode(end)`}\" in string transliteration"}
|
1348
|
+
}
|
1349
|
+
for (c = start + 1; c < end; c++) {
|
1350
|
+
from_chars_expanded.push(String.fromCharCode(c));
|
1351
|
+
}
|
1352
|
+
from_chars_expanded.push(ch);
|
1353
|
+
in_range = null;
|
1354
|
+
last_from = null;
|
1355
|
+
}
|
1356
|
+
else {
|
1357
|
+
from_chars_expanded.push(ch);
|
1358
|
+
}
|
1359
|
+
}
|
1360
|
+
|
1361
|
+
from_chars = from_chars_expanded;
|
1362
|
+
from_length = from_chars.length;
|
1363
|
+
|
1364
|
+
if (inverse) {
|
1365
|
+
for (i = 0; i < from_length; i++) {
|
1366
|
+
subs[from_chars[i]] = true;
|
1367
|
+
}
|
1368
|
+
}
|
1369
|
+
else {
|
1370
|
+
if (to_length > 0) {
|
1371
|
+
var to_chars_expanded = [];
|
1372
|
+
var last_to = null;
|
1373
|
+
in_range = false;
|
1374
|
+
for (i = 0; i < to_length; i++) {
|
1375
|
+
ch = to_chars[i];
|
1376
|
+
if (last_from == null) {
|
1377
|
+
last_from = ch;
|
1378
|
+
to_chars_expanded.push(ch);
|
1379
|
+
}
|
1380
|
+
else if (ch === '-') {
|
1381
|
+
if (last_to === '-') {
|
1382
|
+
to_chars_expanded.push('-');
|
1383
|
+
to_chars_expanded.push('-');
|
1384
|
+
}
|
1385
|
+
else if (i == to_length - 1) {
|
1386
|
+
to_chars_expanded.push('-');
|
1387
|
+
}
|
1388
|
+
else {
|
1389
|
+
in_range = true;
|
1390
|
+
}
|
1391
|
+
}
|
1392
|
+
else if (in_range) {
|
1393
|
+
start = last_from.charCodeAt(0);
|
1394
|
+
end = ch.charCodeAt(0);
|
1395
|
+
if (start > end) {
|
1396
|
+
#{raise ArgumentError, "invalid range \"#{`String.fromCharCode(start)`}-#{`String.fromCharCode(end)`}\" in string transliteration"}
|
1397
|
+
}
|
1398
|
+
for (c = start + 1; c < end; c++) {
|
1399
|
+
to_chars_expanded.push(String.fromCharCode(c));
|
1400
|
+
}
|
1401
|
+
to_chars_expanded.push(ch);
|
1402
|
+
in_range = null;
|
1403
|
+
last_from = null;
|
1404
|
+
}
|
1405
|
+
else {
|
1406
|
+
to_chars_expanded.push(ch);
|
1407
|
+
}
|
1408
|
+
}
|
1409
|
+
|
1410
|
+
to_chars = to_chars_expanded;
|
1411
|
+
to_length = to_chars.length;
|
1412
|
+
}
|
1413
|
+
|
1414
|
+
var length_diff = from_length - to_length;
|
1415
|
+
if (length_diff > 0) {
|
1416
|
+
var pad_char = (to_length > 0 ? to_chars[to_length - 1] : '');
|
1417
|
+
for (i = 0; i < length_diff; i++) {
|
1418
|
+
to_chars.push(pad_char);
|
1419
|
+
}
|
1420
|
+
}
|
1421
|
+
|
1422
|
+
for (i = 0; i < from_length; i++) {
|
1423
|
+
subs[from_chars[i]] = to_chars[i];
|
1424
|
+
}
|
1425
|
+
}
|
1426
|
+
|
1427
|
+
var new_str = ''
|
1428
|
+
for (i = 0, length = self.length; i < length; i++) {
|
1429
|
+
ch = self.charAt(i);
|
1430
|
+
var sub = subs[ch];
|
1431
|
+
if (inverse) {
|
1432
|
+
new_str += (sub == null ? global_sub : ch);
|
1433
|
+
}
|
1434
|
+
else {
|
1435
|
+
new_str += (sub != null ? sub : ch);
|
1436
|
+
}
|
1437
|
+
}
|
1438
|
+
return new_str;
|
1439
|
+
}
|
1440
|
+
end
|
1441
|
+
|
1442
|
+
def tr!(other)
|
1443
|
+
raise NotImplementedError, `MUT_STR_ERR_MSG` % 'tr!'
|
1444
|
+
end
|
1445
|
+
|
1446
|
+
def tr_s(from, to)
|
1447
|
+
from = Opal.coerce_to(from, String, :to_str).to_s
|
1448
|
+
to = Opal.coerce_to(to, String, :to_str).to_s
|
1449
|
+
%x{
|
1450
|
+
if (from.length == 0) {
|
1451
|
+
return self;
|
1452
|
+
}
|
1453
|
+
|
1454
|
+
var i, in_range, c, ch, start, end, length;
|
1455
|
+
var subs = {};
|
1456
|
+
var from_chars = from.split('');
|
1457
|
+
var from_length = from_chars.length;
|
1458
|
+
var to_chars = to.split('');
|
1459
|
+
var to_length = to_chars.length;
|
1460
|
+
|
1461
|
+
var inverse = false;
|
1462
|
+
var global_sub = null;
|
1463
|
+
if (from_chars[0] === '^' && from_chars.length > 1) {
|
1464
|
+
inverse = true;
|
1465
|
+
from_chars.shift();
|
1466
|
+
global_sub = to_chars[to_length - 1]
|
1467
|
+
from_length -= 1;
|
1468
|
+
}
|
1469
|
+
|
1470
|
+
var from_chars_expanded = [];
|
1471
|
+
var last_from = null;
|
1472
|
+
in_range = false;
|
1473
|
+
for (i = 0; i < from_length; i++) {
|
1474
|
+
ch = from_chars[i];
|
1475
|
+
if (last_from == null) {
|
1476
|
+
last_from = ch;
|
1477
|
+
from_chars_expanded.push(ch);
|
1478
|
+
}
|
1479
|
+
else if (ch === '-') {
|
1480
|
+
if (last_from === '-') {
|
1481
|
+
from_chars_expanded.push('-');
|
1482
|
+
from_chars_expanded.push('-');
|
1483
|
+
}
|
1484
|
+
else if (i == from_length - 1) {
|
1485
|
+
from_chars_expanded.push('-');
|
1486
|
+
}
|
1487
|
+
else {
|
1488
|
+
in_range = true;
|
1489
|
+
}
|
1490
|
+
}
|
1491
|
+
else if (in_range) {
|
1492
|
+
start = last_from.charCodeAt(0);
|
1493
|
+
end = ch.charCodeAt(0);
|
1494
|
+
if (start > end) {
|
1495
|
+
#{raise ArgumentError, "invalid range \"#{`String.fromCharCode(start)`}-#{`String.fromCharCode(end)`}\" in string transliteration"}
|
1496
|
+
}
|
1497
|
+
for (c = start + 1; c < end; c++) {
|
1498
|
+
from_chars_expanded.push(String.fromCharCode(c));
|
1499
|
+
}
|
1500
|
+
from_chars_expanded.push(ch);
|
1501
|
+
in_range = null;
|
1502
|
+
last_from = null;
|
1503
|
+
}
|
1504
|
+
else {
|
1505
|
+
from_chars_expanded.push(ch);
|
1506
|
+
}
|
1507
|
+
}
|
1508
|
+
|
1509
|
+
from_chars = from_chars_expanded;
|
1510
|
+
from_length = from_chars.length;
|
1511
|
+
|
1512
|
+
if (inverse) {
|
1513
|
+
for (i = 0; i < from_length; i++) {
|
1514
|
+
subs[from_chars[i]] = true;
|
1515
|
+
}
|
1516
|
+
}
|
1517
|
+
else {
|
1518
|
+
if (to_length > 0) {
|
1519
|
+
var to_chars_expanded = [];
|
1520
|
+
var last_to = null;
|
1521
|
+
in_range = false;
|
1522
|
+
for (i = 0; i < to_length; i++) {
|
1523
|
+
ch = to_chars[i];
|
1524
|
+
if (last_from == null) {
|
1525
|
+
last_from = ch;
|
1526
|
+
to_chars_expanded.push(ch);
|
1527
|
+
}
|
1528
|
+
else if (ch === '-') {
|
1529
|
+
if (last_to === '-') {
|
1530
|
+
to_chars_expanded.push('-');
|
1531
|
+
to_chars_expanded.push('-');
|
1532
|
+
}
|
1533
|
+
else if (i == to_length - 1) {
|
1534
|
+
to_chars_expanded.push('-');
|
1535
|
+
}
|
1536
|
+
else {
|
1537
|
+
in_range = true;
|
1538
|
+
}
|
1539
|
+
}
|
1540
|
+
else if (in_range) {
|
1541
|
+
start = last_from.charCodeAt(0);
|
1542
|
+
end = ch.charCodeAt(0);
|
1543
|
+
if (start > end) {
|
1544
|
+
#{raise ArgumentError, "invalid range \"#{`String.fromCharCode(start)`}-#{`String.fromCharCode(end)`}\" in string transliteration"}
|
1545
|
+
}
|
1546
|
+
for (c = start + 1; c < end; c++) {
|
1547
|
+
to_chars_expanded.push(String.fromCharCode(c));
|
1548
|
+
}
|
1549
|
+
to_chars_expanded.push(ch);
|
1550
|
+
in_range = null;
|
1551
|
+
last_from = null;
|
1552
|
+
}
|
1553
|
+
else {
|
1554
|
+
to_chars_expanded.push(ch);
|
1555
|
+
}
|
1556
|
+
}
|
1557
|
+
|
1558
|
+
to_chars = to_chars_expanded;
|
1559
|
+
to_length = to_chars.length;
|
1560
|
+
}
|
1561
|
+
|
1562
|
+
var length_diff = from_length - to_length;
|
1563
|
+
if (length_diff > 0) {
|
1564
|
+
var pad_char = (to_length > 0 ? to_chars[to_length - 1] : '');
|
1565
|
+
for (i = 0; i < length_diff; i++) {
|
1566
|
+
to_chars.push(pad_char);
|
1567
|
+
}
|
1568
|
+
}
|
1569
|
+
|
1570
|
+
for (i = 0; i < from_length; i++) {
|
1571
|
+
subs[from_chars[i]] = to_chars[i];
|
1572
|
+
}
|
1573
|
+
}
|
1574
|
+
var new_str = ''
|
1575
|
+
var last_substitute = null
|
1576
|
+
for (i = 0, length = self.length; i < length; i++) {
|
1577
|
+
ch = self.charAt(i);
|
1578
|
+
var sub = subs[ch]
|
1579
|
+
if (inverse) {
|
1580
|
+
if (sub == null) {
|
1581
|
+
if (last_substitute == null) {
|
1582
|
+
new_str += global_sub;
|
1583
|
+
last_substitute = true;
|
1584
|
+
}
|
1585
|
+
}
|
1586
|
+
else {
|
1587
|
+
new_str += ch;
|
1588
|
+
last_substitute = null;
|
1589
|
+
}
|
1590
|
+
}
|
1591
|
+
else {
|
1592
|
+
if (sub != null) {
|
1593
|
+
if (last_substitute == null || last_substitute !== sub) {
|
1594
|
+
new_str += sub;
|
1595
|
+
last_substitute = sub;
|
1596
|
+
}
|
1597
|
+
}
|
1598
|
+
else {
|
1599
|
+
new_str += ch;
|
1600
|
+
last_substitute = null;
|
1601
|
+
}
|
1602
|
+
}
|
1603
|
+
}
|
1604
|
+
return new_str;
|
1605
|
+
}
|
1606
|
+
end
|
1607
|
+
|
1608
|
+
def tr_s!(other)
|
1609
|
+
raise NotImplementedError, `MUT_STR_ERR_MSG` % 'tr_s!'
|
1610
|
+
end
|
1611
|
+
|
1612
|
+
def upcase
|
1613
|
+
`self.toUpperCase()`
|
1614
|
+
end
|
1615
|
+
|
1616
|
+
def upcase!(other)
|
1617
|
+
raise NotImplementedError, `MUT_STR_ERR_MSG` % 'upcase!'
|
1618
|
+
end
|
1619
|
+
|
1620
|
+
def freeze
|
1621
|
+
self
|
1622
|
+
end
|
1623
|
+
|
1624
|
+
def frozen?
|
1625
|
+
true
|
1626
|
+
end
|
1627
|
+
|
1628
|
+
def upto(stop, excl = false, &block)
|
1629
|
+
return enum_for :upto, stop, excl unless block_given?
|
1630
|
+
stop = Opal.coerce_to(stop, String, :to_str)
|
1631
|
+
%x{
|
1632
|
+
var a, b, s = self.toString();
|
1633
|
+
|
1634
|
+
if (s.length === 1 && stop.length === 1) {
|
1635
|
+
|
1636
|
+
a = s.charCodeAt(0);
|
1637
|
+
b = stop.charCodeAt(0);
|
1638
|
+
|
1639
|
+
while (a <= b) {
|
1640
|
+
if (excl && a === b) {
|
1641
|
+
break;
|
1642
|
+
}
|
1643
|
+
block(String.fromCharCode(a));
|
1644
|
+
a += 1;
|
1645
|
+
}
|
1646
|
+
|
1647
|
+
} else if (parseInt(s, 10).toString() === s && parseInt(stop, 10).toString() === stop) {
|
1648
|
+
|
1649
|
+
a = parseInt(s, 10);
|
1650
|
+
b = parseInt(stop, 10);
|
1651
|
+
|
1652
|
+
while (a <= b) {
|
1653
|
+
if (excl && a === b) {
|
1654
|
+
break;
|
1655
|
+
}
|
1656
|
+
block(a.toString());
|
1657
|
+
a += 1;
|
1658
|
+
}
|
1659
|
+
|
1660
|
+
} else {
|
1661
|
+
|
1662
|
+
while (s.length <= stop.length && s <= stop) {
|
1663
|
+
if (excl && s === stop) {
|
1664
|
+
break;
|
1665
|
+
}
|
1666
|
+
block(s);
|
1667
|
+
s = #{`s`.succ};
|
1668
|
+
}
|
1669
|
+
|
1670
|
+
}
|
1671
|
+
return self;
|
1672
|
+
}
|
1673
|
+
end
|
1674
|
+
|
1675
|
+
%x{
|
1676
|
+
function char_class_from_char_sets(sets) {
|
1677
|
+
function explode_sequences_in_character_set(set) {
|
1678
|
+
var result = '',
|
1679
|
+
i, len = set.length,
|
1680
|
+
curr_char,
|
1681
|
+
skip_next_dash,
|
1682
|
+
char_code_from,
|
1683
|
+
char_code_upto,
|
1684
|
+
char_code;
|
1685
|
+
for (i = 0; i < len; i++) {
|
1686
|
+
curr_char = set.charAt(i);
|
1687
|
+
if (curr_char === '-' && i > 0 && i < (len - 1) && !skip_next_dash) {
|
1688
|
+
char_code_from = set.charCodeAt(i - 1);
|
1689
|
+
char_code_upto = set.charCodeAt(i + 1);
|
1690
|
+
if (char_code_from > char_code_upto) {
|
1691
|
+
#{raise ArgumentError, "invalid range \"#{`char_code_from`}-#{`char_code_upto`}\" in string transliteration"}
|
1692
|
+
}
|
1693
|
+
for (char_code = char_code_from + 1; char_code < char_code_upto + 1; char_code++) {
|
1694
|
+
result += String.fromCharCode(char_code);
|
1695
|
+
}
|
1696
|
+
skip_next_dash = true;
|
1697
|
+
i++;
|
1698
|
+
} else {
|
1699
|
+
skip_next_dash = (curr_char === '\\');
|
1700
|
+
result += curr_char;
|
1701
|
+
}
|
1702
|
+
}
|
1703
|
+
return result;
|
1704
|
+
}
|
1705
|
+
|
1706
|
+
function intersection(setA, setB) {
|
1707
|
+
if (setA.length === 0) {
|
1708
|
+
return setB;
|
1709
|
+
}
|
1710
|
+
var result = '',
|
1711
|
+
i, len = setA.length,
|
1712
|
+
chr;
|
1713
|
+
for (i = 0; i < len; i++) {
|
1714
|
+
chr = setA.charAt(i);
|
1715
|
+
if (setB.indexOf(chr) !== -1) {
|
1716
|
+
result += chr;
|
1717
|
+
}
|
1718
|
+
}
|
1719
|
+
return result;
|
1720
|
+
}
|
1721
|
+
|
1722
|
+
var i, len, set, neg, chr, tmp,
|
1723
|
+
pos_intersection = '',
|
1724
|
+
neg_intersection = '';
|
1725
|
+
|
1726
|
+
for (i = 0, len = sets.length; i < len; i++) {
|
1727
|
+
set = #{Opal.coerce_to(`sets[i]`, String, :to_str)};
|
1728
|
+
neg = (set.charAt(0) === '^' && set.length > 1);
|
1729
|
+
set = explode_sequences_in_character_set(neg ? set.slice(1) : set);
|
1730
|
+
if (neg) {
|
1731
|
+
neg_intersection = intersection(neg_intersection, set);
|
1732
|
+
} else {
|
1733
|
+
pos_intersection = intersection(pos_intersection, set);
|
1734
|
+
}
|
1735
|
+
}
|
1736
|
+
|
1737
|
+
if (pos_intersection.length > 0 && neg_intersection.length > 0) {
|
1738
|
+
tmp = '';
|
1739
|
+
for (i = 0, len = pos_intersection.length; i < len; i++) {
|
1740
|
+
chr = pos_intersection.charAt(i);
|
1741
|
+
if (neg_intersection.indexOf(chr) === -1) {
|
1742
|
+
tmp += chr;
|
1743
|
+
}
|
1744
|
+
}
|
1745
|
+
pos_intersection = tmp;
|
1746
|
+
neg_intersection = '';
|
1747
|
+
}
|
1748
|
+
|
1749
|
+
if (pos_intersection.length > 0) {
|
1750
|
+
return '[' + #{Regexp.escape(`pos_intersection`)} + ']';
|
1751
|
+
}
|
1752
|
+
|
1753
|
+
if (neg_intersection.length > 0) {
|
1754
|
+
return '[^' + #{Regexp.escape(`neg_intersection`)} + ']';
|
1755
|
+
}
|
1756
|
+
|
1757
|
+
return null;
|
1758
|
+
}
|
1759
|
+
}
|
1760
|
+
end
|
1761
|
+
|
1762
|
+
Symbol = String
|