Repository navigation
Expand file tree
/
Copy pathStringUtils.cs
More file actions
119 lines (113 loc) · 2.88 KB
/
Copy pathStringUtils.cs
File metadata and controls
119 lines (113 loc) · 2.88 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using System;
namespace antlr
{
/* ANTLR Translator Generator
* Project led by Terence Parr at http://www.jGuru.com
* Software rights: http://www.antlr.org/license.html
*
* $Id:$
*/
//
// ANTLR C# Code Generator by Micheal Jordan
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
// Anthony Oguntimehin
//
// With many thanks to Eric V. Smith from the ANTLR list.
//
internal class StringUtils
{
/*General-purpose utility function for removing
* characters from back of string
* @param s The string to process
* @param c The character to remove
* @return The resulting string
*/
static public string stripBack(string s, char c)
{
while (s.Length > 0 && s[s.Length - 1] == c)
{
s = s.Substring(0, (s.Length - 1) - (0));
}
return s;
}
/*General-purpose utility function for removing
* characters from back of string
* @param s The string to process
* @param remove A string containing the set of characters to remove
* @return The resulting string
*/
static public string stripBack(string s, string remove)
{
bool changed;
do
{
changed = false;
for (int i = 0; i < remove.Length; i++)
{
char c = remove[i];
while (s.Length > 0 && s[s.Length - 1] == c)
{
changed = true;
s = s.Substring(0, (s.Length - 1) - (0));
}
}
}
while (changed);
return s;
}
/*General-purpose utility function for removing
* characters from front of string
* @param s The string to process
* @param c The character to remove
* @return The resulting string
*/
static public string stripFront(string s, char c)
{
while (s.Length > 0 && s[0] == c)
{
s = s.Substring(1);
}
return s;
}
/*General-purpose utility function for removing
* characters from front of string
* @param s The string to process
* @param remove A string containing the set of characters to remove
* @return The resulting string
*/
static public string stripFront(string s, string remove)
{
bool changed;
do
{
changed = false;
for (int i = 0; i < remove.Length; i++)
{
char c = remove[i];
while (s.Length > 0 && s[0] == c)
{
changed = true;
s = s.Substring(1);
}
}
}
while (changed);
return s;
}
/*General-purpose utility function for removing
* characters from the front and back of string
* @param s The string to process
* @param head exact string to strip from head
* @param tail exact string to strip from tail
* @return The resulting string
*/
public static string stripFrontBack(string src, string head, string tail)
{
int h = src.IndexOf(head, StringComparison.Ordinal);
int t = src.LastIndexOf(tail, StringComparison.Ordinal);
if (h == - 1 || t == - 1)
return src;
return src.Substring(h + 1, (t) - (h + 1));
}
}
}