-
Notifications
You must be signed in to change notification settings - Fork 322
Expand file tree
/
Copy pathStringBuilderCharacterExtensions.cs
More file actions
78 lines (71 loc) · 2.7 KB
/
StringBuilderCharacterExtensions.cs
File metadata and controls
78 lines (71 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System.Text;
namespace Microsoft.PowerShell
{
internal static class StringBuilderCharacterExtensions
{
/// <summary>
/// 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.
/// </summary>
/// <param name="buffer"></param>
/// <param name="i"></param>
/// <returns></returns>
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';
}
/// <summary>
/// Returns true if the character at the specified position is
/// not present in a list of word-delimiter characters.
/// </summary>
/// <param name="buffer"></param>
/// <param name="i"></param>
/// <param name="wordDelimiters"></param>
/// <returns></returns>
public static bool InWord(this StringBuilder buffer, int i, string wordDelimiters)
{
return Character.IsInWord(buffer[i], wordDelimiters);
}
/// <summary>
/// Returns true if the character at the specified position is
/// at the end of the buffer
/// </summary>
/// <param name="buffer"></param>
/// <param name="i"></param>
/// <returns></returns>
public static bool IsAtEndOfBuffer(this StringBuilder buffer, int i)
{
return i >= (buffer.Length - 1);
}
/// <summary>
/// Returns true if the character at the specified position is
/// a unicode whitespace character.
/// </summary>
/// <param name="buffer"></param>
/// <param name="i"></param>
/// <returns></returns>
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
{
/// <summary>
/// Returns true if the character not present in a list of word-delimiter characters.
/// </summary>
/// <param name="c"></param>
/// <param name="wordDelimiters"></param>
/// <returns></returns>
public static bool IsInWord(char c, string wordDelimiters)
{
return !char.IsWhiteSpace(c) && wordDelimiters.IndexOf(c) < 0;
}
}
}