wasSharp – Blame information for rev 7

Subversion Repositories:
Rev:
Rev Author Line No. Line
7 office 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2013 - License: GNU GPLv3 //
3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
4 // rights of fair usage, the disclaimer and warranty conditions. //
5 ///////////////////////////////////////////////////////////////////////////
6  
7 using System.Collections.Generic;
8 using System.IO;
9 using System.Linq;
10 using System.Runtime.InteropServices;
11 using System.Text;
12  
13 namespace wasSharp
14 {
15 public static class IO
16 {
17 ///////////////////////////////////////////////////////////////////////////
18 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
19 ///////////////////////////////////////////////////////////////////////////
20 /// <summary>
21 /// Combine multiple paths.
22 /// </summary>
23 /// <param name="paths">an array of paths</param>
24 /// <returns>a combined path</returns>
25 public static string PathCombine(params string[] paths)
26 {
27 return paths.Aggregate((x, y) => Path.Combine(x, y));
28 }
29  
30 /// <summary>
31 /// Strip characters that are incompatible with file names.
32 /// </summary>
33 /// <param name="fileName">the name of the file</param>
34 /// <returns>a clean string</returns>
35 private static string CleanFileName(string fileName)
36 {
37 return Path.GetInvalidFileNameChars()
38 .Aggregate(fileName, (current, c) => current.Replace(c.ToString(), string.Empty));
39 }
40  
41 ///////////////////////////////////////////////////////////////////////////
42 // Copyright (C) 2016 Wizardry and Steamworks - License: GNU GPLv3 //
43 ///////////////////////////////////////////////////////////////////////////
44 /// <summary>
45 /// Splits a path using a separator and an escape character.
46 /// </summary>
47 /// <param name="path">the path to split</param>
48 /// <param name="separator">the separator character</param>
49 /// <param name="escape">the escape character</param>
50 /// <returns>path parts</returns>
51 public static IEnumerable<string> PathSplit(this string path, char separator, char? escape)
52 {
53 Stack<char> s = new Stack<char>();
54 StringBuilder p = new StringBuilder();
55 foreach (char c in path)
56 {
57 if (c == escape)
58 {
59 s.Push(c);
60 continue;
61 }
62 if (c == separator)
63 {
64 if (s.Count.Equals(0) || !s.Peek().Equals(escape))
65 {
66 yield return p.ToString();
67 p = new StringBuilder();
68 continue;
69 }
70 s.Pop();
71 while (!s.Count.Equals(0))
72 {
73 p.Append(s.Pop());
74 }
75 p.Append(c);
76 continue;
77 }
78 p.Append(c);
79 }
80 while (!s.Count.Equals(0))
81 {
82 p.Append(s.Pop());
83 }
84 yield return p.ToString();
85 }
86 }
87 }