On Wednesday 12 March 2008 23:38:46 [EMAIL PROTECTED] wrote: > Author: duff > Date: Wed Mar 12 23:38:44 2008 > New Revision: 26345 > > Modified: > trunk/languages/perl6/src/pmc/perl6str.pmc > > Log: > [rakudo] rough cut implementation of auto-{increment,decrement} for > Perl6Str > > > Modified: trunk/languages/perl6/src/pmc/perl6str.pmc > =========================================================================== >=== --- trunk/languages/perl6/src/pmc/perl6str.pmc (original) > +++ trunk/languages/perl6/src/pmc/perl6str.pmc Wed Mar 12 23:38:44 2008 > @@ -165,18 +165,136 @@ > =item C<void decrement()> > > Increment/decrement the string magically according to S03 rules. > -For the moment these are stub implementations to avoid throwing > -exceptions when we attempt to increment/decrement a string. > + > +These implementations are very ASCII oriented. They assume that the > +alphabet is contiguous and that there aren't any other characters on > +either side of the letters or digits that return true for C<isalpha()> or > +C<isdigit()> respectively. > > */ > > - void increment() { > - /* do nothing */ > + VTABLE void increment() { > + STRING* str = PMC_str_val(SELF); > + const char *start = str->strstart; > + const char* const end = start + string_length(INTERP, str); > + > + char* substr; /* pointer to the substring we're going to > increment */ + INTVAL len; /* length of the substring */ > + INTVAL i, carry; > + > + const char* s = start; /* start of the current incrementable > substring */
If you find yourself tempted to add a comment to explain what the variable name stands for, fix the variable name instead -- it's a lot easier to read the subsequent code without scrolling back up to read comment flags every time you can't tell what 'ep' means. I'm tidying these PMCs now, so I might get to revising this code in the next few days... but if I don't, feel free to use something like "prev_end" and "prev_start", for example. -- c