[Issue 9045] Feature request for std.asscii => function isNewline
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Mar 26 10:04:58 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9045
Nick Sabalausky <cbkbbejeap at mailinator.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |cbkbbejeap at mailinator.com
--- Comment #10 from Nick Sabalausky <cbkbbejeap at mailinator.com> 2013-03-26 10:04:56 PDT ---
While an 'isNewline(dchar)' func wouldn't work for reasons already discussed,
what *would* work and be very helpful IMO, is something similar to the
'std.conv.parse(...)' functions. Ie, just like this, but properly templated,
range-ified and UTF8/16-ified:
/// If 'str' starts with a Unix, Windows, Unicode or Mac9 newline, it is
/// removed from 'str' and returned. Otherwise, null is returned.
dstring parseNewline(ref dstring str)
{
if(str.empty)
return null;
dstring ret;
// Newlines are as defined in:
// http://www.unicode.org/reports/tr18/#Line_Boundaries
switch(str[0])
{
case '\r':
if(str.length > 1 && str[1] == '\n')
{
ret = str[0..2];
str = str[2..$];
break;
}
goto case;
case '\n':
case '\f':
case '\v':
case '\x85':
case paraSep:
case lineSep:
ret = str[0..1];
str = str[1..$];
break;
default:
ret = null;
break;
}
return ret;
}
--
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