From f5ec2b0d75e1f29705aa6b04fdf9e03791b99997 Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 21 Sep 2006 08:47:03 +0000 Subject: [PATCH] * 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@10984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ string.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index eecd314811..c2d1cd20c7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Thu Sep 21 17:44:49 2006 Yukihiro Matsumoto + + * 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?. + Thu Sep 21 16:29:02 2006 WATANABE Hirofumi * rubytest.rb: use each_line instead of each. diff --git a/string.c b/string.c index c13f3a15e0..64da8f337f 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