digitalmars.D.bugs - [Issue 11254] New: std.string.strip is not nothrow
- d-bugmail puremagic.com (27/27) Oct 14 2013 http://d.puremagic.com/issues/show_bug.cgi?id=11254
- d-bugmail puremagic.com (15/33) Oct 14 2013 http://d.puremagic.com/issues/show_bug.cgi?id=11254
- d-bugmail puremagic.com (13/16) Oct 14 2013 http://d.puremagic.com/issues/show_bug.cgi?id=11254
- d-bugmail puremagic.com (15/28) Oct 14 2013 http://d.puremagic.com/issues/show_bug.cgi?id=11254
- d-bugmail puremagic.com (12/12) Oct 14 2013 http://d.puremagic.com/issues/show_bug.cgi?id=11254
http://d.puremagic.com/issues/show_bug.cgi?id=11254
Summary: std.string.strip is not nothrow
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody puremagic.com
ReportedBy: bearophile_hugs eml.cc
import std.string: strip;
void main() nothrow {
" hello ".strip;
}
dmd 2.064beta gives:
test.d(3): Error: 'std.string.strip!(immutable(char)).strip' is not nothrow
test.d(2): Error: function 'D main' is nothrow yet may throw
I don't know if this can be done. Often string functions need to decode UTF,
and this could raise exceptions. In most cases, or for ASCII strings, a strip
can't throw exceptions.
If this can't be done then please close down this issue.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 14 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11254
monarchdodra gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |monarchdodra gmail.com
Resolution| |INVALID
import std.string: strip;
void main() nothrow {
" hello ".strip;
}
dmd 2.064beta gives:
test.d(3): Error: 'std.string.strip!(immutable(char)).strip' is not nothrow
test.d(2): Error: function 'D main' is nothrow yet may throw
I don't know if this can be done. Often string functions need to decode UTF,
and this could raise exceptions. In most cases, or for ASCII strings, a strip
can't throw exceptions.
If this can't be done then please close down this issue.
strip is a unicode aware function, that can remove unicode whites, so it *must*
decode. So even if "most of the time", it won't throw, in the generic case, it
can.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 14 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11254strip is a unicode aware function, that can remove unicode whites, so it *must* decode. So even if "most of the time", it won't throw, in the generic case, it can.Some possible alternative solutions: - A strip-like function that works on ubyte[] (the return type of std.string.representation if you give it a string); - A compile-time switch for std.string.strip that compiles out the unicode-aware parts. - A std.ascii.astrip nothrow function designed to work only on ASCII strings/char[]. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 14 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11254You should try the new generic std.algorithm.strip: //---- import std.string, std.ascii, std.algorithm; void main(string[] args) nothrow pure { string s = " hello! "; s = cast(string)s.representation.strip!isWhite(); } //---- -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------strip is a unicode aware function, that can remove unicode whites, so it *must* decode. So even if "most of the time", it won't throw, in the generic case, it can.Some possible alternative solutions: - A strip-like function that works on ubyte[] (the return type of std.string.representation if you give it a string); - A compile-time switch for std.string.strip that compiles out the unicode-aware parts. - A std.ascii.astrip nothrow function designed to work only on ASCII strings/char[].
Oct 14 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11254
Jonathan M Davis <jmdavisProg gmx.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jmdavisProg gmx.com
PDT ---
I think that we should probably move towards overloading string functions with
ubyte[] so that they can have ASCII-specific versions, and more of those would
be able to be nothrow.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 14 2013









d-bugmail puremagic.com 