forked from commandlineparser/commandline
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringExtensions.cs
More file actions
77 lines (64 loc) · 2.39 KB
/
Copy pathStringExtensions.cs
File metadata and controls
77 lines (64 loc) · 2.39 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
// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
using System;
using System.Globalization;
using System.Text;
namespace CommandLine.Infrastructure
{
static class StringExtensions
{
public static string ToOneCharString(this char c)
{
return new string(c, 1);
}
public static string ToStringInvariant<T>(this T value)
{
return Convert.ToString(value, CultureInfo.InvariantCulture);
}
public static string ToStringLocal<T>(this T value)
{
return Convert.ToString(value, CultureInfo.CurrentCulture);
}
public static string FormatInvariant(this string value, params object[] arguments)
{
return string.Format(CultureInfo.InvariantCulture, value, arguments);
}
public static string FormatLocal(this string value, params object[] arguments)
{
return string.Format(CultureInfo.CurrentCulture, value, arguments);
}
public static string Spaces(this int value)
{
return new string(' ', value);
}
public static bool EqualsOrdinal(this string strA, string strB)
{
return string.CompareOrdinal(strA, strB) == 0;
}
public static bool EqualsOrdinalIgnoreCase(this string strA, string strB)
{
return string.Compare(strA, strB, StringComparison.OrdinalIgnoreCase) == 0;
}
public static int SafeLength(this string value)
{
return value == null ? 0 : value.Length;
}
public static string JoinTo(this string value, params string[] others)
{
var builder = new StringBuilder(value);
foreach (var v in others)
{
builder.Append(v);
}
return builder.ToString();
}
public static bool IsBooleanString(this string value)
{
return value.Equals("true", StringComparison.OrdinalIgnoreCase)
|| value.Equals("false", StringComparison.OrdinalIgnoreCase);
}
public static bool ToBoolean(this string value)
{
return value.Equals("true", StringComparison.OrdinalIgnoreCase);
}
}
}