public void Include(DefinedPlaceholder placeholder, ReplaceInfo[] replaceInfos) { while (__include(placeholder, replaceInfos)) { ; } }
public void Repeat(DefinedPlaceholder beginPlaceholder, DefinedPlaceholder endPlaceholder, ReplaceInfo[] replaceInfos) { while (__repeat(beginPlaceholder, endPlaceholder, replaceInfos, null)) { ; } }
private bool __repeat(DefinedPlaceholder beginPlaceholder, DefinedPlaceholder endPlaceholder, ReplaceInfo[] replaceInfos, string parameters) { string beginPlaceholderString = Placeholder.ToString(beginPlaceholder); string endPlaceholderString = Placeholder.ToString(endPlaceholder); string text = _text.ToString(); int beginIndex = text.IndexOf(beginPlaceholderString); int endIndex = text.IndexOf(endPlaceholderString); if (parameters != null) { beginPlaceholderString += "(" + parameters + ")"; } // something to do? if (beginIndex == -1 && endIndex == -1) { return(false); } if (beginIndex != -1 && endIndex == -1) { throw new CodeGeneratorException(ErrorCode.RepeaterBeginWithoutEnd, beginPlaceholderString); } if (endIndex != -1 && beginIndex == -1) { throw new CodeGeneratorException(ErrorCode.RepeaterEndWithoutStart, endPlaceholderString); } // yes! string repeatTemplate = GetRepeatTemplate(text, beginPlaceholderString, endPlaceholderString); string repeatResults = string.Empty; foreach (ReplaceInfo replaceInfo in replaceInfos) { if (replaceInfo.replaceInfos == null) { continue; } string includeResult = repeatTemplate; for (int i = 0; i < replaceInfo.replaceInfos.Length - 1; i += 2) { includeResult = includeResult.Replace(replaceInfo.replaceInfos[i], replaceInfo.replaceInfos[i + 1]); } repeatResults += includeResult; } // replace text = text.Remove(beginIndex, endIndex - beginIndex + endPlaceholderString.Length); text = text.Insert(beginIndex, repeatResults); _text = new StringBuilder(text); return(true); }
public void Repeat(DefinedPlaceholder beginPlaceholder, DefinedPlaceholder endPlaceholder, ReplaceInfo[] replaceInfos, string parameters) { while (__repeat(beginPlaceholder, endPlaceholder, replaceInfos, parameters)) { ; } }
private void OutputPlaceholder(DefinedPlaceholder placeholder, string value) { if (value == string.Empty) { _output(string.Format(" {0,-32}", Placeholder.ToString(placeholder))); } else { _output(string.Format(" {0,-32}: {1,-32}", Placeholder.ToString(placeholder), value)); } }
public void Repeat(DefinedPlaceholder beginPlaceholder, DefinedPlaceholder endPlaceholder, ReplaceInfo[] replaceInfos) { while (__repeat(beginPlaceholder, endPlaceholder, replaceInfos, null)); }
public void Repeat(DefinedPlaceholder beginPlaceholder, DefinedPlaceholder endPlaceholder, ReplaceInfo[] replaceInfos, string parameters) { while (__repeat(beginPlaceholder, endPlaceholder, replaceInfos, parameters)) ; }
public void Include(DefinedPlaceholder placeholder, ReplaceInfo[] replaceInfos) { while (__include(placeholder, replaceInfos)); }
private bool __repeat(DefinedPlaceholder beginPlaceholder, DefinedPlaceholder endPlaceholder, ReplaceInfo[] replaceInfos, string parameters) { string beginPlaceholderString = Placeholder.ToString(beginPlaceholder); string endPlaceholderString = Placeholder.ToString(endPlaceholder); string text = _text.ToString(); int beginIndex = text.IndexOf(beginPlaceholderString); int endIndex = text.IndexOf(endPlaceholderString); if (parameters != null) beginPlaceholderString += "(" + parameters + ")"; // something to do? if (beginIndex == -1 && endIndex == -1) return false; if (beginIndex != -1 && endIndex == -1) throw new CodeGeneratorException(ErrorCode.RepeaterBeginWithoutEnd, beginPlaceholderString); if (endIndex != -1 && beginIndex == -1) throw new CodeGeneratorException(ErrorCode.RepeaterEndWithoutStart, endPlaceholderString); // yes! string repeatTemplate = GetRepeatTemplate(text, beginPlaceholderString, endPlaceholderString); string repeatResults = string.Empty; foreach (ReplaceInfo replaceInfo in replaceInfos) { if (replaceInfo.replaceInfos == null) continue; string includeResult = repeatTemplate; for (int i = 0; i < replaceInfo.replaceInfos.Length - 1; i += 2) includeResult = includeResult.Replace(replaceInfo.replaceInfos[i], replaceInfo.replaceInfos[i + 1]); repeatResults += includeResult; } // replace text = text.Remove(beginIndex, endIndex-beginIndex+endPlaceholderString.Length); text = text.Insert(beginIndex, repeatResults); _text = new StringBuilder(text); return true; }
private bool __include(DefinedPlaceholder placeholder, ReplaceInfo[] replaceInfos) { string placeholderString = Placeholder.ToString(placeholder); string text = _text.ToString(); int startIndex = text.IndexOf(placeholderString); // something to do? if (startIndex == -1) return false; // yes! int length = placeholderString.Length; int endIndex = startIndex + length; // get include placeholder + filename $NAME$(filename) if (text[endIndex] != '(') throw new CodeGeneratorException(ErrorCode.InvalidIncludeTemplateFormatOpeningBracket, placeholderString); do { if (endIndex+1 == text.Length) throw new CodeGeneratorException(ErrorCode.InvalidIncludeTemplateFormatClosingBracket, placeholderString); endIndex++; length++; if (text[endIndex] == ')') { endIndex++; length++; break; } } while (true); // get template from include string includePlaceholderPlusFilename = text.Substring(startIndex, length); string includeTemplate = GetIncludeTemplate(placeholderString, includePlaceholderPlusFilename); // replace string includeResults = string.Empty; foreach (ReplaceInfo replaceInfo in replaceInfos) { if (replaceInfo.replaceInfos == null) continue; string includeResult = includeTemplate; for (int i=0; i<replaceInfo.replaceInfos.Length-1; i+=2) includeResult = includeResult.Replace(replaceInfo.replaceInfos[i], replaceInfo.replaceInfos[i+1]); includeResults += includeResult; } text = text.Replace(includePlaceholderPlusFilename, includeResults); _text = new StringBuilder(text); return true; }
private void OutputPlaceholder(DefinedPlaceholder placeholder, string value) { if (value == string.Empty) _output(string.Format(" {0,-32}", Placeholder.ToString(placeholder))); else _output(string.Format(" {0,-32}: {1,-32}", Placeholder.ToString(placeholder), value)); }
private string Replace(string text, DefinedPlaceholder placeholder, string newText) { string replaceText = Placeholder.ToString(placeholder); return(text.Replace(replaceText, newText)); }
private bool __include(DefinedPlaceholder placeholder, ReplaceInfo[] replaceInfos) { string placeholderString = Placeholder.ToString(placeholder); string text = _text.ToString(); int startIndex = text.IndexOf(placeholderString); // something to do? if (startIndex == -1) { return(false); } // yes! int length = placeholderString.Length; int endIndex = startIndex + length; // get include placeholder + filename $NAME$(filename) if (text[endIndex] != '(') { throw new CodeGeneratorException(ErrorCode.InvalidIncludeTemplateFormatOpeningBracket, placeholderString); } do { if (endIndex + 1 == text.Length) { throw new CodeGeneratorException(ErrorCode.InvalidIncludeTemplateFormatClosingBracket, placeholderString); } endIndex++; length++; if (text[endIndex] == ')') { endIndex++; length++; break; } }while (true); // get template from include string includePlaceholderPlusFilename = text.Substring(startIndex, length); string includeTemplate = GetIncludeTemplate(placeholderString, includePlaceholderPlusFilename); // replace string includeResults = string.Empty; foreach (ReplaceInfo replaceInfo in replaceInfos) { if (replaceInfo.replaceInfos == null) { continue; } string includeResult = includeTemplate; for (int i = 0; i < replaceInfo.replaceInfos.Length - 1; i += 2) { includeResult = includeResult.Replace(replaceInfo.replaceInfos[i], replaceInfo.replaceInfos[i + 1]); } includeResults += includeResult; } text = text.Replace(includePlaceholderPlusFilename, includeResults); _text = new StringBuilder(text); return(true); }
public void Replace(DefinedPlaceholder placeholder, string newText) { _text.Replace(Placeholder.ToString(placeholder), newText); }
public void Replace(DefinedPlaceholder placeholder, string newText) { _text.Replace(Placeholder.ToString(placeholder), newText); }
private void OutputPlaceholder(DefinedPlaceholder placeholder) { OutputPlaceholder(placeholder, string.Empty); }
public static string ToString(DefinedPlaceholder placeholder) { return(s_prefix + placeholder.ToString() + s_postfix); }
private string Replace(string text, DefinedPlaceholder placeholder, string newText) { string replaceText = Placeholder.ToString(placeholder); return text.Replace(replaceText, newText); }
private void OutputPlaceholder(DefinedPlaceholder placeholder) { OutputPlaceholder(placeholder, string.Empty); }
public static string ToString(DefinedPlaceholder placeholder) { return s_prefix + placeholder.ToString() + s_postfix; }