/// <summary> /// Reads a tag or object variable until the end sequence, <tt>%}</tt> or <tt>}}</tt> respectively and advances the enumerator position /// </summary> /// <param name="sb">The string builder</param> /// <param name="markupEnumerator">The string enumerator</param> /// <param name="initialSearchChars">The character set to search for</param> /// <exception cref="SyntaxException"></exception> private static void ReadToEnd(StringBuilder sb, DotLiquid.Util.CharEnumerator markupEnumerator, HashSet <char> initialSearchChars) { var searchChars = initialSearchChars; var isInQuotes = false; while (markupEnumerator.AppendNext(sb)) { char nextChar = markupEnumerator.Current; if (searchChars.Contains(nextChar)) { switch (nextChar) { case '\'': isInQuotes = !isInQuotes; searchChars = isInQuotes ? SearchSingleQuoteEnd : initialSearchChars; break; case '"': isInQuotes = !isInQuotes; searchChars = isInQuotes ? SearchDoubleQuoteEnd : initialSearchChars; break; case '}': case '%': if (markupEnumerator.Remaining > 0 && markupEnumerator.Next == '}') { markupEnumerator.AppendNext(sb); return; } break; } } } ; if (markupEnumerator.Remaining == 0) //Somehow we reached the end without finding the end character(s) { if (initialSearchChars == SearchQuoteOrTagEnd) { throw new SyntaxException(Liquid.ResourceManager.GetString("BlockTagNotTerminatedException"), sb.ToString(), Liquid.TagEnd); } else { throw new SyntaxException(Liquid.ResourceManager.GetString("BlockVariableNotTerminatedException"), sb.ToString(), Liquid.VariableEnd); } } }
/// <summary> /// Reads a fixed number of characters and advances the enumerator position /// </summary> /// <param name="markupEnumerator">The string enumerator</param> /// <param name="markupLength">The number of characters to read</param> /// <returns></returns> private static string ReadChars(DotLiquid.Util.CharEnumerator markupEnumerator, int markupLength) { var sb = new StringBuilder(markupLength); for (var i = 0; i < markupLength; i++) { markupEnumerator.AppendNext(sb); } return(sb.ToString()); }