Beispiel #1
0
        public WordDock GetBlocks(string text)
        {
            var result = new WordDock
            {
                Blocks = new List <WordBlock>()
            };

            string txt;
            var    newline       = 0;
            var    stringBuilder = new StringBuilder();

            foreach (var ch in text)
            {
                if (newline > 1)
                {
                    // here we go to the next block
                    txt = stringBuilder.Remove(stringBuilder.Length - 2, 2).ToString();
                    CombineBlock(result, txt);

                    stringBuilder = new StringBuilder();
                }

                // new block starts after empty string
                if (ch == '\n')
                {
                    newline++;
                }
                else
                {
                    newline = 0;
                }

                stringBuilder.Append(ch);
            }

            txt = stringBuilder.ToString();
            CombineBlock(result, txt);

            return(result);
        }
Beispiel #2
0
        private void CombineBlock(WordDock dock, string txt)
        {
            var lines = GetLines(txt);

            var block = new WordBlock
            {
                Text  = txt,
                Lines = lines
            };

            // force deep dependency (helps a lot with inline generators)
            foreach (var line in lines)
            {
                foreach (var word in line.Words)
                {
                    word.Line  = line;
                    word.Block = block;
                    word.Dock  = dock;
                }
            }

            dock.Blocks.Add(block);
        }