com.caucho.util
Class Sprintf

java.lang.Object
  extended by com.caucho.util.Sprintf

public class Sprintf
extends java.lang.Object


Constructor Summary
Sprintf()
           
 
Method Summary
static void formatChar(CharBuffer cb, long ch, int width, int flags)
           
static void formatDouble(CharBuffer cb, double value, int prec, int flags, int type)
           
static void formatDouble(CharBuffer cb, double value, int width, int prec, int flags, int type)
           
static void formatInteger(CharBuffer cb, double dvalue, int width, int prec, int flags, int radix)
           
static void formatInteger(CharBuffer cb, long dvalue, int width, int prec, int flags, int radix)
           
static void formatString(CharBuffer cb, java.lang.String string, int prec, int width, int flags)
           
static CharBuffer sprintf(CharBuffer result, java.lang.String format, java.lang.Object... args)
           
static java.lang.String sprintf(java.lang.String format, java.lang.Object arg0)
           
static java.lang.String sprintf(java.lang.String format, java.lang.Object[] args)
          An implementation of the classic sprintf.
static java.lang.String sprintf(java.lang.String format, java.lang.Object arg0, java.lang.Object arg1)
           
static java.lang.String sprintf(java.lang.String format, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2)
           
static java.lang.String sprintf(java.lang.String format, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3)
           
static java.lang.String sprintf(java.lang.String format, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4)
           
static java.lang.String sprintf(java.lang.String format, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4, java.lang.Object arg5)
           
static java.lang.String sprintf(java.lang.String format, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4, java.lang.Object arg5, java.lang.Object arg6)
           
static java.lang.String sprintf(java.lang.String format, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4, java.lang.Object arg5, java.lang.Object arg6, java.lang.Object arg7)
           
static java.lang.String sprintf(java.lang.String format, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4, java.lang.Object arg5, java.lang.Object arg6, java.lang.Object arg7, java.lang.Object arg8)
           
static java.lang.String sprintf(java.lang.String format, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4, java.lang.Object arg5, java.lang.Object arg6, java.lang.Object arg7, java.lang.Object arg8, java.lang.Object arg9)
           
static double toDouble(java.lang.Object value)
          Converts some unknown value to a double.
static long toLong(java.lang.Object value)
          Converts some unknown value to a long.
static java.lang.String toString(java.lang.Object value, java.lang.String nullValue)
          Converts some unknown value to a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Sprintf

public Sprintf()
Method Detail

sprintf

public static java.lang.String sprintf(java.lang.String format,
                                       java.lang.Object[] args)
An implementation of the classic sprintf.

`sprintf' accepts a series of arguments, applies to each a format specifier from `format', and returns the formatted data as a string. `format' is a string containing two types of objects: ordinary characters (other than `%'), which are copied unchanged to the output, and conversion specifications, each of which is introduced by `%'. (To include `%' in the output, use `%%' in the format string).

A conversion specification has the following form:

%[FLAGS][WIDTH][.PREC][TYPE]
TYPE is required, the rest are optional. The following TYPE's are supported:
%%a percent sign
%ca character with the given number
%sa string, a null string becomes "#null"
%za string, a null string becomes the empty string ""
%da signed integer, in decimal
%oan integer, in octal
%uan integer, in decimal
%xan integer, in hexadecimal
%Xan integer, in hexadecimal using upper-case letters
%ea floating-point number, in scientific notation
%Ea floating-point number, like %e with an upper-case "E"
%fa floating-point number, in fixed decimal notation
%ga floating-point number, in %e or %f notation
%Ga floating-point number, like %g with an upper-case "E"
%pa pointer (outputs a value like the default of toString())
Intepret the word `integer' to mean the java type long. Since java does not support unsigned integers, all integers are treated the same.

The following optional FLAGS are supported:

0If the TYPE character is an integer leading zeroes are used to pad the field width instead of spaces (following any indication of sign or base).
+Include a `+' with positive numbers.
(a space)use a space placeholder for the `+' that would result from a positive number
-The result of is left justified, and the right is padded with blanks until the result is `WIDTH' in length. If you do not use this flag, the result is right justified, and padded on the left.
#an alternate display is used, for `x' and `X' a non-zero result will have an "0x" prefix; for floating point numbers the result will always contain a decimal point.
jescape a string suitable for a Java string, or a CSV file. The following escapes are applied: " becomes \", newline becomes \n, return becomes \r, \ becomes \\.
vescape a string suitable for CSV files, the same as `j' with an additional " placed at the beginning and ending of the string
mescape a string suitable for a XML file. The following escapes are applied: < becomes &lt;, > becomes &gt; & becomes &amp; ' becomes &#039, " becomes &034;
The optional WIDTH argument specifies a minium width for the field. Spaces are used unless the `0' FLAG was used to indicate 0 padding.

The optional PREC argument is introduced with a `.', and gives the maximum number of characters to print; or the minimum number of digits to print for integer and hex values; or the maximum number of significant digits for `g' and `G'; or the number of digits to print after the decimal point for floating points.


sprintf

public static java.lang.String sprintf(java.lang.String format,
                                       java.lang.Object arg0,
                                       java.lang.Object arg1,
                                       java.lang.Object arg2,
                                       java.lang.Object arg3,
                                       java.lang.Object arg4,
                                       java.lang.Object arg5,
                                       java.lang.Object arg6,
                                       java.lang.Object arg7,
                                       java.lang.Object arg8,
                                       java.lang.Object arg9)

sprintf

public static java.lang.String sprintf(java.lang.String format,
                                       java.lang.Object arg0,
                                       java.lang.Object arg1,
                                       java.lang.Object arg2,
                                       java.lang.Object arg3,
                                       java.lang.Object arg4,
                                       java.lang.Object arg5,
                                       java.lang.Object arg6,
                                       java.lang.Object arg7,
                                       java.lang.Object arg8)

sprintf

public static java.lang.String sprintf(java.lang.String format,
                                       java.lang.Object arg0,
                                       java.lang.Object arg1,
                                       java.lang.Object arg2,
                                       java.lang.Object arg3,
                                       java.lang.Object arg4,
                                       java.lang.Object arg5,
                                       java.lang.Object arg6,
                                       java.lang.Object arg7)

sprintf

public static java.lang.String sprintf(java.lang.String format,
                                       java.lang.Object arg0,
                                       java.lang.Object arg1,
                                       java.lang.Object arg2,
                                       java.lang.Object arg3,
                                       java.lang.Object arg4,
                                       java.lang.Object arg5,
                                       java.lang.Object arg6)

sprintf

public static java.lang.String sprintf(java.lang.String format,
                                       java.lang.Object arg0,
                                       java.lang.Object arg1,
                                       java.lang.Object arg2,
                                       java.lang.Object arg3,
                                       java.lang.Object arg4,
                                       java.lang.Object arg5)

sprintf

public static java.lang.String sprintf(java.lang.String format,
                                       java.lang.Object arg0,
                                       java.lang.Object arg1,
                                       java.lang.Object arg2,
                                       java.lang.Object arg3,
                                       java.lang.Object arg4)

sprintf

public static java.lang.String sprintf(java.lang.String format,
                                       java.lang.Object arg0,
                                       java.lang.Object arg1,
                                       java.lang.Object arg2,
                                       java.lang.Object arg3)

sprintf

public static java.lang.String sprintf(java.lang.String format,
                                       java.lang.Object arg0,
                                       java.lang.Object arg1,
                                       java.lang.Object arg2)

sprintf

public static java.lang.String sprintf(java.lang.String format,
                                       java.lang.Object arg0,
                                       java.lang.Object arg1)

sprintf

public static java.lang.String sprintf(java.lang.String format,
                                       java.lang.Object arg0)

sprintf

public static CharBuffer sprintf(CharBuffer result,
                                 java.lang.String format,
                                 java.lang.Object... args)

formatDouble

public static void formatDouble(CharBuffer cb,
                                double value,
                                int prec,
                                int flags,
                                int type)

formatDouble

public static void formatDouble(CharBuffer cb,
                                double value,
                                int width,
                                int prec,
                                int flags,
                                int type)

formatInteger

public static void formatInteger(CharBuffer cb,
                                 long dvalue,
                                 int width,
                                 int prec,
                                 int flags,
                                 int radix)

formatInteger

public static void formatInteger(CharBuffer cb,
                                 double dvalue,
                                 int width,
                                 int prec,
                                 int flags,
                                 int radix)

formatChar

public static void formatChar(CharBuffer cb,
                              long ch,
                              int width,
                              int flags)

formatString

public static void formatString(CharBuffer cb,
                                java.lang.String string,
                                int prec,
                                int width,
                                int flags)

toDouble

public static double toDouble(java.lang.Object value)
Converts some unknown value to a double.

Parameters:
value - the value to be converted.
Returns:
the double-converted value.

toLong

public static long toLong(java.lang.Object value)
Converts some unknown value to a long.

Parameters:
value - the value to be converted.
Returns:
the long-converted value.

toString

public static java.lang.String toString(java.lang.Object value,
                                        java.lang.String nullValue)
Converts some unknown value to a String.

Parameters:
value - the value to be converted.
nullValue - the value to return if value == null
Returns:
the String converted value