-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrb_u_string_end_with.c
More file actions
31 lines (25 loc) · 1003 Bytes
/
rb_u_string_end_with.c
File metadata and controls
31 lines (25 loc) · 1003 Bytes
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
#include "rb_includes.h"
/* @overload end_with?(*suffixes)
* @param [Array] suffixes
* @return [Boolean] True if any element of SUFFIXES that responds to #to_str
* is a byte-level suffix of the receiver */
VALUE
rb_u_string_end_with(int argc, VALUE *argv, VALUE self)
{
const struct rb_u_string *string = RVAL2USTRING(self);
const char *end = USTRING_END(string);
long p_length = USTRING_LENGTH(string);
for (int i = 0; i < argc; i++) {
VALUE tmp = rb_u_string_check_type(argv[i]);
if (NIL_P(tmp))
continue;
const struct rb_u_string *other = RVAL2USTRING_ANY(tmp);
const char *q = USTRING_STR(other);
long q_length = USTRING_LENGTH(other);
if (p_length < q_length)
continue;
if (memcmp(end - q_length, q, q_length) == 0)
return Qtrue;
}
return Qfalse;
}