* ConversionSpecification allows the formatting of
* a single primitive or object embedded within a
* string. The formatting is controlled by a
* format string. Only one Java primitive or
* object can be formatted at a time.
*
* A format string is a Java string that contains
* a control string. The control string starts at
* the first percent sign (%) in the string,
* provided that this percent sign
*
* The behavior is like printf. One (hopefully the
* only) exception is that the minimum number of
* exponent digits is 3 instead of 2 for e and E
* formats when the optional L is used before the
* e, E, g, or G conversion character. The
* optional L does not imply conversion to a long
* long double.
Method from net.bonzoun.cocodonkey.PrintfFormat$ConversionSpecification Detail: |
int getArgumentPosition() {
return argumentPosition;
}
|
int getArgumentPositionForFieldWidth() {
return argumentPositionForFieldWidth;
}
|
int getArgumentPositionForPrecision() {
return argumentPositionForPrecision;
}
|
char getConversionCharacter() {
return conversionCharacter;
}
* Get the conversion character that tells what
* type of control character this instance has.
*
* @return the conversion character. |
String getLiteral() {
StringBuffer sb=new StringBuffer();
int i=0;
while (i< fmt.length()) {
if (fmt.charAt(i)=='\\') {
i++;
if (i< fmt.length()) {
char c=fmt.charAt(i);
switch(c) {
case 'a':
sb.append((char)0x07);
break;
case 'b':
sb.append('\b');
break;
case 'f':
sb.append('\f');
break;
case 'n':
sb.append(System.getProperty("line.separator"));
break;
case 'r':
sb.append('\r');
break;
case 't':
sb.append('\t');
break;
case 'v':
sb.append((char)0x0b);
break;
case '\\':
sb.append('\\');
break;
}
i++;
}
else
sb.append('\\');
}
else
i++;
}
return fmt;
}
* Get the String for this instance. Translate
* any escape sequences.
*
* @return s the stored String. |
String internalsprintf(int s) throws IllegalArgumentException {
String s2 = "";
switch(conversionCharacter) {
case 'd':
case 'i':
if (optionalh)
s2 = printDFormat((short)s);
else if (optionall)
s2 = printDFormat((long)s);
else
s2 = printDFormat(s);
break;
case 'x':
case 'X':
if (optionalh)
s2 = printXFormat((short)s);
else if (optionall)
s2 = printXFormat((long)s);
else
s2 = printXFormat(s);
break;
case 'o':
if (optionalh)
s2 = printOFormat((short)s);
else if (optionall)
s2 = printOFormat((long)s);
else
s2 = printOFormat(s);
break;
case 'c':
case 'C':
s2 = printCFormat((char)s);
break;
default:
throw new IllegalArgumentException(
"Cannot format a int with a format using a "+
conversionCharacter+
" conversion character.");
}
return s2;
}
* Format an int argument using this conversion
* specification.
* @param s the int to format.
* @return the formatted String.
* @exception IllegalArgumentException if the
* conversion character is f, e, E, g, or G. |
String internalsprintf(long s) throws IllegalArgumentException {
String s2 = "";
switch(conversionCharacter) {
case 'd':
case 'i':
if (optionalh)
s2 = printDFormat((short)s);
else if (optionall)
s2 = printDFormat(s);
else
s2 = printDFormat((int)s);
break;
case 'x':
case 'X':
if (optionalh)
s2 = printXFormat((short)s);
else if (optionall)
s2 = printXFormat(s);
else
s2 = printXFormat((int)s);
break;
case 'o':
if (optionalh)
s2 = printOFormat((short)s);
else if (optionall)
s2 = printOFormat(s);
else
s2 = printOFormat((int)s);
break;
case 'c':
case 'C':
s2 = printCFormat((char)s);
break;
default:
throw new IllegalArgumentException(
"Cannot format a long with a format using a "+
conversionCharacter+" conversion character.");
}
return s2;
}
* Format a long argument using this conversion
* specification.
* @param s the long to format.
* @return the formatted String.
* @exception IllegalArgumentException if the
* conversion character is f, e, E, g, or G. |
String internalsprintf(double s) throws IllegalArgumentException {
String s2 = "";
switch(conversionCharacter) {
case 'f':
s2 = printFFormat(s);
break;
case 'E':
case 'e':
s2 = printEFormat(s);
break;
case 'G':
case 'g':
s2 = printGFormat(s);
break;
default:
throw new IllegalArgumentException("Cannot "+
"format a double with a format using a "+
conversionCharacter+" conversion character.");
}
return s2;
}
* Format a double argument using this conversion
* specification.
* @param s the double to format.
* @return the formatted String.
* @exception IllegalArgumentException if the
* conversion character is c, C, s, S, i, d,
* x, X, or o. |
String internalsprintf(String s) throws IllegalArgumentException {
String s2 = "";
if(conversionCharacter=='s'
|| conversionCharacter=='S')
s2 = printSFormat(s);
else
throw new IllegalArgumentException("Cannot "+
"format a String with a format using a "+
conversionCharacter+" conversion character.");
return s2;
}
* Format a String argument using this conversion
* specification.
* @param s the String to format.
* @return the formatted String.
* @exception IllegalArgumentException if the
* conversion character is neither s nor S. |
String internalsprintf(Object s) {
String s2 = "";
if(conversionCharacter=='s'
|| conversionCharacter=='S')
s2 = printSFormat(s.toString());
else
throw new IllegalArgumentException(
"Cannot format a String with a format using"+
" a "+conversionCharacter+
" conversion character.");
return s2;
}
* Format an Object argument using this conversion
* specification.
* @param s the Object to format.
* @return the formatted String.
* @exception IllegalArgumentException if the
* conversion character is neither s nor S. |
boolean isPositionalFieldWidth() {
return positionalFieldWidth;
}
|
boolean isPositionalPrecision() {
return positionalPrecision;
}
|
boolean isPositionalSpecification() {
return positionalSpecification;
}
|
boolean isVariableFieldWidth() {
return variableFieldWidth;
}
* Check whether the specifier has a variable
* field width that is going to be set by an
* argument.
* @return true if the conversion
* uses an * field width; otherwise
* false . |
boolean isVariablePrecision() {
return variablePrecision;
}
* Check whether the specifier has a variable
* precision that is going to be set by an
* argument.
* @return true if the conversion
* uses an * precision; otherwise
* false . |
void setFieldWidthWithArg(int fw) {
if (fw< 0) leftJustify = true;
fieldWidthSet = true;
fieldWidth = Math.abs(fw);
}
* Set the field width with an argument. A
* negative field width is taken as a - flag
* followed by a positive field width.
* @param fw the field width. |
void setLiteral(String s) {
fmt = s;
}
* Set the String for this instance.
* @param s the String to store. |
void setPrecisionWithArg(int pr) {
precisionSet = true;
precision = Math.max(pr,0);
}
* Set the precision with an argument. A
* negative precision will be changed to zero.
* @param pr the precision. |