Class: CharacterSet
- Inherits:
-
Object
- Object
- CharacterSet
- Extended by:
- PredefinedSets
- Includes:
- SetMethodAdapters, SharedMethods, Enumerable
- Defined in:
- lib/character_set/pure.rb,
lib/character_set.rb,
lib/character_set/parser.rb,
lib/character_set/writer.rb,
lib/character_set/version.rb,
lib/character_set/character.rb,
lib/character_set/ruby_fallback.rb,
lib/character_set/shared_methods.rb,
lib/character_set/predefined_sets.rb,
lib/character_set/core_ext/regexp_ext.rb,
lib/character_set/core_ext/string_ext.rb,
lib/character_set/set_method_adapters.rb,
lib/character_set/expression_converter.rb,
lib/character_set/ruby_fallback/set_methods.rb,
lib/character_set/ruby_fallback/character_set_methods.rb,
ext/character_set/character_set.c
Overview
Various methods shared by the pure-Ruby and the extended implementation.
Many of these methods are hotspots, so they are defined directly on the including classes for better performance.
Defined Under Namespace
Modules: CoreExt, ExpressionConverter, Parser, PredefinedSets, RubyFallback, SetMethodAdapters, SharedMethods, Writer Classes: Character, Pure
Constant Summary collapse
- VERSION =
'1.4.0'
Class Method Summary collapse
-
.from_ranges(ranges) ⇒ Object
******************************.
- .of(str) ⇒ Object
Instance Method Summary collapse
- #&(other) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #<(other) ⇒ Object
- #<<(cp_num) ⇒ Object
- #<=(other) ⇒ Object
- #==(other) ⇒ Object
- #===(num) ⇒ Object
- #>(other) ⇒ Object
- #>=(other) ⇒ Object
- #^(other) ⇒ Object
- #add(cp_num) ⇒ Object
- #add?(cp_num) ⇒ Boolean
- #allocated_length ⇒ Object
- #case_insensitive ⇒ Object
- #clear ⇒ Object
- #count_in(str) ⇒ Object
- #cover?(str) ⇒ Boolean
- #delete(cp_num) ⇒ Object
- #delete?(cp_num) ⇒ Boolean
- #delete_if ⇒ Object
- #delete_in(str) ⇒ Object
- #delete_in!(str) ⇒ Object
- #difference(other) ⇒ Object
- #disjoint?(other) ⇒ Boolean
-
#each ⇒ Object
Setcompatibility methods. - #empty? ⇒ Boolean
- #eql?(other) ⇒ Boolean
- #ext_count_in_section(from, upto) ⇒ Object
- #ext_inversion(*args) ⇒ Object
- #ext_section(from, upto) ⇒ Object
- #ext_section?(from, upto) ⇒ Boolean
- #ext_section_ratio(from, upto) ⇒ Object
- #hash ⇒ Object
- #include?(num) ⇒ Boolean
- #initialize_clone(orig) ⇒ Object
- #initialize_dup(orig) ⇒ Object
- #intersect?(other) ⇒ Boolean
- #intersection(other) ⇒ Object
- #keep_if ⇒ Object
- #keep_in(str) ⇒ Object
- #keep_in!(str) ⇒ Object
- #length ⇒ Object
- #max ⇒ Object
- #member?(num) ⇒ Boolean
- #member_in_plane?(plane_num) ⇒ Boolean
- #merge(other) ⇒ Object
- #min ⇒ Object
- #minmax ⇒ Object
- #plane(plane_num) ⇒ Object
- #planes ⇒ Object
- #proper_subset?(other) ⇒ Boolean
- #proper_superset?(other) ⇒ Boolean
- #ranges ⇒ Object
- #sample(*args) ⇒ Object
- #scan(str) ⇒ Object
- #size ⇒ Object
- #subset?(other) ⇒ Boolean
- #subtract(other) ⇒ Object
- #superset?(other) ⇒ Boolean
-
#to_a(*args) ⇒ Object
returns an Array of Strings of length 1 if passed
true. - #union(other) ⇒ Object
- #used_by?(str) ⇒ Boolean
- #|(other) ⇒ Object
Methods included from PredefinedSets
Methods included from SharedMethods
Class Method Details
.from_ranges(ranges) ⇒ Object
******************************
679 680 681 682 683 684 685 686 687 688 689 690 |
# File 'ext/character_set/character_set.c', line 679
static VALUE
cs_class_method_from_ranges(VALUE self, VALUE ranges)
{
VALUE new_cs, range_count, i;
new_cs = rb_class_new_instance(0, 0, self);
range_count = RARRAY_LEN(ranges);
for (i = 0; i < range_count; i++)
{
cs_merge_rb_range(new_cs, RARRAY_AREF(ranges, i));
}
return new_cs;
}
|
.of(str) ⇒ Object
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 |
# File 'ext/character_set/character_set.c', line 1047
static VALUE
cs_class_method_of(VALUE self, VALUE str)
{
VALUE new_cs;
struct cs_data *new_data;
new_cs = cs_alloc(self, &new_data);
raise_arg_err_unless_string(str);
each_cp(str, add_str_cp_to_arr, 0, 0, new_data, 0);
return new_cs;
}
|
Instance Method Details
#&(other) ⇒ Object
330 331 332 333 334 |
# File 'ext/character_set/character_set.c', line 330
static VALUE
cs_method_intersection(VALUE self, VALUE other)
{
RETURN_COMBINED_CS(self, other, &&);
}
|
#+(other) ⇒ Object
342 343 344 345 346 |
# File 'ext/character_set/character_set.c', line 342
static VALUE
cs_method_union(VALUE self, VALUE other)
{
RETURN_COMBINED_CS(self, other, ||);
}
|
#-(other) ⇒ Object
348 349 350 351 352 |
# File 'ext/character_set/character_set.c', line 348
static VALUE
cs_method_difference(VALUE self, VALUE other)
{
RETURN_COMBINED_CS(self, other, >);
}
|
#<(other) ⇒ Object
653 654 655 656 657 658 659 |
# File 'ext/character_set/character_set.c', line 653
static VALUE
cs_method_proper_subset_p(VALUE self, VALUE other)
{
int is_subset, is_proper;
is_subset = cs_a_subset_of_b(self, other, &is_proper);
return (is_subset && is_proper) ? Qtrue : Qfalse;
}
|
#<<(cp_num) ⇒ Object
392 393 394 395 396 |
# File 'ext/character_set/character_set.c', line 392
static VALUE
cs_method_add(VALUE self, VALUE cp_num)
{
return cs_toggle_codepoint(self, cp_num, 1, 0);
}
|
#<=(other) ⇒ Object
647 648 649 650 651 |
# File 'ext/character_set/character_set.c', line 647
static VALUE
cs_method_subset_p(VALUE self, VALUE other)
{
return cs_a_subset_of_b(self, other, NULL) ? Qtrue : Qfalse;
}
|
#==(other) ⇒ Object
462 463 464 465 466 467 468 469 470 471 472 473 474 |
# File 'ext/character_set/character_set.c', line 462
static VALUE
cs_method_eql_p(VALUE self, VALUE other)
{
if (!cs_check_type(other))
{
return Qfalse;
}
if (self == other) // same object_id
{
return Qtrue;
}
return cs_cps_eql(self, other);
}
|
#===(num) ⇒ Object
354 355 356 357 358 359 360 361 |
# File 'ext/character_set/character_set.c', line 354
static VALUE
cs_method_include_p(VALUE self, VALUE num)
{
cs_ar *cps;
cs_cp len;
cps = cs_fetch_cps(self, &len);
return (tst_cp(cps, len, FIX2ULONG(num)) ? Qtrue : Qfalse);
}
|
#>(other) ⇒ Object
667 668 669 670 671 672 673 |
# File 'ext/character_set/character_set.c', line 667
static VALUE
cs_method_proper_superset_p(VALUE self, VALUE other)
{
int is_superset, is_proper;
is_superset = cs_a_subset_of_b(other, self, &is_proper);
return (is_superset && is_proper) ? Qtrue : Qfalse;
}
|
#>=(other) ⇒ Object
661 662 663 664 665 |
# File 'ext/character_set/character_set.c', line 661
static VALUE
cs_method_superset_p(VALUE self, VALUE other)
{
return cs_a_subset_of_b(other, self, NULL) ? Qtrue : Qfalse;
}
|
#^(other) ⇒ Object
336 337 338 339 340 |
# File 'ext/character_set/character_set.c', line 336
static VALUE
cs_method_exclusion(VALUE self, VALUE other)
{
RETURN_COMBINED_CS(self, other, ^);
}
|
#add(cp_num) ⇒ Object
392 393 394 395 396 |
# File 'ext/character_set/character_set.c', line 392
static VALUE
cs_method_add(VALUE self, VALUE cp_num)
{
return cs_toggle_codepoint(self, cp_num, 1, 0);
}
|
#add?(cp_num) ⇒ Boolean
398 399 400 401 402 |
# File 'ext/character_set/character_set.c', line 398
static VALUE
cs_method_add_p(VALUE self, VALUE cp_num)
{
return cs_toggle_codepoint(self, cp_num, 1, 1);
}
|
#allocated_length ⇒ Object
1276 1277 1278 1279 1280 |
# File 'ext/character_set/character_set.c', line 1276
static VALUE
cs_method_allocated_length(VALUE self)
{
return LONG2FIX(cs_fetch_data(self)->len);
}
|
#case_insensitive ⇒ Object
924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 |
# File 'ext/character_set/character_set.c', line 924
static VALUE
cs_method_case_insensitive(VALUE self)
{
cs_cp i, len;
cs_ar *cps;
VALUE new_cs;
struct cs_data *new_data;
cps = cs_fetch_cps(self, &len);
new_cs = cs_alloc(RBASIC(self)->klass, &new_data);
cs_merge_cs(new_cs, self);
for (i = 0; i < CASEFOLD_COUNT; i++)
{
casefold_mapping m = unicode_casefold_table[i];
if (tst_cp(cps, len, m.from))
{
set_cp(new_data, m.to);
}
else if (tst_cp(cps, len, m.to))
{
set_cp(new_data, m.from);
}
}
return new_cs;
// OnigCaseFoldType flags;
// rb_encoding *enc;
//
// enc = rb_utf8_encoding();
//
// ONIGENC_CASE_UPCASE | ONIGENC_CASE_DOWNCASE (not public on ruby < 2.4)
// flags = (1<<13) | (1<<14);
//
// // case_map args: flags, pp, end, to, to_end, enc
// enc->case_map(flags, (const OnigUChar**)&cp, ?, ?, ?, enc);
}
|
#clear ⇒ Object
266 267 268 269 270 271 272 273 274 |
# File 'ext/character_set/character_set.c', line 266
static VALUE
cs_method_clear(VALUE self)
{
struct cs_data *data;
rb_check_frozen(self);
data = cs_fetch_data(self);
memset(data->cps, 0, CS_MSIZE(data->len));
return self;
}
|
#count_in(str) ⇒ Object
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 |
# File 'ext/character_set/character_set.c', line 1068
static VALUE
cs_method_count_in(VALUE self, VALUE str)
{
VALUE count;
struct cs_data *data;
raise_arg_err_unless_string(str);
data = cs_fetch_data(self);
count = 0;
each_cp(str, count_str_cp, data->cps, data->len, data, &count);
return INT2NUM(count);
}
|
#cover?(str) ⇒ Boolean
1086 1087 1088 1089 1090 1091 1092 1093 |
# File 'ext/character_set/character_set.c', line 1086
static VALUE
cs_method_cover_p(VALUE self, VALUE str)
{
struct cs_data *data;
raise_arg_err_unless_string(str);
data = cs_fetch_data(self);
return each_cp(str, str_cp_in_arr, data->cps, data->len, data, 0);
}
|
#delete(cp_num) ⇒ Object
404 405 406 407 408 |
# File 'ext/character_set/character_set.c', line 404
static VALUE
cs_method_delete(VALUE self, VALUE cp_num)
{
return cs_toggle_codepoint(self, cp_num, 0, 0);
}
|
#delete?(cp_num) ⇒ Boolean
410 411 412 413 414 |
# File 'ext/character_set/character_set.c', line 410
static VALUE
cs_method_delete_p(VALUE self, VALUE cp_num)
{
return cs_toggle_codepoint(self, cp_num, 0, 1);
}
|
#delete_if ⇒ Object
252 253 254 255 256 257 |
# File 'ext/character_set/character_set.c', line 252
static VALUE
cs_method_delete_if(VALUE self)
{
RETURN_SIZED_ENUMERATOR(self, 0, 0, cs_enumerator_length);
return cs_delete_if_block_result(self, 1);
}
|
#delete_in(str) ⇒ Object
1252 1253 1254 1255 1256 |
# File 'ext/character_set/character_set.c', line 1252
static VALUE
cs_method_delete_in(VALUE self, VALUE str)
{
return cs_apply_to_str(self, str, 1, 0);
}
|
#delete_in!(str) ⇒ Object
1258 1259 1260 1261 1262 |
# File 'ext/character_set/character_set.c', line 1258
static VALUE
cs_method_delete_in_bang(VALUE self, VALUE str)
{
return cs_apply_to_str(self, str, 1, 1);
}
|
#difference(other) ⇒ Object
348 349 350 351 352 |
# File 'ext/character_set/character_set.c', line 348
static VALUE
cs_method_difference(VALUE self, VALUE other)
{
RETURN_COMBINED_CS(self, other, >);
}
|
#disjoint?(other) ⇒ Boolean
433 434 435 436 437 |
# File 'ext/character_set/character_set.c', line 433
static VALUE
cs_method_disjoint_p(VALUE self, VALUE other)
{
return cs_method_intersect_p(self, other) ? Qfalse : Qtrue;
}
|
#each ⇒ Object
Set compatibility methods
175 176 177 178 179 180 181 |
# File 'ext/character_set/character_set.c', line 175
static VALUE
cs_method_each(VALUE self)
{
RETURN_SIZED_ENUMERATOR(self, 0, 0, cs_enumerator_length);
FOR_EACH_ACTIVE_CODEPOINT(rb_yield(LONG2FIX(cp)));
return self;
}
|
#empty? ⇒ Boolean
206 207 208 209 210 211 |
# File 'ext/character_set/character_set.c', line 206
static VALUE
cs_method_empty_p(VALUE self)
{
FOR_EACH_ACTIVE_CODEPOINT(return Qfalse);
return Qtrue;
}
|
#eql?(other) ⇒ Boolean
462 463 464 465 466 467 468 469 470 471 472 473 474 |
# File 'ext/character_set/character_set.c', line 462
static VALUE
cs_method_eql_p(VALUE self, VALUE other)
{
if (!cs_check_type(other))
{
return Qfalse;
}
if (self == other) // same object_id
{
return Qtrue;
}
return cs_cps_eql(self, other);
}
|
#ext_count_in_section(from, upto) ⇒ Object
773 774 775 776 777 778 779 |
# File 'ext/character_set/character_set.c', line 773
static VALUE
cs_method_ext_count_in_section(VALUE self, VALUE from, VALUE upto)
{
cs_cp count;
count = cs_active_cp_count_in_section(self, FIX2ULONG(from), FIX2ULONG(upto));
return LONG2FIX(count);
}
|
#ext_inversion(*args) ⇒ Object
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 |
# File 'ext/character_set/character_set.c', line 888
static VALUE
cs_method_ext_inversion(int argc, VALUE *argv, VALUE self)
{
int inc_surr;
cs_cp upto, cp, len;
cs_ar *cps;
VALUE new_cs;
struct cs_data *new_data;
rb_check_arity(argc, 0, 2);
cps = cs_fetch_cps(self, &len);
inc_surr = argc && argv[0] == Qtrue;
new_cs = cs_alloc(RBASIC(self)->klass, &new_data);
upto = argc > 1 && FIXNUM_P(argv[1]) ? FIX2ULONG(argv[1]) : UNICODE_CP_COUNT;
for (cp = 0; cp < UNICODE_CP_COUNT; cp++)
{
if (cp <= upto && !tst_cp(cps, len, cp) && (inc_surr || NON_SURROGATE(cp)))
{
set_cp(new_data, cp);
}
}
return new_cs;
}
|
#ext_section(from, upto) ⇒ Object
751 752 753 754 755 |
# File 'ext/character_set/character_set.c', line 751
static VALUE
cs_method_ext_section(VALUE self, VALUE from, VALUE upto)
{
return cs_from_section(self, FIX2ULONG(from), FIX2ULONG(upto));
}
|
#ext_section?(from, upto) ⇒ Boolean
795 796 797 798 799 800 801 802 |
# File 'ext/character_set/character_set.c', line 795
static VALUE
cs_method_ext_section_p(VALUE self, VALUE from, VALUE upto)
{
cs_ar *cps;
cs_cp len;
cps = cs_fetch_cps(self, &len);
return cs_has_cp_in_section(cps, len, FIX2ULONG(from), FIX2ULONG(upto));
}
|
#ext_section_ratio(from, upto) ⇒ Object
813 814 815 816 817 |
# File 'ext/character_set/character_set.c', line 813
static VALUE
cs_method_ext_section_ratio(VALUE self, VALUE from, VALUE upto)
{
return cs_ratio_of_section(self, FIX2ULONG(from), FIX2ULONG(upto));
}
|
#hash ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'ext/character_set/character_set.c', line 213
static VALUE
cs_method_hash(VALUE self)
{
cs_cp cp, len, hash, four_byte_value;
cs_ar *cps;
cps = cs_fetch_cps(self, &len);
hash = 17;
for (cp = 0; cp < len; cp++)
{
if (cp % 32 == 0)
{
if (cp != 0)
{
hash = hash * 23 + four_byte_value;
}
four_byte_value = 0;
}
if (tst_cp(cps, len, cp))
{
four_byte_value++;
}
}
return LONG2FIX(hash);
}
|
#include?(num) ⇒ Boolean
354 355 356 357 358 359 360 361 |
# File 'ext/character_set/character_set.c', line 354
static VALUE
cs_method_include_p(VALUE self, VALUE num)
{
cs_ar *cps;
cs_cp len;
cps = cs_fetch_cps(self, &len);
return (tst_cp(cps, len, FIX2ULONG(num)) ? Qtrue : Qfalse);
}
|
#initialize_clone(orig) ⇒ Object
580 581 582 583 584 585 |
# File 'ext/character_set/character_set.c', line 580
static VALUE
cs_method_initialize_copy(VALUE self, VALUE orig)
{
cs_merge_cs(self, orig);
return self;
}
|
#initialize_dup(orig) ⇒ Object
580 581 582 583 584 585 |
# File 'ext/character_set/character_set.c', line 580
static VALUE
cs_method_initialize_copy(VALUE self, VALUE orig)
{
cs_merge_cs(self, orig);
return self;
}
|
#intersect?(other) ⇒ Boolean
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
# File 'ext/character_set/character_set.c', line 416
static VALUE
cs_method_intersect_p(VALUE self, VALUE other)
{
cs_cp cp, alen, blen;
cs_ar *acps, *bcps;
acps = cs_fetch_cps(self, &alen);
bcps = cs_fetch_cps(other, &blen);
for (cp = 0; cp < UNICODE_CP_COUNT; cp++)
{
if (tst_cp(acps, alen, cp) && tst_cp(bcps, blen, cp))
{
return Qtrue;
}
}
return Qfalse;
}
|
#intersection(other) ⇒ Object
330 331 332 333 334 |
# File 'ext/character_set/character_set.c', line 330
static VALUE
cs_method_intersection(VALUE self, VALUE other)
{
RETURN_COMBINED_CS(self, other, &&);
}
|
#keep_if ⇒ Object
259 260 261 262 263 264 |
# File 'ext/character_set/character_set.c', line 259
static VALUE
cs_method_keep_if(VALUE self)
{
RETURN_SIZED_ENUMERATOR(self, 0, 0, cs_enumerator_length);
return cs_delete_if_block_result(self, 0);
}
|
#keep_in(str) ⇒ Object
1264 1265 1266 1267 1268 |
# File 'ext/character_set/character_set.c', line 1264
static VALUE
cs_method_keep_in(VALUE self, VALUE str)
{
return cs_apply_to_str(self, str, 0, 0);
}
|
#keep_in!(str) ⇒ Object
1270 1271 1272 1273 1274 |
# File 'ext/character_set/character_set.c', line 1270
static VALUE
cs_method_keep_in_bang(VALUE self, VALUE str)
{
return cs_apply_to_str(self, str, 0, 1);
}
|
#length ⇒ Object
163 164 165 166 167 |
# File 'ext/character_set/character_set.c', line 163
static VALUE
cs_method_length(VALUE self)
{
return LONG2FIX(cs_active_cp_count(self));
}
|
#max ⇒ Object
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'ext/character_set/character_set.c', line 283
static VALUE
cs_method_max(VALUE self)
{
cs_cp len;
long reverse_idx;
cs_ar *cps;
cps = cs_fetch_cps(self, &len);
for (reverse_idx = len; reverse_idx >= 0; reverse_idx--)
{
if (tst_cp(cps, len, reverse_idx))
{
return LONG2FIX(reverse_idx);
}
}
return Qnil;
}
|
#member?(num) ⇒ Boolean
354 355 356 357 358 359 360 361 |
# File 'ext/character_set/character_set.c', line 354
static VALUE
cs_method_include_p(VALUE self, VALUE num)
{
cs_ar *cps;
cs_cp len;
cps = cs_fetch_cps(self, &len);
return (tst_cp(cps, len, FIX2ULONG(num)) ? Qtrue : Qfalse);
}
|
#member_in_plane?(plane_num) ⇒ Boolean
875 876 877 878 879 880 881 882 883 884 |
# File 'ext/character_set/character_set.c', line 875
static VALUE
cs_method_member_in_plane_p(VALUE self, VALUE plane_num)
{
cs_ar *cps;
cs_cp len;
unsigned int plane;
plane = cs_valid_plane_num(plane_num);
cps = cs_fetch_cps(self, &len);
return cs_has_cp_in_plane(cps, len, plane);
}
|
#merge(other) ⇒ Object
565 566 567 568 569 570 571 572 573 574 575 576 577 578 |
# File 'ext/character_set/character_set.c', line 565
static VALUE
cs_method_merge(VALUE self, VALUE other)
{
rb_check_frozen(self);
if (cs_check_type(other))
{
return cs_merge_cs(self, other);
}
else if (TYPE(other) == T_ARRAY)
{
return cs_merge_rb_array(self, other);
}
return cs_merge_rb_range(self, other);
}
|
#min ⇒ Object
276 277 278 279 280 281 |
# File 'ext/character_set/character_set.c', line 276
static VALUE
cs_method_min(VALUE self)
{
FOR_EACH_ACTIVE_CODEPOINT(return LONG2FIX(cp));
return Qnil;
}
|
#minmax ⇒ Object
300 301 302 303 304 305 306 307 308 |
# File 'ext/character_set/character_set.c', line 300
static VALUE
cs_method_minmax(VALUE self)
{
VALUE arr;
arr = rb_ary_new2(2);
rb_ary_push(arr, cs_method_min(self));
rb_ary_push(arr, cs_method_max(self));
return arr;
}
|
#plane(plane_num) ⇒ Object
865 866 867 868 869 870 871 872 873 |
# File 'ext/character_set/character_set.c', line 865
static VALUE
cs_method_plane(VALUE self, VALUE plane_num)
{
cs_cp plane, plane_beg, plane_end;
plane = cs_valid_plane_num(plane_num);
plane_beg = plane * UNICODE_PLANE_SIZE;
plane_end = (plane + 1) * MAX_BMP_CP;
return cs_from_section(self, plane_beg, plane_end);
}
|
#planes ⇒ Object
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 |
# File 'ext/character_set/character_set.c', line 833
static VALUE
cs_method_planes(VALUE self)
{
cs_ar *cps;
cs_cp len;
unsigned int i;
VALUE planes;
cps = cs_fetch_cps(self, &len);
planes = rb_ary_new();
for (i = 0; i < UNICODE_PLANE_COUNT; i++)
{
if (cs_has_cp_in_plane(cps, len, i))
{
rb_ary_push(planes, INT2FIX(i));
}
}
return planes;
}
|
#proper_subset?(other) ⇒ Boolean
653 654 655 656 657 658 659 |
# File 'ext/character_set/character_set.c', line 653
static VALUE
cs_method_proper_subset_p(VALUE self, VALUE other)
{
int is_subset, is_proper;
is_subset = cs_a_subset_of_b(self, other, &is_proper);
return (is_subset && is_proper) ? Qtrue : Qfalse;
}
|
#proper_superset?(other) ⇒ Boolean
667 668 669 670 671 672 673 |
# File 'ext/character_set/character_set.c', line 667
static VALUE
cs_method_proper_superset_p(VALUE self, VALUE other)
{
int is_superset, is_proper;
is_superset = cs_a_subset_of_b(other, self, &is_proper);
return (is_superset && is_proper) ? Qtrue : Qfalse;
}
|
#ranges ⇒ Object
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 |
# File 'ext/character_set/character_set.c', line 692
static VALUE
cs_method_ranges(VALUE self)
{
VALUE ranges, cp_num, previous_cp_num, current_start, current_end;
ranges = rb_ary_new();
previous_cp_num = 0;
current_start = 0;
current_end = 0;
FOR_EACH_ACTIVE_CODEPOINT(
cp_num = LONG2FIX(cp);
if (!previous_cp_num) {
current_start = cp_num;
} else if (previous_cp_num + 2 != cp_num) {
// gap found, finalize previous range
rb_ary_push(ranges, rb_range_new(current_start, current_end, 0));
current_start = cp_num;
} current_end = cp_num;
previous_cp_num = cp_num;);
// add final range
if (current_start)
{
rb_ary_push(ranges, rb_range_new(current_start, current_end, 0));
}
return ranges;
}
|
#sample(*args) ⇒ Object
723 724 725 726 727 728 729 730 |
# File 'ext/character_set/character_set.c', line 723
static VALUE
cs_method_sample(int argc, VALUE *argv, VALUE self)
{
VALUE array, to_a_args[1] = {Qtrue};
rb_check_arity(argc, 0, 1);
array = cs_method_to_a(1, to_a_args, self);
return rb_funcall(array, rb_intern("sample"), argc, argc ? argv[0] : 0);
}
|
#scan(str) ⇒ Object
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 |
# File 'ext/character_set/character_set.c', line 1105
static VALUE
cs_method_scan(VALUE self, VALUE str)
{
VALUE memo[2];
struct cs_data *data;
raise_arg_err_unless_string(str);
data = cs_fetch_data(self);
memo[0] = rb_ary_new();
memo[1] = (VALUE)rb_enc_get(str);
each_cp(str, add_str_cp_to_str_arr, data->cps, data->len, data, memo);
return memo[0];
}
|
#size ⇒ Object
163 164 165 166 167 |
# File 'ext/character_set/character_set.c', line 163
static VALUE
cs_method_length(VALUE self)
{
return LONG2FIX(cs_active_cp_count(self));
}
|
#subset?(other) ⇒ Boolean
647 648 649 650 651 |
# File 'ext/character_set/character_set.c', line 647
static VALUE
cs_method_subset_p(VALUE self, VALUE other)
{
return cs_a_subset_of_b(self, other, NULL) ? Qtrue : Qfalse;
}
|
#subtract(other) ⇒ Object
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 |
# File 'ext/character_set/character_set.c', line 587
static VALUE
cs_method_subtract(VALUE self, VALUE other)
{
cs_cp cp, len, other_len;
cs_ar *cps, *other_cps;
rb_check_frozen(self);
cps = cs_fetch_cps(self, &len);
other_cps = cs_fetch_cps(other, &other_len);
for (cp = 0; cp < UNICODE_CP_COUNT; cp++)
{
if (tst_cp(other_cps, other_len, cp))
{
clr_cp(cps, len, cp);
}
}
return self;
}
|
#superset?(other) ⇒ Boolean
661 662 663 664 665 |
# File 'ext/character_set/character_set.c', line 661
static VALUE
cs_method_superset_p(VALUE self, VALUE other)
{
return cs_a_subset_of_b(other, self, NULL) ? Qtrue : Qfalse;
}
|
#to_a(*args) ⇒ Object
returns an Array of Strings of length 1 if passed true.
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'ext/character_set/character_set.c', line 185
static VALUE
cs_method_to_a(int argc, VALUE *argv, VALUE self)
{
VALUE arr;
rb_encoding *enc;
rb_check_arity(argc, 0, 1);
arr = rb_ary_new();
if (!argc || NIL_P(argv[0]) || argv[0] == Qfalse)
{
FOR_EACH_ACTIVE_CODEPOINT(rb_ary_push(arr, LONG2FIX(cp)));
}
else
{
enc = rb_utf8_encoding();
FOR_EACH_ACTIVE_CODEPOINT(rb_ary_push(arr, rb_enc_uint_chr((int)cp, enc)));
}
return arr;
}
|
#union(other) ⇒ Object
342 343 344 345 346 |
# File 'ext/character_set/character_set.c', line 342
static VALUE
cs_method_union(VALUE self, VALUE other)
{
RETURN_COMBINED_CS(self, other, ||);
}
|
#used_by?(str) ⇒ Boolean
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 |
# File 'ext/character_set/character_set.c', line 1124
static VALUE
cs_method_used_by_p(VALUE self, VALUE str)
{
VALUE only_uses_other_cps;
struct cs_data *data;
raise_arg_err_unless_string(str);
data = cs_fetch_data(self);
only_uses_other_cps = each_cp(str, str_cp_not_in_arr, data->cps, data->len, data, 0);
return only_uses_other_cps == Qfalse ? Qtrue : Qfalse;
}
|
#|(other) ⇒ Object
342 343 344 345 346 |
# File 'ext/character_set/character_set.c', line 342
static VALUE
cs_method_union(VALUE self, VALUE other)
{
RETURN_COMBINED_CS(self, other, ||);
}
|