private void splitTokens(StringValueObject template, ref List <TokenBase> templateTokens) { TemplateTokenFactory ttf = TemplateTokenFactory.Instance; List <SplitElement> splitElements = SplitNonTokenizedElements(template.Value); foreach (SplitElement elem in splitElements) { if (elem.isFixedToken) { // Treat fixed tokens like constant strings between placeholders templateTokens.Add(ttf.createConstStringToken(elem.text)); } else { for (int curPos = 0; curPos < elem.text.Length;) { Match curMatch = PLACEHOLDER_REGEX.Match(elem.text, curPos); if (curMatch.Success && (curMatch.Length >= 2)) { // Constant string before placeholder templateTokens.Add(ttf.createConstStringToken( elem.text.Substring(curPos, curMatch.Index - curPos))); // Placeholder string between delimiters templateTokens.Add( ttf.createPlaceholderToken( elem.text.Substring(curMatch.Index + 1, curMatch.Length - 2), getGroupSeparator(), getDecimalSeparator() ) ); curPos = curMatch.Index + curMatch.Length; } else { // Constant string after last placeholder templateTokens.Add(ttf.createConstStringToken( elem.text.Substring(curPos))); curPos = elem.text.Length; } } } } }
private ValidationResult validateInternal(StringValueObject template, ref List <TokenBase> templateTokens, ref int binCount, ref int intCount, ref int numCount, ref int strCount, string language) { if ((!template.HasValue) || (template.Value.Length <= 0)) { return(new ValidationResult { HasError = true, Message = Localize(language, "EmptyTemplate") }); } TemplateTokenFactory ttf = TemplateTokenFactory.Instance; for (int curPos = 0; curPos < template.Value.Length;) { Match curMatch = PLACEHOLDER_REGEX.Match(template.Value, curPos); if (curMatch.Success && (curMatch.Length >= 2)) { // constant string before placeholder templateTokens.Add(ttf.createConstStringToken( template.Value.Substring(curPos, curMatch.Index - curPos))); // placeholder string between delimiters templateTokens.Add(ttf.createPlaceholderToken( template.Value.Substring(curMatch.Index + 1, curMatch.Length - 2))); curPos = curMatch.Index + curMatch.Length; } else { // constant string after last placeholder templateTokens.Add(ttf.createConstStringToken( template.Value.Substring(curPos))); curPos = template.Value.Length; } } ValidationResult result = validateNumberOfTokens(language, ref templateTokens); if (result.HasError) { return(result); } foreach (TokenBase token in templateTokens) { switch (token.getType()) { case TokenType.ConstString: case TokenType.VarReference: // nothing to do break; case TokenType.VarBoolean: binCount++; break; case TokenType.VarInteger: intCount++; break; case TokenType.VarNumber: numCount++; break; case TokenType.VarString: strCount++; break; case TokenType.Error: default: return(createTokenError(language, template.Name, token)); } } if (binCount > MAX_INPUTS) { return(new ValidationResult { HasError = true, Message = Localize(language, "TooManyBinPlaceholders") }); } if (intCount > MAX_INPUTS) { return(new ValidationResult { HasError = true, Message = Localize(language, "TooManyIntPlaceholders") }); } if (numCount > MAX_INPUTS) { return(new ValidationResult { HasError = true, Message = Localize(language, "TooManyNumPlaceholders") }); } if (strCount > MAX_INPUTS) { return(new ValidationResult { HasError = true, Message = Localize(language, "TooManyStrPlaceholders") }); } return(validateTokens(language, template.Name, ref templateTokens)); }