[Issue 9045] Feature request for std.asscii => function isNewline

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Nov 20 12:29:11 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=9045



--- Comment #9 from Jonathan M Davis <jmdavisProg at gmx.com> 2012-11-20 12:29:09 PST ---
Any code that only cares about \n or \r\n isn't going to work with a function 
which returns true for both. And any code that doesn't care is going to be
ill-served by a such a function, because the reality is that you need to watch
for \r and \n as individual characters and properly handle the cases when
they're separate as well as when they're apart. And the fact that one of them
is multiple characters generally screws with trying to check for them with a
single function in the middle of iterating. Rather, you have to watch for \r
and \n individually and then figure out whether you're dealing with them singly
or together and act appropriately. A function which returns true for a string
is generally useless for the kind of situations where you'd be checking for
newlines, so I'm highly skeptical that such a function is of any real value.
Instead, you end up with stuff like

for(auto range = str.save; !range.empty; range.popFront())
{
    switch(range.front)
    {
        case '\r':
            auto temp = range.save;
            temp.popFront();
            if(temp.front == '\n')
            {
                range.popFront();
                goto case '\n';
            }
            goto default;
        case '\n':
            //do whatever you do for end of line
            break;
        default:
            //do whatever you do for individual characters
            break;
    }
}

And if you all you want to know is whether a particular string starts or ends
with a newline, then it's easy enough to just do str.startsWith("\n", "\r\n")
or str.endsWith("\n", "\r\n"). That gets uglier when you need to deal with
unicode rather than just \n an \r\n, but then all I believe that you really
need is to add [paraSep], and [lineSep] to the list.

I'm not sure that a function telling you whether a string designates the end of
a line is completely useless, but in pretty much every case that I can see code
caring, such a function wouldn't work very well.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list