From: Robert Klemme Date: 2009-12-15T00:20:25+09:00 Subject: Re: Ruby 1.9 string slicing and StringScanner pointers 2009/12/14 Brian Candler : > Caio Chassot wrote: >> Should this be considered a bug in StringScanner? Wouldn't it make more >> sense for it to use character indexes? It would seem so. > I suspect the reason it does it this way is because it's very expensive > in ruby 1.9 to jump to the Nth character. So if you were scanning a > large string, it would get slower and slower as you scanned further > along, calling #scan each time. I don't know StringScanner internals, but does this have to be so? I mean, with $' you get the remainder of the string so when not using positions you could handle it that way at the expense of an additional String instance for each match. > I think what you're doing is the only option: tag the string as a > single-byte encoding ("ASCII-8BIT" would be better than "US-ASCII"), > select the range of bytes, and tag it back again, relying on the fact > that strscan has chomped a whole number of characters. Or use String#scan or another matching option, if that is possible. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/