[]
        
(Showing Draft Content)

C1.WPF.SpellChecker.C1SpellChecker.CustomParser

CustomParser Property

CustomParser

Gets or sets a custom spell-checking parser.

Declaration
public ISpellParser CustomParser { get; set; }
Remarks
<p>This property allows you to specify a custom parser for breaking up 

text into words to be spell-checked.

For example, you may want to use a custom parser when checking source code files. This way you can spell-check the comments in the code and skip the actual code.

Examples

The class below implements a custom parser that breaks words that contain underscores or mixed case into separate words. For example, this parser would treat "Customer_Code" or "CustomerCode" as two separate words.

public class Parser : C1.Win.C1SpellChecker.ISpellParser
{
  CharRange ISpellParser.GetNextWord(string text, int start, IgnoreOptions ignore, string previousWord)
  {
    // start with default implementation
    CharRange range = CharRange.GetNextWord(text, start, ignore, previousWord);

    // additional logic to handle underscores and mixed-case
    if (range != null)
    {
      // get original word
      string word = range.Text;

      // split word at underscores
      int index = word.IndexOf('_');
      if (index > -1)
      {
        word = word.Substring(0, index);
        range = new CharRange(word, range.Start, word == previousWord);
      }

      // split MixedCasedWords
      for (int i = 1; i < word.Length; i++)
      {
        if (char.IsUpper(word[i]) && char.IsLower(word[i - 1]))
        {
          word = word.Substring(0, i);
          range = new CharRange(word, range.Start, word == previousWord);
        }
      }
    }

    // done
    return range;
  }
  string ISpellParser.FilterWord(string word)
  {
    return word;
  }
}