/** * Create a new <tt>FormatStringBuffer</tt>. * * @param format the format string. */ public FormatStringBuffer(String format) { reset(format); }
/** * Reset this <tt>FormatStringBuffer</tt>. * * @param format the format string. * @return format reset */ public FormatStringBuffer reset(String format) { reset(); this.format = format; return this; }
/** * Get the result of the formatting. <tt>reset()</tt> is automatically * called from this method. */ public String toString() { if (index < format.length()) buffer.append(format.substring(index)); String str = buffer.toString(); this.reset(); return str; }
fsb.reset("[%s]").format("test"); test("[test]", fsb.toString()); fsb.reset("[%5s]").format("test"); test("[ test]", fsb.toString()); fsb.reset("[%-5s]").format("test"); test("[test ]", fsb.toString()); fsb.reset("[%5.2s]").format("test"); test("[ te]", fsb.toString()); fsb.reset("[%-5.2s]").format("test"); test("[te ]", fsb.toString()); fsb.reset("[%c]").format('A'); test("[A]", fsb.toString()); fsb.reset("[%2c]").format('A'); test("[ A]", fsb.toString()); fsb.reset("[%-2c]").format('A'); test("[A ]", fsb.toString()); fsb.reset("[%f]").format(3.1415); test("[3.1415]", fsb.toString()); fsb.reset("[%g]").format(3.1415); test("[3.1415]", fsb.toString());