using System.Text; namespace Microsoft.PowerShell { internal static class StringBuilderCharacterExtensions { /// /// Returns true if the character at the specified position is a visible whitespace character. /// A blank character is defined as a SPACE or a TAB. /// /// /// /// public static bool IsVisibleBlank(this StringBuilder buffer, int i) { var c = buffer[i]; // [:blank:] of vim's pattern matching behavior // defines blanks as SPACE and TAB characters. return c == ' ' || c == '\t'; } /// /// Returns true if the character at the specified position is /// not present in a list of word-delimiter characters. /// /// /// /// /// public static bool InWord(this StringBuilder buffer, int i, string wordDelimiters) { return Character.IsInWord(buffer[i], wordDelimiters); } /// /// Returns true if the character at the specified position is /// at the end of the buffer /// /// /// /// public static bool IsAtEndOfBuffer(this StringBuilder buffer, int i) { return i >= (buffer.Length - 1); } /// /// Returns true if the character at the specified position is /// a unicode whitespace character. /// /// /// /// public static bool IsWhiteSpace(this StringBuilder buffer, int i) { // Treat just beyond the end of buffer as whitespace because // it looks like whitespace to the user even though they haven't // entered a character yet. return i >= buffer.Length || char.IsWhiteSpace(buffer[i]); } } public static class Character { /// /// Returns true if the character not present in a list of word-delimiter characters. /// /// /// /// public static bool IsInWord(char c, string wordDelimiters) { return !char.IsWhiteSpace(c) && wordDelimiters.IndexOf(c) < 0; } } }