[#8484] strptime fails to properly parse certain inputs — <noreply@...>

Bugs item #5263, was opened at 2006-08-01 23:14

13 messages 2006/08/02
[#8485] Re: [ ruby-Bugs-5263 ] strptime fails to properly parse certain inputs — Yukihiro Matsumoto <matz@...> 2006/08/02

Hi,

[#8538] Re: [ ruby-Bugs-5263 ] strptime fails to properly parse certain inputs — nobu@... 2006/08/06

Hi,

[#8561] sandbox timers & block scopes — why the lucky stiff <ruby-core@...>

Two puzzles I am trying to solve:

28 messages 2006/08/08
[#8624] Re: sandbox timers & block scopes — why the lucky stiff <ruby-core@...> 2006/08/15

raise ThisDecayingInquisition, "anyone? anyone at all?"

[#8627] Re: sandbox timers & block scopes — MenTaLguY <mental@...> 2006/08/15

On Wed, 2006-08-16 at 00:35 +0900, why the lucky stiff wrote:

[#8628] Re: sandbox timers & block scopes — why the lucky stiff <ruby-core@...> 2006/08/15

On Wed, Aug 16, 2006 at 02:46:30AM +0900, MenTaLguY wrote:

[#8629] Re: sandbox timers & block scopes — "Charles O Nutter" <headius@...> 2006/08/15

On 8/15/06, why the lucky stiff <ruby-core@whytheluckystiff.net> wrote:

[#8690] a ruby-core primer — why the lucky stiff <ruby-core@...>

Hello, all. I've been working on the ruby-core page for the new Ruby site.

21 messages 2006/08/22

Re: [ ruby-Bugs-5273 ] range ===

From: Ondrej Bilka <neleai@...>
Date: 2006-08-03 10:04:23 UTC
List: ruby-core #8503
> ------------ Podnzpr疱a ------------
> Od: Yukihiro Matsumoto <matz@ruby-lang.org>
> Pdm踉: Re: [ ruby-Bugs-5273 ] range ===
> Datum: 03.8.2006 08:25:08
> ----------------------------------------
> Hi,
> 
> In message "Re: [ ruby-Bugs-5273 ] range ==="
>     on Thu, 3 Aug 2006 06:50:03 +0900, <noreply@rubyforge.org> writes:
> 
> |Initial Comment:
> |method range#=== returns false when its begin or end aren't numeric
> |It breaks code like (?a...?z)===?c
> |Another enexpected behaviour is
> |case
> |when (Time.at(0)...Time.at(2))
> 
> Right, it calls Object#=== which should be Enumerable#member?
> The fix was checked in.
> 
> 							matz.
> 
Enumerable#member?  is very slow
And dont work anyway because time is stored as float.  (Time.new...(Time.new+3)).member? Time.new
I would replace numeric restriction to something like
if val.is_a? String || ! val.comparable
   member? val 
else
   cover? val
end
perhaps replace String with #pathologicalsucc?
I would change String#succ to eat leading whitespace and raise error when there isnt. This also helps avoid things like ("1.1"..."1.10").to_a
I changed that string.c and attach unified diff.
also succ!  is faster because directly changes string.  succ is clone,succ!  
To use succ we need method like Range#each!  which calls succ! istead succ


Attachments (1)

diff (3.34 KB, text/x-c)
--- string.c	2006-08-03 13:50:07.629998624 +0200
+++ stringmod.c	2006-08-03 13:59:35.044738472 +0200
@@ -1322,38 +1322,21 @@
 
 /*
  *  call-seq:
- *     str.succ   => new_str
- *     str.next   => new_str
+ *     str.succ!   => str
+ *     str.next!   => str
  *  
- *  Returns the successor to <i>str</i>. The successor is calculated by
- *  incrementing characters starting from the rightmost alphanumeric (or
- *  the rightmost character if there are no alphanumerics) in the
- *  string. Incrementing a digit always results in another digit, and
- *  incrementing a letter results in another letter of the same case.
- *  Incrementing nonalphanumerics uses the underlying character set's
- *  collating sequence.
- *     
- *  If the increment generates a ``carry,'' the character to the left of
- *  it is incremented. This process repeats until there is no carry,
- *  adding an additional character if necessary.
- *     
- *     "abcd".succ        #=> "abce"
- *     "THX1138".succ     #=> "THX1139"
- *     "<<koala>>".succ   #=> "<<koalb>>"
- *     "1999zzz".succ     #=> "2000aaa"
- *     "ZZZ9999".succ     #=> "AAAA0000"
- *     "***".succ         #=> "**+"
+ *  Equivalent to <code>String#succ</code>, but modifies the receiver in
+ *  place.
  */
 
 static VALUE
-rb_str_succ(VALUE orig)
+rb_str_succ_bang(VALUE orig)
 {
-    VALUE str;
+    VALUE str=orig;
     char *sbeg, *s;
     int c = -1;
     long n = 0;
 
-    str = rb_str_new5(orig, RSTRING(orig)->ptr, RSTRING(orig)->len);
     OBJ_INFECT(str, orig);
     if (RSTRING(str)->len == 0) return str;
 
@@ -1375,12 +1358,13 @@
 	}
     }
     if (s < sbeg) {
-	RESIZE_CAPA(str, RSTRING(str)->len + 1);
-	s = RSTRING(str)->ptr + n;
-	memmove(s+1, s, RSTRING(str)->len - n);
-	*s = c;
-	RSTRING(str)->len += 1;
-	RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
+		s=sbeg;
+		while (*s==' ')s++;
+		if (s==sbeg)rb_raise(rb_eRuntimeError, "cannot create next string");
+		if (*s=='0')
+			*(s-1)='1';
+		else
+			*(s-1)=*s;
     }
 
     return str;
@@ -1389,18 +1373,34 @@
 
 /*
  *  call-seq:
- *     str.succ!   => str
- *     str.next!   => str
+ *     str.succ   => new_str
+ *     str.next   => new_str
  *  
- *  Equivalent to <code>String#succ</code>, but modifies the receiver in
- *  place.
+ *  Returns the successor to <i>str</i>. The successor is calculated by
+ *  incrementing characters starting from the rightmost alphanumeric (or
+ *  the rightmost character if there are no alphanumerics) in the
+ *  string. Incrementing a digit always results in another digit, and
+ *  incrementing a letter results in another letter of the same case.
+ *  Incrementing nonalphanumerics uses the underlying character set's
+ *  collating sequence.
+ *     
+ *  If the increment generates a ``carry,'' the character to the left of
+ *  it is incremented. This process repeats until there is no carry,
+ *  adding an additional character if necessary.
+ *     
+ *     "abcd".succ        #=> "abce"
+ *     "THX1138".succ     #=> "THX1139"
+ *     "<<koala>>".succ   #=> "<<koalb>>"
+ *     "1999zzz".succ     #=> "2000aaa"
+ *     "ZZZ9999".succ     #=> "AAAA0000"
+ *     "***".succ         #=> "**+"
  */
 
 static VALUE
-rb_str_succ_bang(VALUE str)
+rb_str_succ(VALUE orig)
 {
-    rb_str_shared_replace(str, rb_str_succ(str));
-
+    VALUE str =rb_str_new5(str, RSTRING(orig)->ptr, RSTRING(orig)->len);
+	rb_str_succ_bang(str);
     return str;
 }
 

In This Thread