wasSharp – Diff between revs 10 and 11

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