wasSharp – Diff between revs 29 and 30
?pathlinks?
Rev 29 | Rev 30 | |||
---|---|---|---|---|
Line 117... | Line 117... | |||
117 | /// </summary> |
117 | /// </summary> |
|
118 | /// <param name="path">the path to split</param> |
118 | /// <param name="path">the path to split</param> |
|
119 | /// <param name="separator">the separator character</param> |
119 | /// <param name="separator">the separator character</param> |
|
120 | /// <param name="escape">the escape character</param> |
120 | /// <param name="escape">the escape character</param> |
|
121 | /// <returns>path parts</returns> |
121 | /// <returns>path parts</returns> |
|
122 | public static IEnumerable<string> PathSplit(this string path, char separator, char? escape = null) |
122 | public static IEnumerable<string> PathSplit(this string path, char separator, char? escape = null, bool includeRootSeparator = true) |
|
123 | { |
123 | { |
|
124 | var s = new Stack<char>(); |
124 | var s = new Stack<char>(); |
|
125 | var p = new StringBuilder(); |
125 | var p = new StringBuilder(); |
|
126 | foreach (var c in path) |
126 | foreach (var c in path) |
|
127 | { |
127 | { |
|
Line 132... | Line 132... | |||
132 | } |
132 | } |
|
133 | if (c.Equals(separator)) |
133 | if (c.Equals(separator)) |
|
134 | { |
134 | { |
|
135 | if (s.Count.Equals(0) || !s.Peek().Equals(escape)) |
135 | if (s.Count.Equals(0) || !s.Peek().Equals(escape)) |
|
136 | { |
136 | { |
|
137 | if (p.Length.Equals(0)) |
137 | if (p.Length.Equals(0) && includeRootSeparator) |
|
138 | { |
138 | { |
|
139 | p.Append(c); |
139 | p.Append(c); |
|
140 | continue; |
140 | continue; |
|
141 | } |
141 | } |
|
142 | yield return p.ToString(); |
142 | yield return p.ToString(); |