From 774609abe936dbb153a9a45acc6349912ad49ba9 Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 21 Sep 2006 08:47:03 +0000 Subject: * string.c (rb_str_startwith): a new method to check if a string starts with given prefix. * string.c (rb_str_endwith): the opposite of String#startwith?. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@10984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'string.c') diff --git a/string.c b/string.c index c13f3a15e..64da8f337 100644 --- a/string.c +++ b/string.c @@ -3118,7 +3118,7 @@ tr_setup_table(VALUE str, char table[256], int init) /* * call-seq: - * str.delete!([other_str]+>) => str or nil + * str.delete!([other_str]+) => str or nil * * Performs a delete operation in place, returning str, or * nil if str was not modified. @@ -4498,6 +4498,51 @@ rb_str_rpartition(VALUE str, VALUE sep) RSTRING_LEN(str)-pos-RSTRING_LEN(sep))); } +/* + * call-seq: + * str.startwith?([prefix]+) => true or false + * + * Returns true if str starts with the prefix given. + */ + +static VALUE +rb_str_startwith(int argc, VALUE *argv, VALUE str) +{ + int i; + + for (i=0; i true or false + * + * Returns true if str ends with the suffix given. + */ + +static VALUE +rb_str_endwith(int argc, VALUE *argv, VALUE str) +{ + int i; + + for (i=0; i