A better way to write this function? (style question)
Thomas Gann
thomasleegann at gmail.com
Mon Dec 30 21:36:04 PST 2013
Thanks for all your replies, guys! I have done some further
research in the meantime and I have found out that I am, in fact,
an idiot. There is actually a standard library function that does
exactly what I am trying to do! As it turns out,
std.string.split():
1) It automatically discards empty tokens, so there is no need to
filter it manually.
2) Its definition of whitespace includes spaces, tabs, and both
types of newlines, so there is no need to convert newlines to
spaces.
An equivalent, but much less verbose, form of the function
becomes the following:
input.toLower.split;
So I'm noticing a common theme here, though, which is that lots
of operations on arrays is bad? Should I be using ranges pretty
much everywhere, then? Or just in performance-critical areas of
code where I want to avoid a lot of copying? Would that just
leave plain vanilla dynamic arrays to the task of (relatively)
permanent storage?
More information about the Digitalmars-d-learn
mailing list