From: Robin B. <ro...@kn...> - 2001-09-18 18:34:31
|
On Tuesday 18 September 2001 20:19, Antoine Quint wrote: > > Have you turned on notification of new subscriptions ? I'd > > like to know about > > it if Bob joins ;-) > > Yes, if Bob is DiBlasi, his posts will be moderated!!! I was thinking about the river one. But yes, moderate all the gremlins fr= om=20 svg-dev. > > If you don't mind testing the version I gave you that adds a > > method to the > > String interface it'd be great. I'd love to know whether that > > approach works. > > Using that we'd be able to have very readable and clean code. > > Well, if there is no way to do it with split, then it's going back in > the code! Yes, but I was thinking specifically about the first one of the two that = I=20 gave: /* this is totally untested, but it would be great if it worked */ function isvgNonNumericSplit () { =A0 =A0 var preClean =3D new Regexp('^\D+'); =A0 =A0 var postClean =3D new Regexp('\D+$'); =A0 =A0 this.replace(preClean, ''); =A0 =A0 this.replace(postClean, ''); =A0 =A0 return this.split('\D+'); } // add to the interface String.prototype.isvgNonNumericSplit =3D isvgNonNumericSplit; We could perhaps have a global isvgUtilRegexp object hanging around to=20 contain all the generally useful Regexps we may use. This would avoid hav= ing=20 to redefine them everytime, and would allow us to fix Regexp bugs far mor= e=20 easily (notably if we start running into unforeseen encoding problems, wh= ich=20 wouldn't suprise me). function isvgUtilRegexp () { this.version =3D '0.0.1'; // version interfaces ? this.nonNumericStart =3D new Regexp('^\D+'); this.nonNumericEnd =3D new Regexp('\D+$'); // etc.... follows long definitions return this; } var globalUtilRegexp =3D new isvgUtilRegexp; We would then have: function isvgNonNumericSplit () { =A0 =A0 this.replace(globalUtilRegexp.nonNumericStart, ''); =A0 =A0 this.replace(globalUtilRegexp.nonNumericEnd, ''); =A0 =A0 return this.split('\D+'); } // add to the interface String.prototype.isvgNonNumericSplit =3D isvgNonNumericSplit; I know that it looks stupid given the simplicity of this example, but if = we=20 want this thing to grow we might just as well put all reusable regexen=20 together. > What would the Perl split do in the case I described? It'd give an empty first element, but no empty last element (unless you a= dded=20 a negative LIMIT parametre). Split is a complex little thing in pretty mu= ch=20 all languages. --=20 _______________________________________________________________________ Robin Berjon <ro...@kn...> -- CTO k n o w s c a p e : // venture knowledge agency www.knowscape.com ----------------------------------------------------------------------- An eye for an eye will make the whole world blind. -- Mahatma Gandhi |