コード例 #1
0
        public void ReadWindowOfSizeExactlyEqualToWindowReadSizeAndSetPositionEqualToSize()
        {
            string s = new string('\n', SlidingWindowReader.WindowSize);

            SlidingWindowReader reader = new SlidingWindowReader(new StringReader(s));
            reader.PosCurrent = SlidingWindowReader.WindowSize;
        }
コード例 #2
0
ファイル: Scanner.cs プロジェクト: paulushub/SandAssists
        private void DoScan(SlidingWindowReader reader, ICodeFormatter formatter, bool writeAsynchronously)
        {
            ArgumentValidator.ThrowIfNull(formatter, "formatter");
            this.Reader = reader;

            if (this.m_isFirstRun)
            {
                this.m_scopeStack      = new List <Scope>(8);
                this.m_modes           = new List <KeyValuePair <int, HighlightMode> >(64);
                this.m_possibleKeyword = new StringBuilder(this.m_syntaxDefinition.MaxKeywordLength + 1);
                this.m_isFirstRun      = false;
            }
            else
            {
                this.m_scopeStack.Clear();
                this.m_modes.Clear();
                this.m_possibleKeyword.Length = 0;
            }

            this.m_pendingMatch = new MatchResult();
            this.m_pendingMatch.PosMatchStart = int.MaxValue;
            this.m_posDontMatchUntil          = -1;
            this.m_posAfterKeepend            = int.MaxValue;

            this.m_scopeStack.Add(Scope.BuildBackgroundScope(this.m_syntaxDefinition.MainContext.TopItems));
            this.BuildHighlightModes();

            this.m_outputWriter = new HighlightedOutputWriter(formatter, writeAsynchronously);
            this.LoadInputWindow(this.Reader.CurrentWindow);
            this.Vrooom();
        }
コード例 #3
0
ファイル: Scanner.cs プロジェクト: paulushub/SandAssists
        public void Scan(TextReader textReader, ICodeFormatter formatter)
        {
            ArgumentValidator.ThrowIfNull(textReader, "textReader");

            SlidingWindowReader reader = new SlidingWindowReader(textReader);

            reader.OnNewInputWindow += this.LoadInputWindow;

            this.DoScan(reader, formatter, true);
        }
コード例 #4
0
ファイル: Scanner.cs プロジェクト: svermeulen/iris
        private void DoScan(SlidingWindowReader reader, ICodeFormatter formatter, bool writeAsynchronously)
        {
            ArgumentValidator.ThrowIfNull(formatter, "formatter");
            this.Reader = reader;

            if (this.m_isFirstRun) {
                this.m_scopeStack = new List<Scope>(8);
                this.m_modes = new List<KeyValuePair<int, HighlightMode>>(64);
                this.m_possibleKeyword = new StringBuilder(this.m_syntaxDefinition.MaxKeywordLength + 1);
                this.m_isFirstRun = false;
            } else {
                this.m_scopeStack.Clear();
                this.m_modes.Clear();
                this.m_possibleKeyword.Length = 0;
            }

            this.m_pendingMatch = new MatchResult();
            this.m_pendingMatch.PosMatchStart = int.MaxValue;
            this.m_posDontMatchUntil = -1;
            this.m_posAfterKeepend = int.MaxValue;

            this.m_scopeStack.Add(Scope.BuildBackgroundScope(this.m_syntaxDefinition.MainContext.TopItems));
            this.BuildHighlightModes();

            this.m_outputWriter = new HighlightedOutputWriter(formatter, writeAsynchronously);
            this.LoadInputWindow(this.Reader.CurrentWindow);
            this.Vrooom();
        }
コード例 #5
0
ファイル: Scanner.cs プロジェクト: svermeulen/iris
        public void Scan(TextReader textReader, ICodeFormatter formatter)
        {
            ArgumentValidator.ThrowIfNull(textReader, "textReader");

            SlidingWindowReader reader = new SlidingWindowReader(textReader);
            reader.OnNewInputWindow += this.LoadInputWindow;

            this.DoScan(reader, formatter, true);
        }
コード例 #6
0
        public void TestNewLineDetection()
        {
            int cntChars = SlidingWindowReader.WindowSize*32;
            int cntLineEnds = 30000;

            StringBuilder sb = new StringBuilder(cntChars);
            sb.Append('t', cntChars-1);
            sb.Append('\n');

            bool[] idxLineEndsSeen = new bool[cntChars];

            Random r = new Random();

            for (int i = 0; i < cntLineEnds-1; ) {
                int idxNewLine = r.Next(0, cntChars - 1);

                if ('\n' == sb[idxNewLine]) {
                    continue;
                }

                sb[idxNewLine] = '\n';
                i++;
            }

            string s = sb.ToString();
            SlidingWindowReader reader = new SlidingWindowReader(new StringReader(s));

            VoidFunc<InputWindow> inspectLineEnds = delegate(InputWindow window) {
                for (int i = 0; i < window.IdxLineEnds.Length; i++) {
                    int idxLineEnd = window.IdxLineEnds[i];

                    Assert.AreEqual('\n', s[idxLineEnd], "Did not find expected new line at position " + idxLineEnd);
                    idxLineEndsSeen[idxLineEnd] = true;
                }
            };

            inspectLineEnds(reader.CurrentWindow);
            reader.OnNewInputWindow += inspectLineEnds;

            int cntLineEndsSeen = 0;

            for (int i = 0; i < cntChars; i++) {
                reader.PosCurrent = i;
                Assert.AreEqual(s[i], reader.CurrentWindow[i]);

                if ('\n' == s[i] && !idxLineEndsSeen[i]) {
                    Assert.Fail("Failed to detect line end at index " + i);
                }

                if (idxLineEndsSeen[i]) {
                    cntLineEndsSeen++;
                }
            }

            Assert.AreEqual(cntLineEnds, cntLineEndsSeen);
        }
コード例 #7
0
        private static void DoReadTestWithLargeSize(int cntChars)
        {
            StringBuilder sb = new StringBuilder(cntChars);

            Random r = new Random();

            for (int i = 0; i < cntChars - 1; i++) {
                if (3 == r.Next(1, 20)) {
                    sb.Append('\n');
                } else {
                    sb.Append((char)r.Next(33, 128));
                }
            }

            sb.Append('\n');

            string s = sb.ToString();

            SlidingWindowReader reader = new SlidingWindowReader(new StringReader(s));

            for (int i = 0; i < cntChars; i++) {
                Assert.AreEqual(s[i], reader.CurrentWindow[i], "difference at i = " + i);
                reader.PosCurrent = i;
            }
        }