52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'ext/u/rb_u_string_squeeze.c', line 52
VALUE
rb_u_string_squeeze(int argc, VALUE *argv, VALUE self)
{
const struct rb_u_string *string = RVAL2USTRING(self);
if (USTRING_LENGTH(string) == 0)
return Qnil;
struct tr_table table;
if (argc > 0)
tr_table_initialize_from_strings(&table, argc, argv);
struct tr_table *table_pointer = (argc > 0) ? &table : NULL;
long count = rb_u_string_squeeze_loop(string, table_pointer, NULL);
if (count == 0)
return self;
char *remaining = ALLOC_N(char, count + 1);
rb_u_string_squeeze_loop(string, table_pointer, remaining);
remaining[count] = '\0';
return rb_u_string_new_c_own(self, remaining, count);
}
|