|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jruby.util.PrintfFormat
PrintfFormat is a Java implementation of the sprintf
utility. To use it, you pass the string containing the format
specifier(s) to the constructor, then call the appropriate form of
the sprintf
method. To pass more than one argument,
convert any primitives to their wrapper types and place all the
arguments in an array of type Object
.
PrintfFormat supports all the standard flags ([-+ #0]
),
as well as the '
(apostrophe) flag, which causes decimal
integers to be grouped in a locale-dependent way (e.g, in English
locales, groups of three digits separated by commas). The integer
modifiers ([hlL]
) are also accepted, but the "L" modifier
is ignored as superfluous. Finally, all the standard conversion-type
characters ([idfgGoxXeEcs]
) are supported, except for
"p" and "n".
In addition, PrintfFormat supports positional syntax for arguments,
field widths, and precisions. A format specifier that starts with
a "%n$" sequence will be applied to the nth argument.
A field width or precision of the form "*m$" will take its
value from the mth argument. The standard variable specifier
for field width and precision (*
), which takes its value
from the next argument, is also supported. However, if a variable
field width or precision is encountered in a format spec that starts
with a positional argument spec, the "*" will be ignored and the
default value will be used instead.
Constructor Summary | |
PrintfFormat(java.util.Locale locale,
java.lang.String fmtArg)
Constructs an array of control specifications possibly preceded, separated, or followed by ordinary strings. |
|
PrintfFormat(java.lang.String fmtArg)
Constructs an array of control specifications possibly preceded, separated, or followed by ordinary strings. |
Method Summary | |
java.lang.String |
sprintf()
Format nothing. |
java.lang.String |
sprintf(double x)
Format a double. |
java.lang.String |
sprintf(int x)
Format an int. |
java.lang.String |
sprintf(long x)
Format a long. |
java.lang.String |
sprintf(java.lang.Object x)
Format an Object. |
java.lang.String |
sprintf(java.lang.Object[] o)
Format an array of objects. |
java.lang.String |
sprintf(java.lang.String x)
Format a String. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public PrintfFormat(java.lang.String fmtArg) throws java.lang.IllegalArgumentException
fmtArg
- Control string.
java.lang.IllegalArgumentException
- if the control
string is null, zero length, or otherwise
malformed.public PrintfFormat(java.util.Locale locale, java.lang.String fmtArg) throws java.lang.IllegalArgumentException
fmtArg
- Control string.
java.lang.IllegalArgumentException
- if the control
string is null, zero length, or otherwise malformed.Method Detail |
public java.lang.String sprintf(java.lang.Object[] o)
o
- The array of objects to format.
public java.lang.String sprintf()
public java.lang.String sprintf(int x) throws java.lang.IllegalArgumentException
x
- The int to format.
java.lang.IllegalArgumentException
- if the
conversion character is f, e, E, g, G, s,
or S.public java.lang.String sprintf(long x) throws java.lang.IllegalArgumentException
x
- The long to format.
java.lang.IllegalArgumentException
- if the
conversion character is f, e, E, g, G, s,
or S.public java.lang.String sprintf(double x) throws java.lang.IllegalArgumentException
x
- The double to format.
java.lang.IllegalArgumentException
- if the
conversion character is c, C, s, S,
d, d, x, X, or o.public java.lang.String sprintf(java.lang.String x) throws java.lang.IllegalArgumentException
x
- The String to format.
java.lang.IllegalArgumentException
- if the
conversion character is neither s nor S.public java.lang.String sprintf(java.lang.Object x) throws java.lang.IllegalArgumentException
x
- the Object to format.
java.lang.IllegalArgumentException
- if the
conversion character is inappropriate for
formatting an unwrapped value.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |