sort strings by interpreting them as integrals

Andrej Mitrovic andrej.mitrovich at gmail.com
Sun Jul 29 20:15:51 PDT 2012


On 7/30/12, bearophile <bearophileHUGS at lycos.com> wrote:
> Because sorting numbers as
> strings is a very good source of bugs.

Thinking about this, pretty much any interpretation of strings is a
very good source of bugs. I've been thinking how e.g. path
manipulation might better be done with tokenization. For example if
you build two paths it's easier to compare them if internally they're
stored as tokens:

Path path1 = Path("c:/foo/bar");
Path path2 = Path(r"C:/foo/bar/doo/../");
assert(path1 == path2);

When you deal with naked strings you have to normalize the paths
somehow before doing comparisons. But I haven't seen any libraries
which use tokenization for paths.. maybe some exist out there..


More information about the Digitalmars-d-learn mailing list