www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - String front, back return code point/unit

reply vit <vit vit.vit> writes:
Hello,

I am implementing  nogc string struct similar to c++ 
std::basic_string (link 
https://code.dlang.org/packages/basic_string).

C++ string has methods front, back and pop_back 
returning/deleting code units.
D strings has functions (std.range) front, back and popBack 
returning/deleting code points (autodecoding?).

Which behavior is better?
Jun 23
parent reply Tejas <notrealemail gmail.com> writes:
On Wednesday, 23 June 2021 at 15:31:04 UTC, vit wrote:
 Hello,

 I am implementing  nogc string struct similar to c++ 
 std::basic_string (link 
 https://code.dlang.org/packages/basic_string).

 C++ string has methods front, back and pop_back 
 returning/deleting code units.
 D strings has functions (std.range) front, back and popBack 
 returning/deleting code points (autodecoding?).

 Which behavior is better?
I think this video will be helpful: https://www.youtube.com/watch?v=d3qY4dZ2r4w There was also a discussion about this in the group: https://forum.dlang.org/thread/diexjstekiyzgxlicnts forum.dlang.org
Jun 23
parent reply vit <vit vit.vit> writes:
On Wednesday, 23 June 2021 at 15:48:57 UTC, Tejas wrote:
 On Wednesday, 23 June 2021 at 15:31:04 UTC, vit wrote:
 Hello,

 I am implementing  nogc string struct similar to c++ 
 std::basic_string (link 
 https://code.dlang.org/packages/basic_string).

 C++ string has methods front, back and pop_back 
 returning/deleting code units.
 D strings has functions (std.range) front, back and popBack 
 returning/deleting code points (autodecoding?).

 Which behavior is better?
I think this video will be helpful: https://www.youtube.com/watch?v=d3qY4dZ2r4w There was also a discussion about this in the group: https://forum.dlang.org/thread/diexjstekiyzgxlicnts forum.dlang.org
I wrongly formulated question. My question is not about ranges/iterators but if is good idea autodecoding custom string or not.
Jun 23
parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Wed, Jun 23, 2021 at 04:01:24PM +0000, vit via Digitalmars-d-learn wrote:
[...]
 My question is not about ranges/iterators but if is good idea
 autodecoding custom string or not.
No. Autodecoding is one of the decisions we regret because it introduces an unavoidable overhead on basically every string operation in Phobos. Autodecoding was introduced under the misunderstanding that code point == grapheme, but unfortunately that is false. So it fails to accomplish its original purpose and on top of that introduces a performance problem. To accomplish its original purpose would require grapheme decoding; but unfortunately that introduces an even worse performance overhead (Unicode grapheme decoding is non-trivial). tl;dr: don't do it. T -- Why are you blatanly misspelling "blatant"? -- Branden Robinson
Jun 23