-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
StringIndexType.cs
60 lines (51 loc) · 2.85 KB
/
StringIndexType.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// <auto-generated/>
#nullable disable
using System;
using System.ComponentModel;
namespace Azure.AI.DocumentIntelligence
{
/// <summary> Method used to compute string offset and length. </summary>
public readonly partial struct StringIndexType : IEquatable<StringIndexType>
{
private readonly string _value;
/// <summary> Initializes a new instance of <see cref="StringIndexType"/>. </summary>
/// <exception cref="ArgumentNullException"> <paramref name="value"/> is null. </exception>
public StringIndexType(string value)
{
_value = value ?? throw new ArgumentNullException(nameof(value));
}
private const string TextElementsValue = "textElements";
private const string UnicodeCodePointValue = "unicodeCodePoint";
private const string Utf16CodeUnitValue = "utf16CodeUnit";
/// <summary>
/// User-perceived display character, or grapheme cluster, as defined by Unicode
/// 8.0.0.
/// </summary>
public static StringIndexType TextElements { get; } = new StringIndexType(TextElementsValue);
/// <summary> Character unit represented by a single unicode code point. Used by Python 3. </summary>
public static StringIndexType UnicodeCodePoint { get; } = new StringIndexType(UnicodeCodePointValue);
/// <summary>
/// Character unit represented by a 16-bit Unicode code unit. Used by JavaScript,
/// Java, and .NET.
/// </summary>
public static StringIndexType Utf16CodeUnit { get; } = new StringIndexType(Utf16CodeUnitValue);
/// <summary> Determines if two <see cref="StringIndexType"/> values are the same. </summary>
public static bool operator ==(StringIndexType left, StringIndexType right) => left.Equals(right);
/// <summary> Determines if two <see cref="StringIndexType"/> values are not the same. </summary>
public static bool operator !=(StringIndexType left, StringIndexType right) => !left.Equals(right);
/// <summary> Converts a string to a <see cref="StringIndexType"/>. </summary>
public static implicit operator StringIndexType(string value) => new StringIndexType(value);
/// <inheritdoc />
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object obj) => obj is StringIndexType other && Equals(other);
/// <inheritdoc />
public bool Equals(StringIndexType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase);
/// <inheritdoc />
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => _value?.GetHashCode() ?? 0;
/// <inheritdoc />
public override string ToString() => _value;
}
}