public NumberFormatter(string formatString, int lang, string letterValue, string groupingSeparator, int groupingSize) {
Debug.Assert(groupingSeparator.Length <= 1);
this.formatString = formatString;
this.lang = lang;
this.letterValue = letterValue;
this.groupingSeparator = groupingSeparator;
this.groupingSize = groupingSeparator.Length > 0 ? groupingSize : 0;
if (formatString == "1" || formatString.Length == 0) {
// Special case of the default format
return;
}
this.tokens = new List<TokenInfo>();
int idxStart = 0;
bool isAlphaNumeric = CharUtil.IsAlphaNumeric(formatString[idxStart]);
if (isAlphaNumeric) {
// If the first one is alpha num add empty separator as a prefix
tokens.Add(null);
}
for (int idx = 0; idx <= formatString.Length; idx++) {
// Loop until a switch from formatString token to separator is detected (or vice-versa)
if (idx == formatString.Length || isAlphaNumeric != CharUtil.IsAlphaNumeric(formatString[idx])) {
if (isAlphaNumeric) {
// Just finished a format token
tokens.Add(TokenInfo.CreateFormat(formatString, idxStart, idx - idxStart));
} else {
// Just finished a separator token
tokens.Add(TokenInfo.CreateSeparator(formatString, idxStart, idx - idxStart));
}
// Begin parsing the next format token or separator
idxStart = idx;
// Flip flag from format token to separator or vice-versa
isAlphaNumeric = !isAlphaNumeric;
}
}
}