char ch;
int nDigits;
Pattern p = Pattern.compile("[#0,.]+");
Matcher m;
NumberNumberElement number;
/*
* If there is a numeric specifcation, then split the
* string into the part before the specifier, the specifier
* itself, and then part after the specifier. The parts
* before and after are just text (which may contain the
* currency symbol).
*/
m = p.matcher(format);
if (m.find()) {
preMatch = format.substring(0, m.start());
numberSpec = format.substring(m.start(), m.end());
postMatch = format.substring(m.end());
processText(preMatch, currencySymbol);
number = new NumberNumberElement((OdfFileDom) this.getOwnerDocument());
/* Process part before the decimal point (if any) */
nDigits = 0;
for (pos = 0; pos < numberSpec.length()
&& (ch = numberSpec.charAt(pos)) != '.'; pos++) {
if (ch == ',') {
number.setNumberGroupingAttribute(new Boolean(true));
} else if (ch == '0') {
nDigits++;
}
}
number.setNumberMinIntegerDigitsAttribute(nDigits);
/* Number of decimal places is the length after the decimal */
if (pos < numberSpec.length()) {
number.setNumberDecimalPlacesAttribute(numberSpec.length() - (pos + 1));
}
this.appendChild(number);
processText(postMatch, currencySymbol);
}