Method: String#rpartition
- Defined in:
- string.c
#rpartition(sep) ⇒ Array
:include: doc/string/rpartition.rdoc
11036 11037 11038 11039 11040 11041 11042 11043 11044 11045 11046 11047 11048 11049 11050 11051 11052 11053 11054 11055 11056 11057 11058 11059 11060 11061 11062 11063 11064 11065 11066 |
# File 'string.c', line 11036 static VALUE rb_str_rpartition(VALUE str, VALUE sep) { long pos = RSTRING_LEN(str); sep = get_pat_quoted(sep, 0); if (RB_TYPE_P(sep, T_REGEXP)) { if (rb_reg_search(sep, str, pos, 1) < 0) { goto failed; } VALUE match = rb_backref_get(); struct re_registers *regs = RMATCH_REGS(match); pos = BEG(0); sep = rb_str_subseq(str, pos, END(0) - pos); } else { pos = rb_str_sublen(str, pos); pos = rb_str_rindex(str, sep, pos); if (pos < 0) { goto failed; } } return rb_ary_new3(3, rb_str_subseq(str, 0, pos), sep, rb_str_subseq(str, pos+RSTRING_LEN(sep), RSTRING_LEN(str)-pos-RSTRING_LEN(sep))); failed: return rb_ary_new3(3, str_new_empty_String(str), str_new_empty_String(str), str_duplicate(rb_cString, str)); } |