Method: StringIO#each_codepoint

Defined in:
ext/stringio/stringio.c

#each_codepoint {|c| ... } ⇒ Object #each_codepointEnumerator

See IO#each_codepoint.

Overloads:

  • #each_codepoint {|c| ... } ⇒ Object

    Yields:

    • (c)
  • #each_codepointEnumerator

    Returns:

    • (Enumerator)


924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
# File 'ext/stringio/stringio.c', line 924

static VALUE
strio_each_codepoint(VALUE self)
{
    struct StringIO *ptr;
    rb_encoding *enc;
    unsigned int c;
    int n;

    RETURN_ENUMERATOR(self, 0, 0);

    ptr = readable(self);
    enc = get_enc(ptr);
    for (;;) {
	if (ptr->pos >= RSTRING_LEN(ptr->string)) {
	    return self;
	}

	c = rb_enc_codepoint_len(RSTRING_PTR(ptr->string)+ptr->pos,
				 RSTRING_END(ptr->string), &n, enc);
	rb_yield(UINT2NUM(c));
	ptr->pos += n;
    }
    return self;
}