csharp2colorized.cs
/// <summary>
/// Helper function: takes an load of words (with "null" representing a linebreak) and turns them into lines,
/// minimizing along the way by combining adjacent words of the same color
/// </summary>
Helper function: takes an load of words (with "null" representing a linebreak) and turns them into lines,
minimizing along the way by combining adjacent words of the same color
Helper function : takes an load of words ( with " null " representing a linebreak ) and turns them into lines minimizing along the way by combining adjacent words of the same color
public static IEnumerable<ColorizedLine> Words2Lines(IEnumerable<ColorizedWord> words)
        {
            var encounteredFirstLinebreak = false;
            var currentLine = new ColorizedLine();
            var currentWord = null as ColorizedWord;
            foreach (var nextWord in words)
            {
                if (nextWord == null) 
                {
                    if (currentWord != null)
                    {
                        currentWord.Text = currentWord.Text.TrimEnd();
                        if (!string.IsNullOrWhiteSpace(currentWord.Text)) currentLine.Words.Add(currentWord);
                    }
                    if (encounteredFirstLinebreak || currentLine.Words.Count > 0) yield return currentLine;
                    encounteredFirstLinebreak = true;
                    currentLine = new ColorizedLine();
                    currentWord = null;
                }
                else if (currentWord == null) 
                {
                    currentWord = nextWord;
                }
                else if (string.IsNullOrWhiteSpace(currentWord.Text)) 
                {
                    nextWord.Text = currentWord.Text + nextWord.Text;
                    currentWord = nextWord;
                }
                else if (string.IsNullOrWhiteSpace(nextWord.Text)) 
                {
                    currentWord.Text = currentWord.Text + nextWord.Text;
                }
                else if (currentWord.Red == nextWord.Red && currentWord.Green == nextWord.Green && currentWord.Blue == nextWord.Blue && currentWord.IsItalic == nextWord.IsItalic)
                {
                    currentWord.Text = currentWord.Text + nextWord.Text;
                }
                else
                {
                    currentLine.Words.Add(currentWord);
                    currentWord = nextWord;
                }
            }
            if (currentWord != null)
            {
                currentWord.Text = currentWord.Text.TrimEnd();
                if (!string.IsNullOrWhiteSpace(currentWord.Text)) currentLine.Words.Add(currentWord);
            }
            if (currentLine.Words.Count > 0) yield return currentLine;
        }
public static IEnumerable < ColorizedLine > Words2Lines ( IEnumerable < ColorizedWord > words ) { var encounteredFirstLinebreak = false ; var currentLine = new ColorizedLine ( ) ; var currentWord = null as ColorizedWord ; foreach ( var nextWord in words ) { if ( nextWord == null ) { if ( currentWord != null ) { currentWord . Text = currentWord . Text . TrimEnd ( ) ; if ( ! string . IsNullOrWhiteSpace ( currentWord . Text ) ) currentLine . Words . Add ( currentWord ) ; } if ( encounteredFirstLinebreak || currentLine . Words . Count > 0 ) yield return currentLine ; encounteredFirstLinebreak = true ; currentLine = new ColorizedLine ( ) ; currentWord = null ; } else if ( currentWord == null ) { currentWord = nextWord ; } else if ( string . IsNullOrWhiteSpace ( currentWord . Text ) ) { nextWord . Text = currentWord . Text + nextWord . Text ; currentWord = nextWord ; } else if ( string . IsNullOrWhiteSpace ( nextWord . Text ) ) { currentWord . Text = currentWord . Text + nextWord . Text ; } else if ( currentWord . Red == nextWord . Red && currentWord . Green == nextWord . Green && currentWord . Blue == nextWord . Blue && currentWord . IsItalic == nextWord . IsItalic ) { currentWord . Text = currentWord . Text + nextWord . Text ; } else { currentLine . Words . Add ( currentWord ) ; currentWord = nextWord ; } } if ( currentWord != null ) { currentWord . Text = currentWord . Text . TrimEnd ( ) ; if ( ! string . IsNullOrWhiteSpace ( currentWord . Text ) ) currentLine . Words . Add ( currentWord ) ; } if ( currentLine . Words . Count > 0 ) yield return currentLine ; }
Helper function: takes an load of words (with "null" representing a linebreak) and turns them into lines,
minimizing along the way by combining adjacent words of the same color
Helper function : takes an load of words ( with " null " representing a linebreak ) and turns them into lines minimizing along the way by combining adjacent words of the same color
// linebreak // first word on line // merge the currentWord into the new one // merge the word into the previous one
words
IEnumerable<ColorizedWord>