News for hackers. Stuff that matters.
Re:The Absolute Minimum Every Software Developer Must Know A... by DrJokepu on Wednesday January 11, 2012 @04:23PM (#3453761)
Maybe I'm missing something but I'm not sure if I understand you question. How would you write even a simple parser without being able to access the contents of the string randomly by the character index?
Re:The Absolute Minimum Every Software Developer Must Know A... by pjscott on Wednesday January 11, 2012 @05:12PM (#3453940)
You can access the contents randomly. Just use the index in bytes, rather than characters. Let's look at a really simple parsing task as an example: splitting tab-delimited strings, in UTF-8. First, you find the indexes in the string (in bytes) of the commas, then you use those to split out substrings. This is exactly the same code you would use with plain ASCII text, and in fact a lot of programs designed to process ASCII work unmodified with UTF-8.

Another example: for a lex-and-yacc type of parser, you can use regular expressions to split a string into tokens, and then use a parser on that stream-of-tokens representation. None of this requires character indexing; just byte indexing.