public void NoCommentsWithinLiteralStrings() { // No comments within literal strings string src = " \"// /* */\" "; int[] exp = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; var com = new InComment(); for (int i = 0; i != src.Length; ++i) { Assert.Equal(exp[i], com.WithinComment(src, i) ? 1 : 0); } }
public void IgnoreLiteralStringsWithinComments() { // Ignore literal strings within comments string src = " /* \" */ // \" \n "; int[] exp = { 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0 }; var com = new InComment(); for (int i = 0; i != src.Length; ++i) { Assert.Equal(exp[i], com.WithinComment(src, i) ? 1 : 0); } }
public void LineCommentEndsAsEoS() { // Line comment ends at EOS string src = " // "; int[] exp = { 0, 1, 1, 1, 0 }; var com = new InComment(); for (int i = 0; i != src.Length; ++i) { Assert.Equal(exp[i], com.WithinComment(src, i) ? 1 : 0); } }
public void LineCommentEndsAtUnescapedNewLine() { // Line comment ends at unescaped new line (exclusive) string src = " // \\\n \n "; int[] exp = { 0, 1, 1, 1, 1, 1, 1, 0, 0, 0 }; var com = new InComment(); for (int i = 0; i != src.Length; ++i) { Assert.Equal(exp[i], com.WithinComment(src, i) ? 1 : 0); } }
public void NoSubstringMatchingWithinBlockCommentMarkers() { // No substring matching within block comment markers string src = "/*/*/ /**/*/"; int[] exp = { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0 }; var com = new InComment(); for (int i = 0; i != src.Length; ++i) { Assert.Equal(exp[i], com.WithinComment(src, i) ? 1 : 0); } }
public void SimpleBlockComment() { // Simple block comment string src = " /**/ "; int[] exp = { 0, 1, 1, 1, 1, 0 }; var com = new InComment(); for (int i = 0; i != src.Length; ++i) { Assert.Equal(exp[i], com.WithinComment(src, i) ? 1 : 0); } }
/// <summary>Return the next valid character from the underlying stream or '\0' for the end of stream.</summary> protected override int Read() { for (; m_src != '\0'; ++m_src) { // Eat comments var len = m_src.ReadAhead(8); if (m_com.WithinComment(m_src.Buffer.ToString(0, len), 0)) { continue; } break; } var ch = m_src.Peek; if (ch != '\0') { m_src.Next(); } return(ch); }