ruby-changes:23240
From: drbrain <ko1@a...>
Date: Wed, 11 Apr 2012 06:11:47 +0900 (JST)
Subject: [ruby-changes:23240] drbrain:r35291 (trunk): * string.c (rb_str_tr): Documented use of \ to escape characters.
drbrain 2012-04-11 06:11:37 +0900 (Wed, 11 Apr 2012) New Revision: 35291 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35291 Log: * string.c (rb_str_tr): Documented use of \ to escape characters. [ruby-trunk - Bug #6161] * string.c (rb_str_count): ditto Modified files: trunk/ChangeLog trunk/string.c Index: ChangeLog =================================================================== --- ChangeLog (revision 35290) +++ ChangeLog (revision 35291) @@ -1,3 +1,9 @@ +Wed Apr 11 06:11:10 2012 Eric Hodel <drbrain@s...> + + * string.c (rb_str_tr): Documented use of \ to escape characters. + [ruby-trunk - Bug #6161] + * string.c (rb_str_count): ditto + Wed Apr 11 05:14:51 2012 Eric Hodel <drbrain@s...> * lib/abbrev.rb: Clarified that Abbrev.abbrev returns a Hash instead Index: string.c =================================================================== --- string.c (revision 35290) +++ string.c (revision 35291) @@ -5270,20 +5270,35 @@ * call-seq: * str.tr(from_str, to_str) => new_str * - * Returns a copy of <i>str</i> with the characters in <i>from_str</i> - * replaced by the corresponding characters in <i>to_str</i>. If - * <i>to_str</i> is shorter than <i>from_str</i>, it is padded with its last - * character in order to maintain the correspondence. + * Returns a copy of +str+ with the characters in +from_str+ replaced by the + * corresponding characters in +to_str+. If +to_str+ is shorter than + * +from_str+, it is padded with its last character in order to maintain the + * correspondence. * * "hello".tr('el', 'ip') #=> "hippo" * "hello".tr('aeiou', '*') #=> "h*ll*" + * "hello".tr('aeiou', 'AA*') #=> "hAll*" * - * Both strings may use the c1-c2 notation to denote ranges of characters, - * and <i>from_str</i> may start with a <code>^</code>, which denotes all - * characters except those listed. + * Both strings may use the <code>c1-c2</code> notation to denote ranges of + * characters, and +from_str+ may start with a <code>^</code>, which denotes + * all characters except those listed. * * "hello".tr('a-y', 'b-z') #=> "ifmmp" * "hello".tr('^aeiou', '*') #=> "*e**o" + * + * The backslash character <code>\</code> can be used to escape + * <code>^</code> or <code>-</code> and is otherwise ignored unless it + * appears at the end of a range or the end of the +from_str+ or +to_str+: + * + * "hello^world".tr("\\^aeiou", "*") #=> "h*ll**w*rld" + * "hello-world".tr("a\\-eo", "*") #=> "h*ll**w*rld" + * + * "hello\r\nworld".tr("\r", "") #=> "hello\nworld" + * "hello\r\nworld".tr("\\r", "") #=> "hello\r\nwold" + * "hello\r\nworld".tr("\\\r", "") #=> "hello\nworld" + * + * "X['\\b']".tr("X\\", "") #=> "['b']" + * "X['\\b']".tr("X-\\]", "") #=> "'b'" */ static VALUE @@ -5622,16 +5637,27 @@ * call-seq: * str.count([other_str]+) -> fixnum * - * Each <i>other_str</i> parameter defines a set of characters to count. The - * intersection of these sets defines the characters to count in - * <i>str</i>. Any <i>other_str</i> that starts with a caret (^) is - * negated. The sequence c1--c2 means all characters between c1 and c2. + * Each +other_str+ parameter defines a set of characters to count. The + * intersection of these sets defines the characters to count in +str+. Any + * +other_str+ that starts with a caret <code>^</code> is negated. The + * sequence <code>c1-c2</code> means all characters between c1 and c2. The + * backslash character <code>\</code> can be used to escape <code>^</code> or + * <code>-</code> and is otherwise ignored unless it appears at the end of a + * sequence or the end of a +other_str+. * * a = "hello world" - * a.count "lo" #=> 5 - * a.count "lo", "o" #=> 2 - * a.count "hello", "^l" #=> 4 - * a.count "ej-m" #=> 4 + * a.count "lo" #=> 5 + * a.count "lo", "o" #=> 2 + * a.count "hello", "^l" #=> 4 + * a.count "ej-m" #=> 4 + * + * "hello^world".count "\\^aeiou" #=> 4 + * "hello-world".count "a\\-eo" #=> 4 + * + * c = "hello world\\r\\n" + * c.count "\\" #=> 2 + * c.count "\\A" #=> 0 + * c.count "X-\\w" #=> 3 */ static VALUE -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/