|
| 1 | +using System.Text; |
| 2 | + |
| 3 | +namespace Microsoft.PowerShell |
| 4 | +{ |
| 5 | + internal static partial class StringBuilderExtensions |
| 6 | + { |
| 7 | + /// <summary> |
| 8 | + /// Returns true if the character at the specified position is a visible whitespace character. |
| 9 | + /// A blank character is defined as a SPACE or a TAB. |
| 10 | + /// </summary> |
| 11 | + /// <param name="buffer"></param> |
| 12 | + /// <param name="i"></param> |
| 13 | + /// <returns></returns> |
| 14 | + public static bool IsVisibleBlank(this StringBuilder buffer, int i) |
| 15 | + { |
| 16 | + var c = buffer[i]; |
| 17 | + |
| 18 | + // [:blank:] of vim's pattern matching behavior |
| 19 | + // defines blanks as SPACE and TAB characters. |
| 20 | + |
| 21 | + return c == ' ' || c == '\t'; |
| 22 | + } |
| 23 | + |
| 24 | + /// <summary> |
| 25 | + /// Returns true if the character at the specified position is |
| 26 | + /// not present in a list of word-delimiter characters. |
| 27 | + /// </summary> |
| 28 | + /// <param name="buffer"></param> |
| 29 | + /// <param name="i"></param> |
| 30 | + /// <param name="wordDelimiters"></param> |
| 31 | + /// <returns></returns> |
| 32 | + public static bool InWord(this StringBuilder buffer, int i, string wordDelimiters) |
| 33 | + { |
| 34 | + return Character.IsInWord(buffer[i], wordDelimiters); |
| 35 | + } |
| 36 | + |
| 37 | + /// <summary> |
| 38 | + /// Returns true if the character at the specified position is |
| 39 | + /// a unicode whitespace character. |
| 40 | + /// </summary> |
| 41 | + /// <param name="buffer"></param> |
| 42 | + /// <param name="i"></param> |
| 43 | + /// <returns></returns> |
| 44 | + public static bool IsWhiteSpace(this StringBuilder buffer, int i) |
| 45 | + { |
| 46 | + // Treat just beyond the end of buffer as whitespace because |
| 47 | + // it looks like whitespace to the user even though they haven't |
| 48 | + // entered a character yet. |
| 49 | + return i >= buffer.Length || char.IsWhiteSpace(buffer[i]); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + public static class Character |
| 54 | + { |
| 55 | + /// <summary> |
| 56 | + /// Returns true if the character not present in a list of word-delimiter characters. |
| 57 | + /// </summary> |
| 58 | + /// <param name="c"></param> |
| 59 | + /// <param name="wordDelimiters"></param> |
| 60 | + /// <returns></returns> |
| 61 | + public static bool IsInWord(char c, string wordDelimiters) |
| 62 | + { |
| 63 | + return !char.IsWhiteSpace(c) && wordDelimiters.IndexOf(c) < 0; |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments