format = "1";
int headIndex = format.length();
ArrayList separators = new ArrayList();
IntArray zeroSizes = new IntArray();
IntArray formats = new IntArray();
CharBuffer cb = new CharBuffer();
int i = 0;
while (i < format.length()) {
char ch;
// scan the separator
cb.clear();
for (; i < format.length(); i++) {
ch = format.charAt(i);
if (Character.isLetterOrDigit(ch))
break;
cb.append(ch);
}
// head and tail separators are just sticked on the ends
if (head == null)
head = cb.toString();
else if (i >= format.length())
tail = cb.toString();
else
separators.add(cb.toString());
if (i >= format.length())
break;
// scan the format code
int zeroSize = 1;
int code = '0';
for (; i < format.length(); i++) {
ch = format.charAt(i);
if (! Character.isLetterOrDigit(ch))
break;
if (! Character.isDigit(ch)) {
if (code != '0' || zeroSize != 1)
code = 0;
else
code = ch;
}
else if (Character.digit(ch, 10) == 0 && zeroSize >= 0)
zeroSize++;
else if (Character.digit(ch, 10) == 1)
code = ch - 1;
else
code = 0;
}
if (code == 0)
code = '0';
zeroSizes.add(zeroSize);
formats.add(code);
}
// default format is '1'
if (formats.size() == 0) {
tail = head;
head = "";
formats.add('0');
zeroSizes.add(0);
}
// default separator is '.'
if (separators.size() == 0)
separators.add(".");
if (separators.size() < formats.size())
separators.add(separators.get(separators.size() - 1));
this.separators = (String []) separators.toArray(new String[separators.size()]);
this.zeroSize = zeroSizes.toArray();
this.formats = formats.toArray();
if (head == null)
head = "";
if (tail == null)
tail = "";