Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changes between Version 2 and Version 3 of TutCSharpFormatterComments

Show
Ignore:
Author:
kris (IP: 68.122.70.98)
Timestamp:
03/16/07 18:33:50 (17 years ago)
Comment:

added D formatting

Legend:

Unmodified
Added
Removed
Modified
  • TutCSharpFormatterComments

    v2 v3  
    55The interesting code is in the tango.text.convert.Layout module, in a templated class called Layout(T). You can instantiate the template with char, dchar, or wchar types, and use the !OpCall syntax to format your strings, like this: 
    66{{{ 
     7#!d 
    78import tango.text.convert.Layout; 
    89 
    2122You might consider the sprint() method also, which avoids heap activity. Also, if you're already using Stdout or Stderr, it can be simpler to apply the Layout instance exposed there instead:  
    2223{{{ 
     24#!d 
    2325char[256] out = void; 
    2426auto content = Stdout.layout.sprint (out, "This is the thing: '{}'", thing); 
    2729One might also utilize the locale enabled extensions in a similar manner, by using tango.text.locale.Locale instead of Layout. Locale is a derivative of Layout, so all formatting methods are common with Locale adding support for more sophisticated formatting options along with culture-specific currency, time and date consideration: 
    2830{{{ 
     31#!d 
    2932import tango.text.locale.Locale; 
    3033 
    3639It's also possible to make Stdout and Stderr locale-aware, by replacing the (shared) layout instance: 
    3740{{{ 
     41#!d 
    3842Stdout.layout = new Locale (Culture.getCulture ("fr-FR")); 
    3943}}}