June 17, 2011 Re: Rename std.string.toStringz? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On 16/06/2011 21:32, Jonathan M Davis wrote:
> I have _never_
> heard the term stringz used outside of D. Searching for it online brings up
> _nothing_ (not even D).
Have you tested what results you get when searching for "c string"?
A...
|
June 17, 2011 Re: Rename std.string.toStringz? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alix Pexton | Alix Pexton wrote:
> On 16/06/2011 21:32, Jonathan M Davis wrote:
>
>> I have _never_
>> heard the term stringz used outside of D. Searching for it online brings up
>> _nothing_ (not even D).
>
> Have you tested what results you get when searching for "c string"?
>
> A...
LOL.
|
June 17, 2011 Re: Rename std.string.toStringz? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Gibson | Daniel Gibson Wrote: > What is to!c_str() supposed to return? C string obviously. > To be a useful alternative to toStringz() it needs to be > > char* to!c_str(string s) (or immutable(char)* or something) > i.e. the related toImpl looks like > char* toImpl(c_str, string)(string s) > => 3 types! (char*, c_str, string) > > But the signature of toImpl is > T toImpl(T, S)(S s) > so the related to's signature is > T to(T)(S s) > or something like that. I thought, D templates allow specialization, so it should be possible to specialize toImpl for c_str like auto toImpl(T,S)(S s) if(T==c_str) { return ... } |
June 17, 2011 Re: Rename std.string.toStringz? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | Am 17.06.2011 15:16, schrieb Kagamin:
> Daniel Gibson Wrote:
>
>> What is to!c_str() supposed to return?
>
> C string obviously.
>
>> To be a useful alternative to toStringz() it needs to be
>>
>> char* to!c_str(string s) (or immutable(char)* or something)
>> i.e. the related toImpl looks like
>> char* toImpl(c_str, string)(string s)
>> => 3 types! (char*, c_str, string)
>>
>> But the signature of toImpl is
>> T toImpl(T, S)(S s)
>> so the related to's signature is
>> T to(T)(S s)
>> or something like that.
>
> I thought, D templates allow specialization, so it should be possible to specialize toImpl for c_str
> like
> auto toImpl(T,S)(S s) if(T==c_str)
> {
> return ...
> }
This would be inconsistent with all other to implementations, as far as I know.
|
June 17, 2011 Re: Rename std.string.toStringz? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dmitry Olshansky | Dmitry Olshansky Wrote:
> Fixable with alias this, but still I dislike this c_str artifact. It looks like you are converting type, while all it does is ensuring that there is enough 0 bytes past the end of string.
It should convert if you pass it, say, dchar[].
toStringz should also support conversion to mutable string.
|
June 17, 2011 Re: Rename std.string.toStringz? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Gibson | Daniel Gibson Wrote:
> char* to!c_str(string s) (or immutable(char)* or something)
> i.e. the related toImpl looks like
> char* toImpl(c_str, string)(string s)
> => 3 types! (char*, c_str, string)
btw, if we're talking about C api, the return type must not be char*, because c string character encoding is not utf-8, but char* implies utf-8.
|
June 17, 2011 Re: Rename std.string.toStringz? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | Am 17.06.2011 15:21, schrieb Kagamin:
> Daniel Gibson Wrote:
>
>> char* to!c_str(string s) (or immutable(char)* or something)
>> i.e. the related toImpl looks like
>> char* toImpl(c_str, string)(string s)
>> => 3 types! (char*, c_str, string)
>
> btw, if we're talking about C api, the return type must not be char*, because c string character encoding is not utf-8, but char* implies utf-8.
Of course we're talking about C api, that's the whole point of toStringz
What about C functions that *do* deal with UTF8?
And C functions that don't care about encoding?
I don't think you usually use different types used in C for ASCII, 8bit
encodings and UTF8..
|
June 17, 2011 Re: Rename std.string.toStringz? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | On 2011-06-17 06:21, Kagamin wrote:
> Daniel Gibson Wrote:
> > char* to!c_str(string s) (or immutable(char)* or something)
> >
> > i.e. the related toImpl looks like
> >
> > char* toImpl(c_str, string)(string s)
> >
> > => 3 types! (char*, c_str, string)
>
> btw, if we're talking about C api, the return type must not be char*, because c string character encoding is not utf-8, but char* implies utf-8.
The C string encoding that the system expects depends on your locale and the function that you're calling. For the most part, it _is_ UTF-8 - at least on Linux.
- Jonathan M Davis
|
Copyright © 1999-2021 by the D Language Foundation