www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7054] New: formatting fixed width string fields w/utf

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7054

           Summary: formatting fixed width string fields w/utf
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P5
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: brad.lanam.comp gmail.com



---
Using a width specifier in conjunction with a utf string fails.  It would be
nice to have a %S modifier that handles this situation.

123456789012345
   Größe: incorrect
     Größe: correct
Größe   : incorrect
Größe     : correct
Grö      : incorrect
Größ      : correct


import std.stdio;
import std.string;
import std.utf : count;

void
main (string[] args)
{
  string t = "Größe";
  size_t width = 10;
  auto len = t.length;
  auto utflen = std.utf.count (t);
  auto tlen = width + len - utflen;
  writefln ("123456789012345");
  writefln ("%10s: incorrect", t);
  writefln ("%*s: correct", tlen, t);
  writefln ("%-10s: incorrect", t);
  writefln ("%-*s: correct", tlen, t);
  writefln ("%-10.4s: incorrect", t);
  auto fmt = format ("%%-%d.%ds: correct", tlen, tlen - 6);
  writefln (fmt, t);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 02 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7054


Stewart Gordon <smjg iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |spec
                 CC|                            |smjg iname.com
            Summary|formatting fixed width      |writef formats strings
                   |string fields w/utf         |containing UTF-8 multibyte
                   |                            |characters to the wrong
                   |                            |width
           Severity|enhancement                 |normal




 Using a width specifier in conjunction with a utf string fails.  It would be
 nice to have a %S modifier that handles this situation.
We shouldn't need a different format specifier for this. It's a matter of what "Width" means in the format string spec, not one of different kinds of string format. http://www.d-programming-language.org/phobos/std_format.html "Specifies the minimum field width. If the width is a *, the next argument, which must be of type int, is taken as the width. If the width is negative, it is as if the - was given as a Flags character." While it doesn't specify the units the width is measured in, it seems a reasonable assumption that it is intended to be characters, rather than bytes. Indeed, 1.071's version gets it right, so clearly the bug is in the D2 line's implementation. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 04 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7054


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|spec                        |
                 CC|                            |bugzilla digitalmars.com
          Component|DMD                         |Phobos



01:50:59 PST ---
This is a bug in Phobos, not the compiler or spec.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 24 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7054


Denis Shelomovskij <verylonglogin.reg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P5                          |P4
                 CC|                            |verylonglogin.reg gmail.com
            Summary|writef formats strings      |std.format.formattedWrite
                   |containing UTF-8 multibyte  |uses code units count as
                   |characters to the wrong     |width instead of characters
                   |width                       |count


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 06 2012