Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
StringUtils.cs
Go to the documentation of this file.
1 #region License
2 /* **********************************************************************************
3  * Copyright (c) Roman Ivantsov
4  * This source code is subject to terms and conditions of the MIT License
5  * for Irony. A copy of the license can be found in the License.txt file
6  * at the root of this distribution.
7  * By using this source code in any fashion, you are agreeing to be bound by the terms of the
8  * MIT License.
9  * You must not remove this notice from this software.
10  * **********************************************************************************/
11 #endregion
12 
13 using System;
14 using System.Collections.Generic;
15 using System.Text;
16 
17 namespace Irony.Parsing {
18 
19  public static class Strings {
20  public const string AllLatinLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
21  public const string DecimalDigits = "1234567890";
22  public const string OctalDigits = "12345670";
23  public const string HexDigits = "1234567890aAbBcCdDeEfF";
24  public const string BinaryDigits = "01";
25 
26  public static string JoinStrings(string separator, IEnumerable<string> values) {
27  StringList list = new StringList();
28  list.AddRange(values);
29  string[] arr = new string[list.Count];
30  list.CopyTo(arr, 0);
31  return string.Join(separator, arr);
32  }
33 
34  }//class
35 
36  public class StringDictionary : Dictionary<string, string> { }
37  public class CharList : List<char> { }
38  public class CharHashSet : HashSet<char> { } //adding Hash to the name to avoid confusion with System.Runtime.Interoperability.CharSet
39 
40  public class StringSet : HashSet<string> {
41  public StringSet() { }
42  public StringSet(StringComparer comparer) : base(comparer) { }
43  public override string ToString() {
44  return ToString(" ");
45  }
46  public void AddRange(params string[] items) {
47  base.UnionWith(items);
48  }
49  public string ToString(string separator) {
50  return Strings.JoinStrings(separator, this);
51  }
52  }
53 
54  public class StringList : List<string> {
55  public StringList() { }
56  public StringList(params string[] args) {
57  AddRange(args);
58  }
59  public override string ToString() {
60  return ToString(" ");
61  }
62  public string ToString(string separator) {
63  return Strings.JoinStrings(separator, this);
64  }
65  //Used in sorting suffixes and prefixes; longer strings must come first in sort order
66  public static int LongerFirst(string x, string y) {
67  try {//in case any of them is null
68  if (x.Length > y.Length) return -1;
69  } catch { }
70  if (x == y) return 0;
71  return 1;
72  }
73 
74  }//class
75 
76 
77 }
string ToString(string separator)
Definition: StringUtils.cs:62
override string ToString()
Definition: StringUtils.cs:43
override string ToString()
Definition: StringUtils.cs:59
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t y
Definition: DirectXTexP.h:191
static int LongerFirst(string x, string y)
Definition: StringUtils.cs:66
StringSet(StringComparer comparer)
Definition: StringUtils.cs:42
string ToString(string separator)
Definition: StringUtils.cs:49
static string JoinStrings(string separator, IEnumerable< string > values)
Definition: StringUtils.cs:26
StringList(params string[] args)
Definition: StringUtils.cs:56
void AddRange(params string[] items)
Definition: StringUtils.cs:46