u 0.5.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/build/ext/u/data/attributes.rb +39 -0
- data/build/ext/u/data/bidi-mirroring.rb +27 -0
- data/build/ext/u/data/canonical-combining-class.rb +15 -0
- data/build/ext/u/data/case-folding.rb +39 -0
- data/build/ext/u/data/cased.rb +19 -0
- data/build/ext/u/data/compose.rb +304 -0
- data/build/ext/u/data/constants.rb +31 -0
- data/build/ext/u/data/decompose.rb +85 -0
- data/build/ext/u/data/general-category.rb +61 -0
- data/build/ext/u/data/grapheme-word-break.rb +15 -0
- data/build/ext/u/data/marshalled.rb +5 -0
- data/build/ext/u/data/script.rb +91 -0
- data/build/ext/u/data/soft-dotted.rb +17 -0
- data/build/ext/u/data/title-table.rb +30 -0
- data/build/ext/u/data/wide.rb +17 -0
- data/build/lib/u/build.rb +8 -0
- data/build/lib/u/build/data.rb +16 -0
- data/build/lib/u/build/data/bidimirroring.rb +26 -0
- data/build/lib/u/build/data/break.rb +14 -0
- data/build/lib/u/build/data/casefolding.rb +77 -0
- data/build/lib/u/build/data/compositionexclusions.rb +14 -0
- data/build/lib/u/build/data/derivedeastasianwidth.rb +15 -0
- data/build/lib/u/build/data/file.rb +88 -0
- data/build/lib/u/build/data/linebreak.rb +14 -0
- data/build/lib/u/build/data/proplist.rb +18 -0
- data/build/lib/u/build/data/scripts.rb +22 -0
- data/build/lib/u/build/data/specialcasing.rb +106 -0
- data/build/lib/u/build/data/unicode.rb +41 -0
- data/build/lib/u/build/data/unicode/entry.rb +27 -0
- data/build/lib/u/build/data/unicode/entry/decomposition.rb +29 -0
- data/build/lib/u/build/data/unicode/points.rb +32 -0
- data/build/lib/u/build/header.rb +11 -0
- data/build/lib/u/build/header/table.rb +19 -0
- data/build/lib/u/build/header/table/row.rb +64 -0
- data/build/lib/u/build/header/tables.rb +6 -0
- data/build/lib/u/build/header/tables/intervals.rb +50 -0
- data/build/lib/u/build/header/tables/split.rb +20 -0
- data/build/lib/u/build/header/tables/split/data.rb +29 -0
- data/build/lib/u/build/header/tables/split/part1.rb +28 -0
- data/build/lib/u/build/header/tables/split/part2.rb +13 -0
- data/build/lib/u/build/header/tables/split/row.rb +34 -0
- data/build/lib/u/build/header/tables/split/rows.rb +22 -0
- data/build/test/unit/break.rb +45 -0
- data/build/test/unit/case.rb +178 -0
- data/build/test/unit/foldcase.rb +44 -0
- data/build/test/unit/normalize.rb +81 -0
- data/ext/u/attributes.c +62 -0
- data/ext/u/attributes.h +5 -0
- data/ext/u/case.h +41 -0
- data/ext/u/data/attributes.h +3070 -0
- data/ext/u/data/bidi-mirroring.h +373 -0
- data/ext/u/data/canonical-combining-class.h +2157 -0
- data/ext/u/data/case-folding.h +171 -0
- data/ext/u/data/cased.h +42 -0
- data/ext/u/data/compose.h +1714 -0
- data/ext/u/data/constants.h +17 -0
- data/ext/u/data/decompose.h +9356 -0
- data/ext/u/data/general-category.h +28959 -0
- data/ext/u/data/grapheme-break.h +13201 -0
- data/ext/u/data/line-break.h +26501 -0
- data/ext/u/data/normalization-quick-check.h +3002 -0
- data/ext/u/data/script.h +2928 -0
- data/ext/u/data/soft-dotted.h +55 -0
- data/ext/u/data/title-table.h +41 -0
- data/ext/u/data/types.h +11117 -0
- data/ext/u/data/wide-cjk.h +197 -0
- data/ext/u/data/wide.h +59 -0
- data/ext/u/data/word-break.h +10001 -0
- data/ext/u/depend +281 -0
- data/ext/u/extconf.rb +158 -0
- data/ext/u/output.h +51 -0
- data/ext/{encoding/character/utf-8 → u}/private.c +11 -15
- data/ext/u/private.h +58 -0
- data/ext/u/rb_includes.h +10 -0
- data/ext/u/rb_private.c +98 -0
- data/ext/u/rb_private.h +67 -0
- data/ext/u/rb_u.c +251 -0
- data/ext/u/rb_u_buffer.c +443 -0
- data/ext/u/rb_u_buffer.h +24 -0
- data/ext/u/rb_u_re.c +43 -0
- data/ext/u/rb_u_re.h +15 -0
- data/ext/u/rb_u_string.c +478 -0
- data/ext/u/rb_u_string.h +173 -0
- data/ext/u/rb_u_string_alnum.c +10 -0
- data/ext/u/rb_u_string_alpha.c +10 -0
- data/ext/u/rb_u_string_aref.c +142 -0
- data/ext/u/rb_u_string_ascii_only.c +13 -0
- data/ext/u/rb_u_string_assigned.c +10 -0
- data/ext/u/rb_u_string_b.c +18 -0
- data/ext/u/rb_u_string_bytesize.c +10 -0
- data/ext/u/rb_u_string_byteslice.c +103 -0
- data/ext/u/rb_u_string_canonical_combining_class.c +33 -0
- data/ext/u/rb_u_string_case_ignorable.c +25 -0
- data/ext/u/rb_u_string_casecmp.c +61 -0
- data/ext/u/rb_u_string_cased.c +17 -0
- data/ext/u/rb_u_string_chomp.c +107 -0
- data/ext/u/rb_u_string_chop.c +33 -0
- data/ext/u/rb_u_string_chr.c +9 -0
- data/ext/u/rb_u_string_cntrl.c +10 -0
- data/ext/u/rb_u_string_collate.c +46 -0
- data/ext/u/rb_u_string_collation_key.c +18 -0
- data/ext/u/rb_u_string_count.c +38 -0
- data/ext/u/rb_u_string_defined.c +10 -0
- data/ext/u/rb_u_string_delete.c +62 -0
- data/ext/u/rb_u_string_digit.c +10 -0
- data/ext/u/rb_u_string_downcase.c +13 -0
- data/ext/u/rb_u_string_dump.c +153 -0
- data/ext/u/rb_u_string_each_byte.c +46 -0
- data/ext/u/rb_u_string_each_char.c +49 -0
- data/ext/u/rb_u_string_each_codepoint.c +45 -0
- data/ext/u/rb_u_string_each_grapheme_cluster.c +36 -0
- data/ext/u/rb_u_string_each_line.c +142 -0
- data/ext/u/rb_u_string_each_word.c +34 -0
- data/ext/u/rb_u_string_empty.c +11 -0
- data/ext/u/rb_u_string_end_with.c +31 -0
- data/ext/u/rb_u_string_eql.c +30 -0
- data/ext/u/rb_u_string_equal.c +33 -0
- data/ext/u/rb_u_string_foldcase.c +12 -0
- data/ext/u/rb_u_string_folded.c +13 -0
- data/ext/u/rb_u_string_format.c +1745 -0
- data/ext/u/rb_u_string_general_category.c +109 -0
- data/ext/u/rb_u_string_getbyte.c +21 -0
- data/ext/u/rb_u_string_graph.c +21 -0
- data/ext/u/rb_u_string_grapheme_break.c +61 -0
- data/ext/u/rb_u_string_gsub.c +164 -0
- data/ext/u/rb_u_string_hash.c +10 -0
- data/ext/u/rb_u_string_hex.c +9 -0
- data/ext/u/rb_u_string_include.c +10 -0
- data/ext/u/rb_u_string_index.c +110 -0
- data/ext/u/rb_u_string_inspect.c +189 -0
- data/ext/u/rb_u_string_internal_tr.c +148 -0
- data/ext/u/rb_u_string_internal_tr.h +29 -0
- data/ext/u/rb_u_string_justify.c +169 -0
- data/ext/u/rb_u_string_length.c +10 -0
- data/ext/u/rb_u_string_line_break.c +115 -0
- data/ext/u/rb_u_string_lower.c +13 -0
- data/ext/u/rb_u_string_lstrip.c +24 -0
- data/ext/u/rb_u_string_match.c +65 -0
- data/ext/u/rb_u_string_mirror.c +16 -0
- data/ext/u/rb_u_string_newline.c +21 -0
- data/ext/u/rb_u_string_normalize.c +70 -0
- data/ext/u/rb_u_string_normalized.c +28 -0
- data/ext/u/rb_u_string_oct.c +11 -0
- data/ext/u/rb_u_string_ord.c +14 -0
- data/ext/u/rb_u_string_partition.c +80 -0
- data/ext/u/rb_u_string_plus.c +33 -0
- data/ext/u/rb_u_string_print.c +10 -0
- data/ext/u/rb_u_string_punct.c +10 -0
- data/ext/u/rb_u_string_reverse.c +13 -0
- data/ext/u/rb_u_string_rindex.c +104 -0
- data/ext/u/rb_u_string_rpartition.c +81 -0
- data/ext/u/rb_u_string_rstrip.c +29 -0
- data/ext/u/rb_u_string_scan.c +109 -0
- data/ext/u/rb_u_string_script.c +253 -0
- data/ext/u/rb_u_string_soft_dotted.c +13 -0
- data/ext/u/rb_u_string_space.c +24 -0
- data/ext/u/rb_u_string_split.c +245 -0
- data/ext/u/rb_u_string_squeeze.c +75 -0
- data/ext/u/rb_u_string_start_with.c +31 -0
- data/ext/u/rb_u_string_strip.c +36 -0
- data/ext/u/rb_u_string_sub.c +147 -0
- data/ext/u/rb_u_string_times.c +35 -0
- data/ext/u/rb_u_string_title.c +10 -0
- data/ext/u/rb_u_string_titlecase.c +13 -0
- data/ext/u/rb_u_string_to_i.c +45 -0
- data/ext/u/rb_u_string_to_inum.c +364 -0
- data/ext/u/rb_u_string_to_inum.h +1 -0
- data/ext/u/rb_u_string_to_str.c +17 -0
- data/ext/u/rb_u_string_to_sym.c +12 -0
- data/ext/u/rb_u_string_tr.c +290 -0
- data/ext/u/rb_u_string_upcase.c +12 -0
- data/ext/u/rb_u_string_upper.c +13 -0
- data/ext/u/rb_u_string_valid.c +10 -0
- data/ext/u/rb_u_string_valid_encoding.c +12 -0
- data/ext/u/rb_u_string_wide.c +21 -0
- data/ext/u/rb_u_string_wide_cjk.c +21 -0
- data/ext/u/rb_u_string_width.c +19 -0
- data/ext/u/rb_u_string_word_break.c +63 -0
- data/ext/u/rb_u_string_xdigit.c +22 -0
- data/ext/u/rb_u_string_zero_width.c +16 -0
- data/ext/u/titled.c +55 -0
- data/ext/u/titled.h +1 -0
- data/ext/u/u.c +23 -0
- data/ext/u/u.h +458 -0
- data/ext/u/u_char_canonical_combining_class.c +31 -0
- data/ext/u/u_char_digit_value.c +21 -0
- data/ext/u/u_char_downcase.c +27 -0
- data/ext/u/u_char_general_category.c +31 -0
- data/ext/u/u_char_grapheme_break.c +28 -0
- data/ext/u/u_char_isalnum.c +24 -0
- data/ext/u/u_char_isalpha.c +21 -0
- data/ext/u/u_char_isassigned.c +16 -0
- data/ext/u/u_char_iscased.c +22 -0
- data/ext/u/u_char_iscaseignorable.c +29 -0
- data/ext/u/u_char_iscntrl.c +17 -0
- data/ext/u/u_char_isdefined.c +15 -0
- data/ext/u/u_char_isdigit.c +16 -0
- data/ext/u/u_char_isgraph.c +22 -0
- data/ext/u/u_char_islower.c +16 -0
- data/ext/u/u_char_isnewline.c +24 -0
- data/ext/u/u_char_isprint.c +21 -0
- data/ext/u/u_char_ispunct.c +27 -0
- data/ext/u/u_char_issoftdotted.c +18 -0
- data/ext/u/u_char_isspace.c +28 -0
- data/ext/u/u_char_isupper.c +16 -0
- data/ext/u/u_char_isvalid.c +18 -0
- data/ext/u/u_char_iswide.c +18 -0
- data/ext/u/u_char_iswide_cjk.c +22 -0
- data/ext/u/u_char_isxdigit.c +27 -0
- data/ext/u/u_char_iszerowidth.c +29 -0
- data/ext/u/u_char_line_break.c +29 -0
- data/ext/u/u_char_mirror.c +16 -0
- data/ext/u/u_char_normalized.c +23 -0
- data/ext/u/u_char_script.c +41 -0
- data/ext/u/u_char_to_u.c +48 -0
- data/ext/u/u_char_upcase.c +24 -0
- data/ext/u/u_char_width.c +12 -0
- data/ext/u/u_char_word_break.c +28 -0
- data/ext/u/u_char_xdigit_value.c +31 -0
- data/ext/u/u_collate.c +83 -0
- data/ext/u/u_collation_key.c +132 -0
- data/ext/u/u_decode.c +156 -0
- data/ext/u/u_downcase.c +201 -0
- data/ext/u/u_foldcase.c +68 -0
- data/ext/u/u_grapheme_clusters.c +57 -0
- data/ext/u/u_has_prefix.c +27 -0
- data/ext/u/u_index.c +93 -0
- data/ext/u/u_is_ascii_only.c +33 -0
- data/ext/u/u_locale.c +40 -0
- data/ext/u/u_locale.h +14 -0
- data/ext/u/u_mirror.c +20 -0
- data/ext/u/u_n_bytes.c +16 -0
- data/ext/u/u_n_chars.c +43 -0
- data/ext/u/u_normalize.c +232 -0
- data/ext/u/u_normalized.c +28 -0
- data/ext/u/u_offset_to_pointer.c +62 -0
- data/ext/u/u_pointer_to_offset.c +23 -0
- data/ext/u/u_recode.c +73 -0
- data/ext/u/u_reverse.c +21 -0
- data/ext/u/u_rindex.c +132 -0
- data/ext/u/u_titlecase.c +68 -0
- data/ext/u/u_upcase.c +89 -0
- data/ext/u/u_width.c +35 -0
- data/ext/u/u_words.c +82 -0
- data/ext/u/yield.h +27 -0
- data/lib/u-1.0.rb +20 -0
- data/lib/u-1.0/buffer.rb +10 -0
- data/lib/u-1.0/string.rb +9 -0
- data/lib/u-1.0/version.rb +287 -0
- data/test/unit/case.rb +2080 -0
- data/test/unit/foldcase.rb +1136 -0
- data/test/unit/graphemebreak.rb +407 -0
- data/test/unit/normalize.rb +367545 -0
- data/test/unit/u-1.0.rb +10 -0
- data/test/unit/u-1.0/buffer.rb +52 -0
- data/test/unit/u-1.0/string.rb +1439 -0
- data/test/unit/{u.rb → u-1.0/version.rb} +0 -1
- data/test/unit/wordbreak.rb +1083 -0
- metadata +603 -148
- data/README +0 -38
- data/Rakefile +0 -64
- data/ext/encoding/character/utf-8/break.c +0 -25
- data/ext/encoding/character/utf-8/data/break.h +0 -22931
- data/ext/encoding/character/utf-8/data/character-tables.h +0 -14358
- data/ext/encoding/character/utf-8/data/compose.h +0 -1607
- data/ext/encoding/character/utf-8/data/decompose.h +0 -10926
- data/ext/encoding/character/utf-8/data/generate-unicode-data.rb +0 -1070
- data/ext/encoding/character/utf-8/decompose.c +0 -444
- data/ext/encoding/character/utf-8/depend +0 -65
- data/ext/encoding/character/utf-8/extconf.rb +0 -67
- data/ext/encoding/character/utf-8/private.h +0 -51
- data/ext/encoding/character/utf-8/properties.c +0 -1056
- data/ext/encoding/character/utf-8/rb_includes.h +0 -19
- data/ext/encoding/character/utf-8/rb_methods.h +0 -49
- data/ext/encoding/character/utf-8/rb_private.h +0 -52
- data/ext/encoding/character/utf-8/rb_utf_aref.c +0 -111
- data/ext/encoding/character/utf-8/rb_utf_aset.c +0 -105
- data/ext/encoding/character/utf-8/rb_utf_casecmp.c +0 -24
- data/ext/encoding/character/utf-8/rb_utf_chomp.c +0 -114
- data/ext/encoding/character/utf-8/rb_utf_chop.c +0 -44
- data/ext/encoding/character/utf-8/rb_utf_collate.c +0 -13
- data/ext/encoding/character/utf-8/rb_utf_count.c +0 -30
- data/ext/encoding/character/utf-8/rb_utf_delete.c +0 -60
- data/ext/encoding/character/utf-8/rb_utf_downcase.c +0 -13
- data/ext/encoding/character/utf-8/rb_utf_each_char.c +0 -27
- data/ext/encoding/character/utf-8/rb_utf_foldcase.c +0 -13
- data/ext/encoding/character/utf-8/rb_utf_hex.c +0 -14
- data/ext/encoding/character/utf-8/rb_utf_index.c +0 -50
- data/ext/encoding/character/utf-8/rb_utf_insert.c +0 -48
- data/ext/encoding/character/utf-8/rb_utf_internal_bignum.c +0 -332
- data/ext/encoding/character/utf-8/rb_utf_internal_bignum.h +0 -12
- data/ext/encoding/character/utf-8/rb_utf_internal_tr.c +0 -142
- data/ext/encoding/character/utf-8/rb_utf_internal_tr.h +0 -41
- data/ext/encoding/character/utf-8/rb_utf_justify.c +0 -96
- data/ext/encoding/character/utf-8/rb_utf_length.c +0 -14
- data/ext/encoding/character/utf-8/rb_utf_lstrip.c +0 -41
- data/ext/encoding/character/utf-8/rb_utf_normalize.c +0 -51
- data/ext/encoding/character/utf-8/rb_utf_oct.c +0 -14
- data/ext/encoding/character/utf-8/rb_utf_reverse.c +0 -13
- data/ext/encoding/character/utf-8/rb_utf_rindex.c +0 -88
- data/ext/encoding/character/utf-8/rb_utf_rstrip.c +0 -51
- data/ext/encoding/character/utf-8/rb_utf_squeeze.c +0 -70
- data/ext/encoding/character/utf-8/rb_utf_strip.c +0 -27
- data/ext/encoding/character/utf-8/rb_utf_to_i.c +0 -25
- data/ext/encoding/character/utf-8/rb_utf_tr.c +0 -250
- data/ext/encoding/character/utf-8/rb_utf_upcase.c +0 -13
- data/ext/encoding/character/utf-8/tables.h +0 -38
- data/ext/encoding/character/utf-8/unicode.c +0 -319
- data/ext/encoding/character/utf-8/unicode.h +0 -216
- data/ext/encoding/character/utf-8/utf.c +0 -1334
- data/lib/encoding/character/utf-8.rb +0 -201
- data/lib/u.rb +0 -16
- data/lib/u/string.rb +0 -185
- data/lib/u/version.rb +0 -5
- data/test/unit/u/string.rb +0 -91
@@ -1,51 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* contents: UTF8.rstrip module function.
|
3
|
-
*
|
4
|
-
* Copyright © 2006 Nikolai Weibull <now@bitwi.se>
|
5
|
-
*/
|
6
|
-
|
7
|
-
#include "rb_includes.h"
|
8
|
-
|
9
|
-
VALUE
|
10
|
-
rb_utf_rstrip_bang(UNUSED(VALUE self), VALUE str)
|
11
|
-
{
|
12
|
-
StringValue(str);
|
13
|
-
const char *begin = RSTRING(str)->ptr;
|
14
|
-
if (begin == NULL || RSTRING(str)->len == 0)
|
15
|
-
return Qnil;
|
16
|
-
|
17
|
-
const char *end = begin + RSTRING(str)->len;
|
18
|
-
const char *t = end;
|
19
|
-
|
20
|
-
/* Remove trailing '\0'’s. */
|
21
|
-
while (t > begin && t[-1] == '\0')
|
22
|
-
t--;
|
23
|
-
|
24
|
-
/* Remove trailing spaces. */
|
25
|
-
while (t > begin) {
|
26
|
-
/* FIXME: Should we be validating here? */
|
27
|
-
const char *prev = rb_utf_prev_validated(begin, t);
|
28
|
-
|
29
|
-
if (!unichar_isspace(utf_char(prev)))
|
30
|
-
break;
|
31
|
-
|
32
|
-
t = prev;
|
33
|
-
}
|
34
|
-
|
35
|
-
if (t == end)
|
36
|
-
return Qnil;
|
37
|
-
|
38
|
-
rb_str_modify(str);
|
39
|
-
RSTRING(str)->len = t - begin;
|
40
|
-
RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
|
41
|
-
|
42
|
-
return str;
|
43
|
-
}
|
44
|
-
|
45
|
-
VALUE
|
46
|
-
rb_utf_rstrip(VALUE self, VALUE str)
|
47
|
-
{
|
48
|
-
str = rb_utf_dup(str);
|
49
|
-
rb_utf_rstrip_bang(self, str);
|
50
|
-
return str;
|
51
|
-
}
|
@@ -1,70 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* contents: UTF8.squeeze module function.
|
3
|
-
*
|
4
|
-
* Copyright © 2006 Nikolai Weibull <now@bitwi.se>
|
5
|
-
*/
|
6
|
-
|
7
|
-
#include "rb_includes.h"
|
8
|
-
#include "rb_utf_internal_tr.h"
|
9
|
-
|
10
|
-
VALUE
|
11
|
-
rb_utf_squeeze_bang(int argc, VALUE *argv, UNUSED(VALUE self))
|
12
|
-
{
|
13
|
-
need_at_least_n_arguments(argc, 1);
|
14
|
-
|
15
|
-
VALUE str = argv[0];
|
16
|
-
StringValue(str);
|
17
|
-
if (RSTRING(str)->len == 0)
|
18
|
-
return Qnil;
|
19
|
-
|
20
|
-
unsigned int table[TR_TABLE_SIZE];
|
21
|
-
if (argc == 1)
|
22
|
-
for (int i = 0; i < TR_TABLE_SIZE; i++)
|
23
|
-
table[i] = ~0U;
|
24
|
-
else
|
25
|
-
tr_setup_table_from_strings(table, argc - 1, &argv[1]);
|
26
|
-
|
27
|
-
rb_str_modify(str);
|
28
|
-
|
29
|
-
char *begin = RSTRING(str)->ptr;
|
30
|
-
char const *end = begin + RSTRING(str)->len;
|
31
|
-
|
32
|
-
/* We know that there is a character to eat (if the input isn’t
|
33
|
-
* invalid), as we’ve already verified that RSTRING(str)->len > 0, so
|
34
|
-
* ‘s_end’ must lay beyond ‘s’. Also, as we validate when we fetch the
|
35
|
-
* character, there’s no need to validate the call to utf_next(). */
|
36
|
-
unichar previous = _utf_char_validated(begin, end);
|
37
|
-
char *s = utf_next(begin);
|
38
|
-
char *t = s;
|
39
|
-
while (s < end) {
|
40
|
-
unichar c = _utf_char_validated(s, end);
|
41
|
-
char *next = utf_next(s);
|
42
|
-
|
43
|
-
if (c != previous || !tr_table_lookup(table, c)) {
|
44
|
-
memmove(t, s, next - s);
|
45
|
-
t += next - s;
|
46
|
-
previous = c;
|
47
|
-
}
|
48
|
-
|
49
|
-
s = next;
|
50
|
-
}
|
51
|
-
*t = '\0';
|
52
|
-
|
53
|
-
if (t - begin != RSTRING(str)->len) {
|
54
|
-
RSTRING(str)->len = t - begin;
|
55
|
-
return str;
|
56
|
-
}
|
57
|
-
|
58
|
-
return Qnil;
|
59
|
-
}
|
60
|
-
|
61
|
-
VALUE
|
62
|
-
rb_utf_squeeze(int argc, VALUE *argv, VALUE self)
|
63
|
-
{
|
64
|
-
need_at_least_n_arguments(argc, 1);
|
65
|
-
|
66
|
-
StringValue(argv[0]);
|
67
|
-
argv[0] = rb_utf_dup(argv[0]);
|
68
|
-
rb_utf_squeeze_bang(argc, argv, self);
|
69
|
-
return argv[0];
|
70
|
-
}
|
@@ -1,27 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* contents: UTF8.strip module function.
|
3
|
-
*
|
4
|
-
* Copyright © 2006 Nikolai Weibull <now@bitwi.se>
|
5
|
-
*/
|
6
|
-
|
7
|
-
#include "rb_includes.h"
|
8
|
-
|
9
|
-
VALUE
|
10
|
-
rb_utf_strip_bang(VALUE self, VALUE str)
|
11
|
-
{
|
12
|
-
VALUE left = rb_utf_lstrip_bang(self, str);
|
13
|
-
VALUE right = rb_utf_rstrip_bang(self, str);
|
14
|
-
|
15
|
-
if (NIL_P(left) && NIL_P(right))
|
16
|
-
return Qnil;
|
17
|
-
|
18
|
-
return str;
|
19
|
-
}
|
20
|
-
|
21
|
-
VALUE
|
22
|
-
rb_utf_strip(VALUE self, VALUE str)
|
23
|
-
{
|
24
|
-
str = rb_utf_dup(str);
|
25
|
-
rb_utf_strip_bang(self, str);
|
26
|
-
return str;
|
27
|
-
}
|
@@ -1,25 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* contents: UTF8.to_i module function.
|
3
|
-
*
|
4
|
-
* Copyright © 2006 Nikolai Weibull <now@bitwi.se>
|
5
|
-
*/
|
6
|
-
|
7
|
-
#include "rb_includes.h"
|
8
|
-
#include "rb_utf_internal_bignum.h"
|
9
|
-
|
10
|
-
VALUE
|
11
|
-
rb_utf_to_i(int argc, VALUE *argv, UNUSED(VALUE self))
|
12
|
-
{
|
13
|
-
VALUE str, rbbase;
|
14
|
-
|
15
|
-
int base = 10;
|
16
|
-
if (rb_scan_args(argc, argv, "11", &str, &rbbase) == 2)
|
17
|
-
base = NUM2INT(rbbase);
|
18
|
-
|
19
|
-
/* XXX: this test is actually unnecessary, as this will be checked in
|
20
|
-
* rb_utf_to_inum() as well. */
|
21
|
-
if (base < 0)
|
22
|
-
rb_raise(rb_eArgError, "illegal radix %d", base);
|
23
|
-
|
24
|
-
return rb_utf_to_inum(str, base, false);
|
25
|
-
}
|
@@ -1,250 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* contents: UTF8.tr module function.
|
3
|
-
*
|
4
|
-
* Copyright © 2006 Nikolai Weibull <now@bitwi.se>
|
5
|
-
*/
|
6
|
-
|
7
|
-
#include "rb_includes.h"
|
8
|
-
#include "rb_utf_internal_tr.h"
|
9
|
-
|
10
|
-
struct tr_range
|
11
|
-
{
|
12
|
-
unichar begin;
|
13
|
-
unichar end;
|
14
|
-
};
|
15
|
-
|
16
|
-
static int
|
17
|
-
tr_ranges_setup(struct tr *tr, struct tr_range *ranges)
|
18
|
-
{
|
19
|
-
int n = 0;
|
20
|
-
bool was_inside_range = false;
|
21
|
-
while (tr_next(tr) != TR_FINISHED) {
|
22
|
-
if (tr->inside_range) {
|
23
|
-
if (!was_inside_range) {
|
24
|
-
ranges[n].begin = tr->now;
|
25
|
-
was_inside_range = true;
|
26
|
-
}
|
27
|
-
} else {
|
28
|
-
if (was_inside_range)
|
29
|
-
ranges[n].end = tr->now;
|
30
|
-
else
|
31
|
-
ranges[n].begin = ranges[n].end = tr->now;
|
32
|
-
n++;
|
33
|
-
was_inside_range = false;
|
34
|
-
}
|
35
|
-
}
|
36
|
-
|
37
|
-
return n;
|
38
|
-
}
|
39
|
-
|
40
|
-
|
41
|
-
struct tr_trans_closure
|
42
|
-
{
|
43
|
-
struct tr_range *from;
|
44
|
-
int n_from;
|
45
|
-
struct tr_range *to;
|
46
|
-
int n_to;
|
47
|
-
};
|
48
|
-
|
49
|
-
static unichar
|
50
|
-
tr_trans_replace_exclude(UNUSED(unichar c), void *closure)
|
51
|
-
{
|
52
|
-
return *((unichar *)closure);
|
53
|
-
}
|
54
|
-
|
55
|
-
static int
|
56
|
-
tr_trans_replace_include_offset_of(struct tr_range *ranges, int range)
|
57
|
-
{
|
58
|
-
int offset = 0;
|
59
|
-
|
60
|
-
for (int i = 0; i < range; i++)
|
61
|
-
offset += ranges[i].end - ranges[i].begin + 1;
|
62
|
-
|
63
|
-
return offset;
|
64
|
-
}
|
65
|
-
|
66
|
-
static unichar
|
67
|
-
tr_trans_replace_include(unichar c, void *v_closure)
|
68
|
-
{
|
69
|
-
struct tr_trans_closure *closure = (struct tr_trans_closure *)v_closure;
|
70
|
-
|
71
|
-
for (int i = closure->n_from - 1; i >= 0; i--) {
|
72
|
-
if (closure->from[i].begin >= c && closure->from[i].end <= c) {
|
73
|
-
int offset = tr_trans_replace_include_offset_of(closure->from, i);
|
74
|
-
int j;
|
75
|
-
for (j = 0; j < closure->n_to && offset > 0; j++)
|
76
|
-
offset -= closure->to[j].end - closure->to[j].begin + 1;
|
77
|
-
|
78
|
-
if (offset > 0)
|
79
|
-
return closure->to[closure->n_to - 1].end;
|
80
|
-
|
81
|
-
return closure->to[j].end - offset;
|
82
|
-
}
|
83
|
-
}
|
84
|
-
|
85
|
-
return closure->to[closure->n_to - 1].end;
|
86
|
-
}
|
87
|
-
|
88
|
-
static VALUE
|
89
|
-
tr_trans_do(VALUE src, unsigned int *translation,
|
90
|
-
unichar (*replace)(unichar, void *), void *closure, bool squeeze,
|
91
|
-
UNUSED(bool replace_content))
|
92
|
-
{
|
93
|
-
VALUE dst = Qnil;
|
94
|
-
long len;
|
95
|
-
|
96
|
-
again:
|
97
|
-
len = 0;
|
98
|
-
|
99
|
-
const char *s = RSTRING(src)->ptr;
|
100
|
-
const char *s_end = s + RSTRING(src)->len;
|
101
|
-
|
102
|
-
char *t = NULL;
|
103
|
-
|
104
|
-
if (dst != Qnil)
|
105
|
-
t = RSTRING(dst)->ptr;
|
106
|
-
|
107
|
-
bool modified = false;
|
108
|
-
|
109
|
-
/* TODO: this should really be refactored… */
|
110
|
-
if (squeeze) {
|
111
|
-
unichar prev_c = -1;
|
112
|
-
|
113
|
-
while (s < s_end) {
|
114
|
-
unichar c0 = utf_char(s);
|
115
|
-
|
116
|
-
const char *prev = s;
|
117
|
-
s = utf_next(s);
|
118
|
-
|
119
|
-
if (tr_table_lookup(translation, c0)) {
|
120
|
-
unichar c = replace(c0, closure);
|
121
|
-
if (prev_c == c)
|
122
|
-
continue;
|
123
|
-
prev_c = c;
|
124
|
-
len += unichar_to_utf(c, (t != NULL) ? t + len : NULL);
|
125
|
-
modified = true;
|
126
|
-
} else {
|
127
|
-
prev_c = -1;
|
128
|
-
if (t != NULL)
|
129
|
-
memcpy(t + len, prev, s - prev);
|
130
|
-
len += s - prev;
|
131
|
-
}
|
132
|
-
|
133
|
-
}
|
134
|
-
|
135
|
-
if (RSTRING(src)->len > (t + len - RSTRING(src)->ptr))
|
136
|
-
modified = true;
|
137
|
-
} else {
|
138
|
-
while (s < s_end) {
|
139
|
-
unichar c = utf_char(s);
|
140
|
-
|
141
|
-
const char *prev = s;
|
142
|
-
s = utf_next(s);
|
143
|
-
|
144
|
-
if (tr_table_lookup(translation, c)) {
|
145
|
-
len += unichar_to_utf(replace(c, closure),
|
146
|
-
(t != NULL) ? t + len : NULL);
|
147
|
-
modified = true;
|
148
|
-
} else {
|
149
|
-
if (t != NULL)
|
150
|
-
memcpy(t + len, prev, s - prev);
|
151
|
-
len += s - prev;
|
152
|
-
}
|
153
|
-
}
|
154
|
-
}
|
155
|
-
|
156
|
-
#ifdef RB_STR_REPLACE_IS_EXTERN
|
157
|
-
if (replace_content && !modified)
|
158
|
-
return Qnil;
|
159
|
-
#endif
|
160
|
-
|
161
|
-
if (dst == Qnil) {
|
162
|
-
#ifdef RB_STR_REPLACE_IS_EXTERN
|
163
|
-
if (replace_content && len <= RSTRING(src)->len)
|
164
|
-
dst = src;
|
165
|
-
else
|
166
|
-
#endif
|
167
|
-
dst = rb_str_buf_new(len);
|
168
|
-
goto again;
|
169
|
-
}
|
170
|
-
|
171
|
-
t[len] = '\0';
|
172
|
-
RSTRING(dst)->len = len;
|
173
|
-
|
174
|
-
#ifdef RB_STR_REPLACE_IS_EXTERN
|
175
|
-
if (dst != src && replace_content) {
|
176
|
-
rb_str_replace(src, dst);
|
177
|
-
return src;
|
178
|
-
}
|
179
|
-
#endif
|
180
|
-
|
181
|
-
return dst;
|
182
|
-
}
|
183
|
-
|
184
|
-
static VALUE
|
185
|
-
tr_trans(VALUE str, VALUE from, VALUE to, bool squeeze, bool replace_content)
|
186
|
-
{
|
187
|
-
StringValue(str);
|
188
|
-
StringValue(from);
|
189
|
-
StringValue(to);
|
190
|
-
|
191
|
-
if (RSTRING(str)->ptr == NULL || RSTRING(str)->len == 0)
|
192
|
-
return replace_content ? Qnil : str;
|
193
|
-
|
194
|
-
if (RSTRING(to)->len == 0)
|
195
|
-
return rb_utf_delete_bang(1, &from, str);
|
196
|
-
|
197
|
-
struct tr tr_from;
|
198
|
-
tr_init(&tr_from,
|
199
|
-
RSTRING(from)->ptr,
|
200
|
-
RSTRING(from)->ptr + RSTRING(from)->len);
|
201
|
-
|
202
|
-
struct tr tr_to;
|
203
|
-
tr_init(&tr_to,
|
204
|
-
RSTRING(to)->ptr,
|
205
|
-
RSTRING(to)->ptr + RSTRING(to)->len);
|
206
|
-
|
207
|
-
unsigned int translation[TR_TABLE_SIZE];
|
208
|
-
tr_setup_table(from, translation, true);
|
209
|
-
|
210
|
-
tr_init(&tr_from,
|
211
|
-
RSTRING(from)->ptr,
|
212
|
-
RSTRING(from)->ptr + RSTRING(from)->len);
|
213
|
-
if (tr_should_exclude(&tr_from)) {
|
214
|
-
/* This case is easy. Just include everything by default and
|
215
|
-
* exclude the rest as always. Replace characters found by the
|
216
|
-
* last character found in tr_to. */
|
217
|
-
while (tr_next(&tr_to) != TR_FINISHED)
|
218
|
-
; /* We just need the last replacement character. */
|
219
|
-
return tr_trans_do(str, translation, tr_trans_replace_exclude,
|
220
|
-
&tr_to.now, squeeze, replace_content);
|
221
|
-
} else {
|
222
|
-
/* This case is hard. We need a full-fledged lookup of what
|
223
|
-
* character to translate to, not simply a check whether to
|
224
|
-
* include it or not. */
|
225
|
-
struct tr_trans_closure trans_closure;
|
226
|
-
|
227
|
-
struct tr_range from_ranges[utf_length_n(RSTRING(from)->ptr, RSTRING(from)->len)];
|
228
|
-
trans_closure.from = from_ranges;
|
229
|
-
trans_closure.n_from = tr_ranges_setup(&tr_from, from_ranges);
|
230
|
-
|
231
|
-
struct tr_range to_ranges[utf_length_n(RSTRING(to)->ptr, RSTRING(to)->len)];
|
232
|
-
trans_closure.to = to_ranges;
|
233
|
-
trans_closure.n_to = tr_ranges_setup(&tr_to, to_ranges);
|
234
|
-
|
235
|
-
return tr_trans_do(str, translation, tr_trans_replace_include,
|
236
|
-
&trans_closure, squeeze, replace_content);
|
237
|
-
}
|
238
|
-
}
|
239
|
-
|
240
|
-
VALUE
|
241
|
-
rb_utf_tr(UNUSED(VALUE self), VALUE str, VALUE from, VALUE to)
|
242
|
-
{
|
243
|
-
return tr_trans(str, from, to, false, false);
|
244
|
-
}
|
245
|
-
|
246
|
-
VALUE
|
247
|
-
rb_utf_tr_s(UNUSED(VALUE self), VALUE str, VALUE from, VALUE to)
|
248
|
-
{
|
249
|
-
return tr_trans(str, from, to, true, false);
|
250
|
-
}
|
@@ -1,13 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* contents: UTF8.upcase module function.
|
3
|
-
*
|
4
|
-
* Copyright © 2006 Nikolai Weibull <now@bitwi.se>
|
5
|
-
*/
|
6
|
-
|
7
|
-
#include "rb_includes.h"
|
8
|
-
|
9
|
-
VALUE
|
10
|
-
rb_utf_upcase(UNUSED(VALUE self), VALUE str)
|
11
|
-
{
|
12
|
-
return rb_utf_alloc_using(utf_upcase(StringValuePtr(str)));
|
13
|
-
}
|
@@ -1,38 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* contents: Functions for dealing with Unicode tables.
|
3
|
-
*
|
4
|
-
* Copyright © 2007 Nikolai Weibull <now@bitwi.se>
|
5
|
-
*/
|
6
|
-
|
7
|
-
#ifndef TABLES_H
|
8
|
-
#define TABLES_H
|
9
|
-
|
10
|
-
|
11
|
-
/*
|
12
|
-
static inline int
|
13
|
-
split_unicode_table_lookup_page(const uint8_t data[][256], int16_t page, unichar c)
|
14
|
-
{
|
15
|
-
return (page >= UNICODE_MAX_TABLE_INDEX) ?
|
16
|
-
page - UNICODE_MAX_TABLE_INDEX :
|
17
|
-
data[page][c & 0xff];
|
18
|
-
}
|
19
|
-
|
20
|
-
static inline int
|
21
|
-
split_unicode_table_lookup(const uint8_t data[][256], const int16_t part1[], const int16_t part2[], unichar c, int fallback)
|
22
|
-
{
|
23
|
-
if (c <= UNICODE_LAST_CHAR_PART1)
|
24
|
-
return split_unicode_table_lookup_page(data,
|
25
|
-
part1[c >> 8],
|
26
|
-
c);
|
27
|
-
|
28
|
-
if (c >= UNICODE_FIRST_CHAR_PART2 && c <= UNICODE_LAST_CHAR)
|
29
|
-
return split_unicode_table_lookup_page(data,
|
30
|
-
part2[(c - UNICODE_FIRST_CHAR_PART2) >> 8],
|
31
|
-
c);
|
32
|
-
|
33
|
-
return fallback;
|
34
|
-
}
|
35
|
-
*/
|
36
|
-
|
37
|
-
|
38
|
-
#endif /* TABLES_H */
|