In This Article

Word Break Finder

While most languages use the same criteria for locating word breaks, some languages like may wish to include a @ character as the start of a word.

Basic Concepts

Word break finders are classes that implement IWordBreakFinder and navigate text to locate word breaks. The text/parsing framework includes a DefaultWordBreakFinder class that implements IWordBreakFinder using the most common word break finding logic that suits most languages fine.

When making a custom word break finder, the members of IWordBreakFinder must be implemented. The FindCurrentWordStart, FindCurrentWordEnd, FindPreviousWordStart, and FindNextWordStart methods each accept a TextSnapshotOffset that indicates the ITextSnapshot and offset within that snapshot at which to begin scanning. Those methods all return an integer indicating the offset within the same snapshot at which the appropriate word break was found.

Registering with a Language

Any object that implements IWordBreakFinder can be associated with a syntax language by registering it as an IWordBreakFinder service on the language.

The SyntaxLanguage class automatically registers a DefaultWordBreakFinder with itself when it is created, so normally word break finders never need to be set on a language unless a custom one is made.

This code creates a custom word break finder (defined in a make-believe CustomWordBreakFinder class) and registers it with the syntax language that is already declared in the language variable:

language.RegisterWordBreakFinder(new CustomWordBreakFinder());
Note

The SyntaxLanguageExtensions.RegisterWordBreakFinder method in the code snippet above is a helper extension method that gets added to ISyntaxLanguage objects when the ActiproSoftware.Text namespace is imported. See the Service Locator Architecture topic for details on registering and retrieving various service object instances, both via extension methods and generically, as there are some additional requirements for using the extension methods.