-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathString.cs
66 lines (48 loc) · 2.49 KB
/
String.cs
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
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using static System.Runtime.CompilerServices.MethodImplOptions;
namespace Plato
{
/// <summary>
/// A simple wrapper around the built-in <c>string</c> type.
/// </summary>
[DataContract]
public partial struct String
{
// -------------------------------------------------------------------------------
// Field
// -------------------------------------------------------------------------------
[DataMember] public readonly string Value;
// -------------------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------------------
[MethodImpl(AggressiveInlining)]
public String(string value) => Value = value;
// -------------------------------------------------------------------------------
// Methods
// -------------------------------------------------------------------------------
[MethodImpl(AggressiveInlining)]
public Character At(Integer n) => Value[n];
public Character this[Integer n] { [MethodImpl(AggressiveInlining)] get => At(n); }
public Integer Count { [MethodImpl(AggressiveInlining)] get => Value.Length; }
// -------------------------------------------------------------------------------
// Conversions
// -------------------------------------------------------------------------------
[MethodImpl(AggressiveInlining)]
public string ToSystem() => Value;
[MethodImpl(AggressiveInlining)]
public static String FromSystem(string s) => new(s);
[MethodImpl(AggressiveInlining)]
public static implicit operator String(string s) => FromSystem(s);
[MethodImpl(AggressiveInlining)]
public static implicit operator string(String s) => s.ToSystem();
[MethodImpl(AggressiveInlining)]
public static bool operator <= (String a, String b) => a.Value.CompareTo(b.Value) <= 0;
[MethodImpl(AggressiveInlining)]
public static bool operator >=(String a, String b) => a.Value.CompareTo(b.Value) >= 0;
[MethodImpl(AggressiveInlining)]
public static bool operator <(String a, String b) => a.Value.CompareTo(b.Value) < 0;
[MethodImpl(AggressiveInlining)]
public static bool operator >(String a, String b) => a.Value.CompareTo(b.Value) > 0;
}
}