-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrb_u_string_each_char.c
More file actions
49 lines (45 loc) · 1.28 KB
/
rb_u_string_each_char.c
File metadata and controls
49 lines (45 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "rb_includes.h"
#include "yield.h"
static void
each(VALUE self, struct yield *yield)
{
const struct rb_u_string *s = RVAL2USTRING(self);
for (const char *p = USTRING_STR(s), *q, *end = USTRING_END(s); p < end; p = q) {
u_decode(&q, p, end);
yield_call(yield, rb_u_string_new_c(self, p, q - p));
}
}
UNUSED(static VALUE
size(VALUE self, UNUSED(VALUE args)))
{
const struct rb_u_string *string = RVAL2USTRING(self);
return UINT2NUM(u_n_chars_n(USTRING_STR(string), USTRING_LENGTH(string)));
}
/* @overload each_char{ |char| … }
*
* Enumerates the characters in the receiver, each inheriting any taint and
* untrust.
*
* @yieldparam [U::String] char
* @return [self]
*
* @overload each_char
*
* @return [Enumerator] An Enumerator over the characters in the receiver */
VALUE
rb_u_string_each_char(VALUE self)
{
RETURN_SIZED_ENUMERATOR(self, 0, NULL, size);
struct yield y = YIELD_INIT;
each(self, &y);
return self;
}
/* @return [Array<U::String>] The characters of the receiver, each inheriting
* any taint and untrust. */
VALUE
rb_u_string_chars(VALUE self)
{
struct yield_array y = YIELD_ARRAY_INIT;
each(self, &y.yield);
return y.array;
}