コード例 #1
0
        private static string FormatInstructions(SplitWord splitWord)
        {
            var output = string.Empty;
            if (splitWord.PrefixInstructions.Any())
                output += ">" + FormatInstructions(splitWord.PrefixInstructions);

            if (splitWord.SuffixInstructions.Any())
                output += "<" + FormatInstructions(splitWord.SuffixInstructions);

            return output;
        }
コード例 #2
0
        private string Analyse(string source, SplitWord[] split)
        {
            var sb = new StringBuilder();
            sb.AppendLine("Original:");
            sb.AppendLine(source);
            sb.AppendLine();
            sb.AppendLine("Split:");
            sb.AppendLine(DescribeWords(split));
            sb.AppendLine();
            sb.AppendLine("Reconstituted:");
            var reconstituted = Reconstitute(split);
            sb.AppendLine(reconstituted);

            var reSplit = WordSplitter.Split(reconstituted, 4);
            sb.AppendLine();
            sb.AppendLine("Re-split:");
            sb.AppendLine(DescribeWords(reSplit));

            return sb.ToString();
        }
コード例 #3
0
 private void StoreCurrentIfPresent()
 {
     if (_current != null)
     {
         Words.Add(_current);
         _current = null;
     }
 }
コード例 #4
0
        private string Reconstitute(SplitWord[] split)
        {
            var sb = new StringBuilder();

            foreach (var splitWord in split)
            {
                sb.Append(ColourInstructionRebuilder.Rebuild(AdapterConfiguration.PrefixAffinity,
                    splitWord.PrefixInstructions.ToList()));
                sb.Append(splitWord.WordValue);
                sb.Append(ColourInstructionRebuilder.Rebuild(AdapterConfiguration.SuffixAffinity,
                    splitWord.SuffixInstructions.ToList()));
            }

            return sb.ToString();
        }
コード例 #5
0
            private void ProcessColourControlItem(ColourControlItem colourControlItem)
            {
                if (colourControlItem.PrefixAffinity && string.IsNullOrEmpty(colourControlItem.Text))
                {
                    _cachedPrefixInstructions.AddRange(colourControlItem.Instructions);

                    StoreCurrentIfPresent();
                    return;
                }

                if (!string.IsNullOrEmpty(colourControlItem.Text))
                {
                    StoreCurrentIfPresent();

                    var splitWords = SplitWords(colourControlItem.Text, _tabLength);
                    if (splitWords.Any())
                    {
                        splitWords.First().AddPrefixInstructions(_cachedPrefixInstructions);
                        _cachedPrefixInstructions.Clear();
                    }

                    if (splitWords.Length > 1)
                        Words.AddRange(splitWords.Take(splitWords.Length - 1));

                    _current = splitWords[splitWords.Length - 1];
                }
                else if (InstructionIsNewLineOnly(colourControlItem))
                {
                    StoreCurrentIfPresent();
                    _current = new SplitWord(0, 0, string.Empty);
                    _current.AddPrefixInstructions(_cachedPrefixInstructions);
                    _current.AddSuffixInstructions(colourControlItem.Instructions);
                    _cachedPrefixInstructions.Clear();
                }
                else
                    AddSuffixInstructionsToCurrent(colourControlItem.Instructions);
            }
コード例 #6
0
            private void InitFromColourControlItems(IEnumerable<ColourControlItem> items)
            {
                foreach (var colourControlItem in items)
                {
                    ProcessColourControlItem(colourControlItem);
                }
                StoreCurrentIfPresent();

                if (_cachedPrefixInstructions.Any())
                {
                    var lastWord = new SplitWord(0, 0, string.Empty);
                    lastWord.AddPrefixInstructions(_cachedPrefixInstructions);
                    Words.Add(lastWord);
                }
            }
コード例 #7
0
            private void AddSuffixInstructionsToCurrent(List<ColourControlItem.ControlInstruction> instructions)
            {
                if (_current == null)
                {
                    _current = new SplitWord(0, 0, string.Empty);
                    _current.AddPrefixInstructions(_cachedPrefixInstructions);
                    _cachedPrefixInstructions.Clear();
                }

                _current.AddSuffixInstructions(instructions);
            }
コード例 #8
0
 public SplitImpl(IEnumerable<ColourControlItem> data, int tabLength)
 {
     _tabLength = tabLength;
     _current = null;
     InitFromColourControlItems(data);
 }
コード例 #9
0
 public SplitImpl(string data, int tabLength)
 {
     _tabLength = tabLength;
     var items = ColourControlSplitter.Split(data);
     _current = null;
     InitFromColourControlItems(items);
 }