www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: eliminate junk from std.string?

reply Jerry Quinn <jlquinn optonline.net> writes:
Andrei Alexandrescu Wrote:

 On 1/9/11 4:51 PM, Andrei Alexandrescu wrote:
 There's a lot of junk in std.string that should be gone. I'm trying to
 motivate myself to port some functions to different string widths and...
 it's not worth it.

 What functions do you think we should remove from std.string? Let's make
 a string and then send them the way of the dino.


 Thanks,

 Andrei

I have uploaded a preview of the changed APIs here: http://d-programming-language.org/cutting-edge/phobos/std_string.html

Unclear if iswhite() refers to ASCII whitespace or Unicode. If Unicode, which version of the standard? Same comment for icmp(). Also, in the Unicode standard, case folding can depend on the specific language. There is room for ascii-only functions, but unless a D version of ICU is going to be done separately, it would be nice to have full unicode-aware functions available. You've got chop() marked as deprecated. Is popBack() going to make sense as something that removes a variable number of chars from a string in the CR-LF case? That might be a bit too magical. Rather than zfill, what about modifying ljustify, rjustify, and center to take an optional fill character? One set of functions I'd like to see are startsWith() and endsWith(). I find them frequently useful in Java and an irritating lack in the C++ standard library. Jerry
Jan 11 2011
next sibling parent reply Jerry Quinn <jlquinn optonline.net> writes:
Jerry Quinn Wrote:

 One set of functions I'd like to see are startsWith() and endsWith().  I find
them frequently useful in Java and an irritating lack in the C++ standard
library.

Just adding that these functions are useful because they're more efficient than doing a find and checking that the match is in the first position. Jerry
Jan 11 2011
parent Dmitry Olshansky <dmitry.olsh gmail.com> writes:
On 12.01.2011 0:47, Jerry Quinn wrote:
 Jerry Quinn Wrote:

 One set of functions I'd like to see are startsWith() and endsWith().  I find
them frequently useful in Java and an irritating lack in the C++ standard
library.

Jerry

wrong with them? -- Dmitry Olshansky
Jan 11 2011
prev sibling parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 1/11/11 1:45 PM, Jerry Quinn wrote:
 Andrei Alexandrescu Wrote:

 On 1/9/11 4:51 PM, Andrei Alexandrescu wrote:
 There's a lot of junk in std.string that should be gone. I'm trying to
 motivate myself to port some functions to different string widths and...
 it's not worth it.

 What functions do you think we should remove from std.string? Let's make
 a string and then send them the way of the dino.


 Thanks,

 Andrei

I have uploaded a preview of the changed APIs here: http://d-programming-language.org/cutting-edge/phobos/std_string.html

Unclear if iswhite() refers to ASCII whitespace or Unicode. If Unicode, which version of the standard?

Not sure. enum dchar LS = '\u2028'; /// UTF line separator enum dchar PS = '\u2029'; /// UTF paragraph separator bool iswhite(dchar c) { return c <= 0x7F ? indexOf(whitespace, c) != -1 : (c == PS || c == LS); } Which version?
 Same comment for icmp().  Also, in the Unicode standard, case folding can
depend on the specific language.

That uses toUniLower. Not sure how that works.
 There is room for ascii-only functions, but unless a D version of ICU
 is going to be done separately, it would be nice to have full
 unicode-aware functions available.

Yah, I'm increasingly thinking of defining an AsciiChar entity and perhaps a Zstring one for zero-terminated strings.
 You've got chop() marked as deprecated.  Is popBack() going to make
 sense as something that removes a variable number of chars from a
 string in the CR-LF case?  That might be a bit too magical.

Well I found little use for chop in e.g. Perl. People either use chomp or want to remove the last character. I think chop is useless.
 Rather than zfill, what about modifying ljustify, rjustify, and
 center to take an optional fill character?

Yah, I wanted to do that but postponed because it's quite a bit of work with general dchars etc.
 One set of functions I'd like to see are startsWith() and endsWith().  I find
them frequently useful in Java and an irritating lack in the C++ standard
library.

Yah, those are in std.algorithm. Ideally we'd move everything that's applicable beyond strings to std.algorithm. Andrei
Jan 11 2011