Changeset 1732
- Timestamp:
- 07/06/10 01:32:14 (14 years ago)
- Files:
-
- trunk/phobos/std/format.d (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/phobos/std/format.d
r1725 r1732 1699 1699 } // end switch 1700 1700 } // end for 1701 1701 enforce(false, text("Incorrect format specifier: ", fmt)); 1702 1702 } 1703 1703 } 1704 1704 1705 1705 //------------------------------------------------------------------------------ 1706 1706 // Writes characters in the format strings up to the first format 1707 1707 // specifier and updates the format specifier to remove the written 1708 1708 // portion The updated format fmt does not include the '%' 1709 private void writeUpToFormatSpec(OutRange, S)( OutRange w, ref S fmt)1709 private void writeUpToFormatSpec(OutRange, S)(ref OutRange w, ref S fmt) 1710 1710 { 1711 1711 for (size_t i = 0; i < fmt.length; ++i) 1712 1712 { 1713 1713 if (fmt[i] != '%') continue; 1714 1714 if (fmt[++i] != '%') 1715 1715 { 1716 1716 // spec found, print and bailout 1717 1717 w.put(fmt[0 .. i - 1]); 1718 1718 fmt = fmt[i .. $]; 1719 1719 return; … … 1745 1745 writeUpToFormatSpec(w, fmt); 1746 1746 assert(w.data == "ab%cd%ef" && fmt == "sg%%h%sij"); 1747 1747 writeUpToFormatSpec(w, fmt); 1748 1748 assert(w.data == "ab%cd%efsg%h" && fmt == "sij"); 1749 1749 } 1750 1750 1751 1751 /* 1752 1752 * Formats an integral number 'arg' according to 'f' and writes it to 1753 1753 * 'w'. 1754 1754 */ 1755 private void formatImpl(Writer, D)( Writer w, D argx, FormatInfo f)1755 private void formatImpl(Writer, D)(ref Writer w, D argx, FormatInfo f) 1756 1756 if (isIntegral!(D)) 1757 1757 { 1758 1758 Unqual!(D) arg = argx; 1759 1759 if (f.spec == 'r') 1760 1760 { 1761 1761 // raw write, skip all else and write the thing 1762 1762 auto begin = cast(const char*) &arg; 1763 1763 if (std.system.endian == Endian.LittleEndian && f.flPlus 1764 1764 || std.system.endian == Endian.BigEndian && f.flDash) 1765 1765 { … … 2167 2167 The positional and non-positional styles can be mixed in the same 2168 2168 format string. (POSIX leaves this behavior undefined.) The internal 2169 2169 counter for non-positional parameters tracks the next parameter after 2170 2170 the largest positional parameter already used. 2171 2171 2172 2172 Warning: 2173 2173 This is the function internally used by writef* but it's still 2174 2174 undergoing active development. Do not rely on it. 2175 2175 */ 2176 2176 2177 void formattedWrite(Writer, F, A...)( Writer w, const(F)[] fmt, A args)2177 void formattedWrite(Writer, F, A...)(ref Writer w, const(F)[] fmt, A args) 2178 2178 { 2179 2179 enum len = args.length; 2180 2180 void function(ref Writer, const(void)*, FormatInfo) funs[len] = void; 2181 2181 const(void)* argsAddresses[len] = void; 2182 2182 foreach (i, arg; args) 2183 2183 { 2184 2184 funs[i] = &formatGeneric!(Writer, typeof(arg)); 2185 2185 argsAddresses[i] = &arg; 2186 2186 } 2187 2187 // Are we already done with formats? Then just dump each parameter in turn
