public override string DoFormating(string vhod) { string startTagStart = "[" + Name + "="; string endTag = String.Format(endF, Name); int start = vhod.Length; while ((start = vhod.IndexOf(startTagStart)) >= 0) { int startTagLength = vhod.Substring(start).IndexOf(']') + 1; int parameterLength = startTagLength - 1 - startTagStart.Length; int parameterStart = start + startTagStart.Length; string parameter = vhod.Substring(parameterStart, parameterLength); int end = vhod.IndexOf(endTag); if (end > vhod.Length) { throw new Exception("No closing tag for " + startTagStart); } int valueStart = start + startTagLength; int valueEnd = end - valueStart; int elementStart = start; int elementEnd = end + endTag.Length; string content = vhod.Substring(valueStart, valueEnd); Dictionary <string, string> parametri = new Dictionary <string, string>(); parametri.Add("parameter", parameter); parametri.Add("value", content); vhod = vhod.Substring(0, elementStart) + StartTag.Braces().NamedFormat(parametri) + EndTag.Braces().NamedFormat(parametri) + vhod.Substring(elementEnd); } return(vhod); }
public virtual string DoFormating(string vhod) { return (vhod .Replace(String.Format(startF, Name), StartTag.Braces()) .Replace(String.Format(endF, Name), EndTag.Braces())); }
public override string DoFormating(string vhod) { string sts = "[" + Name; int stsIndex = -1; string endTag = String.Format(endF, Name); while ((stsIndex = vhod.IndexOf(sts)) >= 0) { string formatedPart = vhod.Substring(0, stsIndex); string unformatedPart = vhod.Substring(stsIndex); int steIndex = unformatedPart.IndexOf("]"); int endTagIndex = unformatedPart.IndexOf(endTag); string paramString = unformatedPart.Substring(sts.Length, steIndex - sts.Length - 1); if (String.IsNullOrEmpty(paramString)) { throw new Exception("Ni parametrov"); } Dictionary <string, string> parametri = new Dictionary <string, string>(); foreach (string kvp in paramString.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)) { string[] parameter = kvp.Split('='); if (parameter.Length < 2) { throw new Exception("Invalid parameter format: " + kvp); } if (parameter[0].CompareTo("content") == 0) { throw new Exception("'content' can not be used as a parameter!"); } parametri.Add(parameter[0], parameter[1]); } parametri.Add("content", unformatedPart.Substring(steIndex + 1, endTagIndex - steIndex - 1)); string newEnd = EndTag.Braces(); vhod = formatedPart + StartTag.Braces().NamedFormat(parametri) + EndTag.Braces().NamedFormat(parametri) + unformatedPart.Substring(endTagIndex + endTag.Length); } return(vhod); }