Std

Mainly a port of Rust's std.
git clone https://git.philomathiclife.com/repos/Std
Log | Files | Refs | README

String.cs (10186B)


      1 using System;
      2 using System.Runtime.InteropServices;
      3 #region Namespaces
      4 namespace Std.String {
      5     #region Types
      6     // Marker interface that MUST only be used as a type bound (along with the struct type bound) for the type parameter
      7     // for the Name type constructor.
      8     public interface IStringComparison {
      9 
     10         #region Type-level Constructors
     11         #endregion
     12 
     13         #region Instance Constructors
     14         #endregion
     15 
     16         #region Type-level Fields
     17         internal const string Exception = "Bottom-like types are not allowed to be instantiated.";
     18         #endregion
     19 
     20         #region Instance Fields
     21         #endregion
     22 
     23         #region Type-level Properties
     24         #endregion
     25 
     26         #region Instance Properties
     27         public abstract byte Encoding { get; }
     28         public abstract StringComparison StringComparison { get; }
     29         #endregion
     30 
     31         #region Type-level Functions
     32         #endregion
     33 
     34         #region Instance Functions
     35         internal abstract void Sealed();
     36         #endregion
     37 
     38         #region Operators
     39         #endregion
     40 
     41         #region Types
     42         #endregion
     43     }
     44     // The below six types are bottom types (i.e., they MUST NOT be instantiated or used in way at runtime).
     45     // They exist purely as a way to hoist a System.StringComparison to the type level allowing
     46     // for something like Name to be imbued with additional algebraic structure (e.g., a total order to be defined).
     47     [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode, Pack = 1, Size = 1)]
     48     public readonly struct Ordinal: IStringComparison {
     49 
     50         #region Type-level Constructors
     51         #endregion
     52 
     53         #region Instance Constructors
     54         public Ordinal() => throw new InvalidOperationException(IStringComparison.Exception);
     55         #endregion
     56 
     57         #region Type-level Fields
     58         #endregion
     59 
     60         #region Instance Fields
     61         #endregion
     62 
     63         #region Type-level Properties
     64         #endregion
     65 
     66         #region Instance Properties
     67         readonly byte IStringComparison.Encoding => 1;
     68         readonly StringComparison IStringComparison.StringComparison => StringComparison.Ordinal;
     69         #endregion
     70 
     71         #region Type-level Functions
     72         #endregion
     73 
     74         #region Instance Functions
     75         public override readonly bool Equals(object? _) => throw new InvalidOperationException(IStringComparison.Exception);
     76         public override readonly int GetHashCode() => throw new InvalidOperationException(IStringComparison.Exception);
     77         readonly void IStringComparison.Sealed() => throw new InvalidOperationException(IStringComparison.Exception);
     78         public override readonly string ToString() => throw new InvalidOperationException(IStringComparison.Exception);
     79         #endregion
     80 
     81         #region Operators
     82         #endregion
     83 
     84         #region Types
     85         #endregion
     86     }
     87     [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode, Pack = 1, Size = 1)]
     88     public readonly struct OrdinalIgnoreCase: IStringComparison {
     89 
     90         #region Type-level Constructors
     91         #endregion
     92 
     93         #region Instance Constructors
     94         public OrdinalIgnoreCase() => throw new InvalidOperationException(IStringComparison.Exception);
     95         #endregion
     96 
     97         #region Type-level Fields
     98         #endregion
     99 
    100         #region Instance Fields
    101         #endregion
    102 
    103         #region Type-level Properties
    104         #endregion
    105 
    106         #region Instance Properties
    107         readonly byte IStringComparison.Encoding => 2;
    108         readonly StringComparison IStringComparison.StringComparison => StringComparison.OrdinalIgnoreCase;
    109         #endregion
    110 
    111         #region Type-level Functions
    112         #endregion
    113 
    114         #region Instance Functions
    115         public override readonly bool Equals(object? _) => throw new InvalidOperationException(IStringComparison.Exception);
    116         public override readonly int GetHashCode() => throw new InvalidOperationException(IStringComparison.Exception);
    117         readonly void IStringComparison.Sealed() => throw new InvalidOperationException(IStringComparison.Exception);
    118         public override readonly string ToString() => throw new InvalidOperationException(IStringComparison.Exception);
    119         #endregion
    120 
    121         #region Operators
    122         #endregion
    123 
    124         #region Types
    125         #endregion
    126     }
    127     [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode, Pack = 1, Size = 1)]
    128     public readonly struct InvariantCulture: IStringComparison {
    129 
    130         #region Type-level Constructors
    131         #endregion
    132 
    133         #region Instance Constructors
    134         public InvariantCulture() => throw new InvalidOperationException(IStringComparison.Exception);
    135         #endregion
    136 
    137         #region Type-level Fields
    138         #endregion
    139 
    140         #region Instance Fields
    141         #endregion
    142 
    143         #region Type-level Properties
    144         #endregion
    145 
    146         #region Instance Properties
    147         readonly byte IStringComparison.Encoding => 3;
    148         readonly StringComparison IStringComparison.StringComparison => StringComparison.InvariantCulture;
    149         #endregion
    150 
    151         #region Type-level Functions
    152         #endregion
    153 
    154         #region Instance Functions
    155         public override readonly bool Equals(object? _) => throw new InvalidOperationException(IStringComparison.Exception);
    156         public override readonly int GetHashCode() => throw new InvalidOperationException(IStringComparison.Exception);
    157         readonly void IStringComparison.Sealed() => throw new InvalidOperationException(IStringComparison.Exception);
    158         public override readonly string ToString() => throw new InvalidOperationException(IStringComparison.Exception);
    159         #endregion
    160 
    161         #region Operators
    162         #endregion
    163 
    164         #region Types
    165         #endregion
    166     }
    167     [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode, Pack = 1, Size = 1)]
    168     public readonly struct InvariantCultureIgnoreCase: IStringComparison {
    169 
    170         #region Type-level Constructors
    171         #endregion
    172 
    173         #region Instance Constructors
    174         public InvariantCultureIgnoreCase() => throw new InvalidOperationException(IStringComparison.Exception);
    175         #endregion
    176 
    177         #region Type-level Fields
    178         #endregion
    179 
    180         #region Instance Fields
    181         #endregion
    182 
    183         #region Type-level Properties
    184         #endregion
    185 
    186         #region Instance Properties
    187         readonly byte IStringComparison.Encoding => 4;
    188         readonly StringComparison IStringComparison.StringComparison => StringComparison.InvariantCultureIgnoreCase;
    189         #endregion
    190 
    191         #region Type-level Functions
    192         #endregion
    193 
    194         #region Instance Functions
    195         public override readonly bool Equals(object? _) => throw new InvalidOperationException(IStringComparison.Exception);
    196         public override readonly int GetHashCode() => throw new InvalidOperationException(IStringComparison.Exception);
    197         readonly void IStringComparison.Sealed() => throw new InvalidOperationException(IStringComparison.Exception);
    198         public override readonly string ToString() => throw new InvalidOperationException(IStringComparison.Exception);
    199         #endregion
    200 
    201         #region Operators
    202         #endregion
    203 
    204         #region Types
    205         #endregion
    206     }
    207     [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode, Pack = 1, Size = 1)]
    208     public readonly struct CurrentCulture: IStringComparison {
    209 
    210         #region Type-level Constructors
    211         #endregion
    212 
    213         #region Instance Constructors
    214         public CurrentCulture() => throw new InvalidOperationException(IStringComparison.Exception);
    215         #endregion
    216 
    217         #region Type-level Fields
    218         #endregion
    219 
    220         #region Instance Fields
    221         #endregion
    222 
    223         #region Type-level Properties
    224         #endregion
    225 
    226         #region Instance Properties
    227         readonly byte IStringComparison.Encoding => 5;
    228         readonly StringComparison IStringComparison.StringComparison => StringComparison.CurrentCulture;
    229         #endregion
    230 
    231         #region Type-level Functions
    232         #endregion
    233 
    234         #region Instance Functions
    235         public override readonly bool Equals(object? _) => throw new InvalidOperationException(IStringComparison.Exception);
    236         public override readonly int GetHashCode() => throw new InvalidOperationException(IStringComparison.Exception);
    237         readonly void IStringComparison.Sealed() => throw new InvalidOperationException(IStringComparison.Exception);
    238         public override readonly string ToString() => throw new InvalidOperationException(IStringComparison.Exception);
    239         #endregion
    240 
    241         #region Operators
    242         #endregion
    243 
    244         #region Types
    245         #endregion
    246     }
    247     [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode, Pack = 1, Size = 1)]
    248     public readonly struct CurrentCultureIgnoreCase: IStringComparison {
    249 
    250         #region Type-level Constructors
    251         #endregion
    252 
    253         #region Instance Constructors
    254         public CurrentCultureIgnoreCase() => throw new InvalidOperationException(IStringComparison.Exception);
    255         #endregion
    256 
    257         #region Type-level Fields
    258         #endregion
    259 
    260         #region Instance Fields
    261         #endregion
    262 
    263         #region Type-level Properties
    264         #endregion
    265 
    266         #region Instance Properties
    267         readonly byte IStringComparison.Encoding => 6;
    268         readonly StringComparison IStringComparison.StringComparison => StringComparison.CurrentCultureIgnoreCase;
    269         #endregion
    270 
    271         #region Type-level Functions
    272         #endregion
    273 
    274         #region Instance Functions
    275         public override readonly bool Equals(object? _) => throw new InvalidOperationException(IStringComparison.Exception);
    276         public override readonly int GetHashCode() => throw new InvalidOperationException(IStringComparison.Exception);
    277         readonly void IStringComparison.Sealed() => throw new InvalidOperationException(IStringComparison.Exception);
    278         public override readonly string ToString() => throw new InvalidOperationException(IStringComparison.Exception);
    279         #endregion
    280 
    281         #region Operators
    282         #endregion
    283 
    284         #region Types
    285         #endregion
    286     }
    287     #endregion
    288 
    289     #region Namespaces
    290     #endregion
    291 }
    292 #endregion