Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 1751

Show
Ignore:
Timestamp:
07/12/10 01:17:37 (14 years ago)
Author:
andrei
Message:

Changed w.put(e) with put(w, e) everywhere

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/phobos/std/format.d

    r1748 r1751  
    808808                "\ntrailing = ", trailing, "\n"); 
    809809    } 
    810810} 
    811811 
    812812/** 
    813813   $(D void[]) is formatted like $(D ubyte[]). 
    814814 */ 
    815815void formatValue(Writer, T, Char)(Writer w, T val, ref FormatSpec!Char f) 
    816816if (is(const(T) == const(void[]))) 
    817817{ 
    818     w.put(cast(const ubyte[]) val); 
     818    put(w, cast(const ubyte[]) val); 
    819819} 
    820820 
    821821unittest 
    822822{ 
    823823    FormatSpec!char f; 
    824824    auto a = appender!string(); 
    825825    void[] val; 
    826826    formatValue(a, val, f); 
    827827} 
    828828 
     
    849849    Unqual!T arg = val; 
    850850    if (f.spec == 'r') 
    851851    { 
    852852        // raw write, skip all else and write the thing 
    853853        auto begin = cast(const char*) &arg; 
    854854        if (std.system.endian == Endian.LittleEndian && f.flPlus 
    855855            || std.system.endian == Endian.BigEndian && f.flDash) 
    856856        { 
    857857            // must swap bytes 
    858858            foreach_reverse (i; 0 .. arg.sizeof) 
    859                 w.put(begin[i]); 
     859                put(w, begin[i]); 
    860860        } 
    861861        else 
    862862        { 
    863863            foreach (i; 0 .. arg.sizeof) 
    864                 w.put(begin[i]); 
     864                put(w, begin[i]); 
    865865        } 
    866866        return; 
    867867    } 
    868868    if (f.precision == f.UNSPECIFIED) 
    869869    { 
    870870        // default precision for integrals is 1 
    871871        f.precision = 1; 
    872872    } 
    873873    else 
    874874    { 
     
    916916        { 
    917917            --i; 
    918918            buffer[i] = cast(char) (n % base); 
    919919            n /= base; 
    920920            if (buffer[i] < 10) buffer[i] += '0'; 
    921921            else buffer[i] += (f.spec == 'x' ? 'a' : 'A') - 10; 
    922922        } while (n); 
    923923        digits = buffer[i .. $]; // got the digits without the sign 
    924924    } 
    925925    // adjust precision to print a '0' for octal if alternate format is on 
    926     if (base == 8 && f.flHash() 
     926    if (base == 8 && f.flHash 
    927927        && (f.precision <= digits.length)) // too low precision 
    928928    { 
    929929        //f.precision = digits.length + (arg != 0); 
    930930        forcedPrefix = '0'; 
    931931    } 
    932932    // write left pad; write sign; write 0x or 0X; write digits; 
    933933    //   write right pad 
    934934    // Writing left pad 
    935935    int spacesToPrint = 
    936936        f.width // start with the minimum width 
    937937        - digits.length  // take away digits to print 
    938938        - (forcedPrefix != 0) // take away the sign if any 
    939         - (base == 16 && f.flHash() && arg ? 2 : 0); // 0x or 0X 
     939        - (base == 16 && f.flHash && arg ? 2 : 0); // 0x or 0X 
    940940    const int delta = f.precision - digits.length; 
    941941    if (delta > 0) spacesToPrint -= delta; 
    942942    //writeln(spacesToPrint); 
    943943    if (spacesToPrint > 0) // need to do some padding 
    944944    { 
    945945        if (leftPad == '0') 
    946946        { 
    947947            // pad with zeros 
    948948            f.precision = 
    949949                cast(typeof(f.precision)) (spacesToPrint + digits.length); 
    950950                //to!(typeof(f.precision))(spacesToPrint + digits.length); 
    951951        } 
    952         else if (leftPad) foreach (i ; 0 .. spacesToPrint) w.put(' '); 
     952        else if (leftPad) foreach (i ; 0 .. spacesToPrint) put(w, ' '); 
    953953    } 
    954954    // write sign 
    955     if (forcedPrefix) w.put(forcedPrefix); 
     955    if (forcedPrefix) put(w, forcedPrefix); 
    956956    // write 0x or 0X 
    957     if (base == 16 && f.flHash() && arg) { 
     957    if (base == 16 && f.flHash && arg) { 
    958958        // @@@ overcome bug in dmd; 
    959959        //w.write(f.spec == 'x' ? "0x" : "0X"); //crashes the compiler 
    960         w.put('0'); 
    961         w.put(f.spec == 'x' ? 'x' : 'X'); // x or X 
     960        put(w, '0'); 
     961        put(w, f.spec == 'x' ? 'x' : 'X'); // x or X 
    962962    } 
    963963    // write the digits 
    964964    if (arg || f.precision) 
    965965    { 
    966966        int zerosToPrint = f.precision - digits.length; 
    967         foreach (i ; 0 .. zerosToPrint) w.put('0'); 
    968         w.put(digits); 
     967        foreach (i ; 0 .. zerosToPrint) put(w, '0'); 
     968        put(w, digits); 
    969969    } 
    970970    // write the spaces to the right if left-align 
    971     if (!leftPad) foreach (i ; 0 .. spacesToPrint) w.put(' '); 
     971    if (!leftPad) foreach (i ; 0 .. spacesToPrint) put(w, ' '); 
    972972} 
    973973 
    974974/** 
    975975 * Floating-point values are formatted like $(D printf) does. 
    976976 */ 
    977977void formatValue(Writer, D, Char)(Writer w, D obj, 
    978978        ref FormatSpec!Char f) 
    979979if (isFloatingPoint!D) 
    980980{ 
    981981    if (f.spec == 'r') 
    982982    { 
    983983        // raw write, skip all else and write the thing 
    984984        auto begin = cast(const char*) &obj; 
    985985        if (std.system.endian == Endian.LittleEndian && f.flPlus 
    986986            || std.system.endian == Endian.BigEndian && f.flDash) 
    987987        { 
    988988            // must swap bytes 
    989989            foreach_reverse (i; 0 .. obj.sizeof) 
    990                 w.put(begin[i]); 
     990                put(w, begin[i]); 
    991991        } 
    992992        else 
    993993        { 
    994994            foreach (i; 0 .. obj.sizeof) 
    995                 w.put(begin[i]); 
     995                put(w, begin[i]); 
    996996        } 
    997997        return; 
    998998    } 
    999999    if (std.string.indexOf("fgFGaAeEs", f.spec) < 0) { 
    10001000        throw new FormatError("floating"); 
    10011001    } 
    10021002    if (f.spec == 's') f.spec = 'g'; 
    10031003    char sprintfSpec[1 /*%*/ + 5 /*flags*/ + 3 /*width.prec*/ + 2 /*format*/ 
    10041004                     + 1 /*\0*/] = void; 
    10051005    sprintfSpec[0] = '%'; 
     
    10171017    //printf("format: '%s'; geeba: %g\n", sprintfSpec.ptr, obj); 
    10181018    char[512] buf; 
    10191019    //writeln("Spec is: ", sprintfSpec); 
    10201020    immutable n = snprintf(buf.ptr, buf.length, 
    10211021            sprintfSpec.ptr, 
    10221022            f.width, 
    10231023            // negative precision is same as no precision specified 
    10241024            f.precision == f.UNSPECIFIED ? -1 : f.precision, 
    10251025            obj); 
    10261026    if (n < 0) throw new FormatError("floating point formatting failure"); 
    1027     w.put(buf[0 .. strlen(buf.ptr)]); 
     1027    put(w, buf[0 .. strlen(buf.ptr)]); 
    10281028} 
    10291029 
    10301030unittest 
    10311031{ 
    10321032    auto a = appender!(string)(); 
    10331033    immutable real x = 5.5; 
    10341034    FormatSpec!char f; 
    10351035    formatValue(a, x, f); 
    10361036    assert(a.data == "5.5"); 
    10371037} 
    10381038 
    10391039/** 
    10401040   $(D bool) is formatted as "true" or "false" with %s and as "1" or 
    10411041   "0" with integral-specific format specs. 
    10421042 */ 
    10431043void formatValue(Writer, T, Char)(Writer w, T val, 
    10441044        ref FormatSpec!Char f) 
    10451045if (is(T : bool)) 
    10461046{ 
    10471047    if (f.spec == 's') { 
    1048         w.put(val ? "true" : "false"); 
     1048        put(w, val ? "true" : "false"); 
    10491049    } else { 
    10501050        formatValue(w, cast(int) val, f); 
    10511051    } 
    10521052} 
    10531053 
    10541054/** 
    10551055   Individual characters ($(D char), $(D wchar), or $(D dchar)) are 
    10561056   formatted as Unicode characters with %s and as integers with 
    10571057   integral-specific format specs. 
    10581058 */ 
    10591059void formatValue(Writer, T, Char)(Writer w, T val, 
    10601060        ref FormatSpec!Char f) 
    10611061if (isSomeChar!T) 
    10621062{ 
    10631063    if (f.spec == 's') { 
    1064         w.put(val); 
     1064        put(w, val); 
    10651065    } else { 
    10661066        formatValue(w, cast(uint) val, f); 
    10671067    } 
    10681068} 
    10691069 
    10701070/** 
    10711071   Strings are formatted like printf does. 
    10721072 */ 
    10731073void formatValue(Writer, T, Char)(Writer w, T val, 
    10741074        ref FormatSpec!Char f) 
    10751075if (isSomeString!T && !isStaticArray!T) 
    10761076{ 
    10771077    auto s = val[0 .. f.precision < $ ? f.precision : $]; 
    10781078    if (!f.flDash) 
    10791079    { 
    10801080        // right align 
    10811081        if (f.width > s.length) 
    1082             foreach (i ; 0 .. f.width - s.length) w.put(' '); 
    1083         w.put(s); 
     1082            foreach (i ; 0 .. f.width - s.length) put(w, ' '); 
     1083        put(w, s); 
    10841084    } 
    10851085    else 
    10861086    { 
    10871087        // left align 
    1088         w.put(s); 
     1088        put(w, s); 
    10891089        if (f.width > s.length) 
    1090             foreach (i ; 0 .. f.width - s.length) w.put(' '); 
     1090            foreach (i ; 0 .. f.width - s.length) put(w, ' '); 
    10911091    } 
    10921092} 
    10931093 
    10941094/** 
    10951095   Input ranges are formatted like arrays. 
    10961096 */ 
    10971097void formatValue(Writer, T, Char)(Writer w, T val, 
    10981098        ref FormatSpec!Char f) 
    10991099if (isInputRange!T && !isSomeChar!(ElementType!T)) 
    11001100{ 
     
    11141114                formatValue(w, arr.front, f); 
    11151115            } 
    11161116        } 
    11171117    } 
    11181118    else 
    11191119    { 
    11201120        if (arr.empty) return; 
    11211121        // formatted writes 
    11221122        if (!f.nested) 
    11231123        { 
    1124             w.put(f.seqBefore); 
    1125             scope(exit) w.put(f.seqAfter); 
     1124            put(w, f.seqBefore); 
     1125            scope(exit) put(w, f.seqAfter); 
    11261126            formatValue(w, arr.front, f); 
    11271127            arr.popFront(); 
    11281128            for (size_t i; !arr.empty; arr.popFront(), ++i) 
    11291129            { 
    1130                 w.put(f.seqSeparator); 
     1130                put(w, f.seqSeparator); 
    11311131                formatValue(w, arr.front, f); 
    11321132            } 
    11331133        } 
    11341134        else 
    11351135        { 
    11361136            // Nested specifier is to be used 
    11371137            for (;;) 
    11381138            { 
    11391139                auto f = FormatSpec!Char(f.nested); 
    11401140                f.writeUpToNextSpec(w); 
     
    11591159            // itemFormatString = itemFormatString[i .. $]; 
    11601160            // auto itemFmt = FormatSpec(itemFormatString); 
    11611161            // auto tail = itemFormatString; 
    11621162            // for (;;) 
    11631163            // { 
    11641164            //     auto headCopy = head; 
    11651165            //     writeUpToFormatSpec(w, headCopy); 
    11661166            //     formatValue(w, arr.front, itemFmt); 
    11671167            //     arr.popFront(); 
    11681168            //     if (arr.empty) break; 
    1169             //     w.put(tail); 
     1169            //     put(w, tail); 
    11701170            // } 
    11711171        } 
    11721172    } 
    11731173} 
    11741174 
    11751175/** 
    11761176   $(D void[0]) is formatted as "[]". 
    11771177 */ 
    11781178void formatValue(Writer, T, Char)(Writer w, T val, 
    11791179        ref FormatSpec!Char f) 
    11801180if (is(D == void[0])) 
    11811181{ 
    1182     w.put(seqBefore); 
    1183     w.put(seqAfter); 
     1182    put(w, seqBefore); 
     1183    put(w, seqAfter); 
    11841184} 
    11851185 
    11861186/** 
    11871187   Pointers are formatted as hex integers. 
    11881188 */ 
    11891189void formatValue(Writer, T, Char)(Writer w, T val, 
    11901190        ref FormatSpec!Char f) 
    11911191if (isPointer!T) 
    11921192{ 
    11931193    const void * p = val; 
     
    11951195    formatValue(w, cast(ulong) p, f); 
    11961196} 
    11971197 
    11981198/** 
    11991199   Objects are formatted by calling $(D toString). 
    12001200 */ 
    12011201void formatValue(Writer, T, Char)(Writer w, T val, 
    12021202        ref FormatSpec!Char f) 
    12031203if (is(T == class)) 
    12041204{ 
    1205     if (val is null) w.put("null"); 
    1206     else w.put(val.toString); 
     1205    if (val is null) put(w, "null"); 
     1206    else put(w, val.toString); 
    12071207} 
    12081208 
    12091209/** 
    12101210   Associative arrays are formatted by using $(D ':') and $(D ' ') as 
    12111211   separators. 
    12121212 */ 
    12131213void formatValue(Writer, T, Char)(Writer w, T val, 
    12141214        ref FormatSpec!Char f) 
    12151215if (isAssociativeArray!T) 
    12161216{ 
    12171217    bool firstTime = true; 
    12181218    foreach (ref k, v; val) 
    12191219    { 
    12201220        if (firstTime) firstTime = false; 
    1221         else w.put(' '); 
     1221        else put(w, ' '); 
    12221222        formatValue(w, k, f); 
    1223         w.put(':'); 
     1223        put(w, ':'); 
    12241224        formatValue(w, v, f); 
    12251225    } 
    12261226} 
    12271227 
    12281228/** 
    12291229   Associative arrays are formatted by using $(D ':') and $(D ' ') as 
    12301230   separators. 
    12311231 */ 
    12321232void formatValue(Writer, T, Char)(Writer w, T val, 
    12331233        ref FormatSpec!Char f) 
    12341234if (is(T == struct) && !isInputRange!T) 
    12351235{ 
    1236     if (is(typeof(w.put(val.toString)))) 
    1237     { 
    1238         w.put(val.toString); 
     1236    if (is(typeof(put(w, val.toString)))) 
     1237    { 
     1238        put(w, val.toString); 
    12391239    } 
    12401240    else 
    12411241    { 
    1242         w.put(S.stringof); 
     1242        put(w, S.stringof); 
    12431243    } 
    12441244} 
    12451245 
    12461246/** 
    12471247   Static-size arrays are formatted just like arrays. 
    12481248 */ 
    12491249void formatValue(Writer, T, Char)(Writer w, ref T val, 
    12501250        ref FormatSpec!Char f) 
    12511251if (isStaticArray!T) 
    12521252{