[Issue 5379] std.array.replace fails on char[]s

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jan 3 05:58:06 PST 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5379


Lars T. Kyllingstad <bugzilla at kyllingen.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla at kyllingen.net
         Resolution|                            |WONTFIX


--- Comment #1 from Lars T. Kyllingstad <bugzilla at kyllingen.net> 2011-01-03 05:55:54 PST ---
The thing is, char[] is assumed to be UTF-8 encoded, which means that one array
element doesn't necessarily correspond to one symbol (or, more precisely, one
code point may be composed of several code units).  That's why (from a range
point of view) the element type of char[] is dchar, which is UTF-32 encoded, or
"decoded" in the sense that one element is one symbol.

Here's an example to prove the point:

  char[] foo = "ångstrøm";
  replace(foo, 0, 1, "a");

If this were allowed, foo would not contain "angstrøm" as one may expect, it
would contain garbage.  This is because the first character, "å", spans two
array elements.

You have two options:

1. If you want to use std.array.replace() like this with character arrays, you
should use dchar[].

2. Use std.string.replace(), which works with strings but always allocates.


I am closing this as WONTFIX.  There are several people who disagree with dchar
being the range element type of char[], however, so feel free to reopen as an
enhancement request if you wish.

-- 
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