| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. See License.txt in the project root for |
| | 3 | | // license information. |
| | 4 | |
|
| | 5 | | namespace Microsoft.Azure.Search.Models |
| | 6 | | { |
| | 7 | | using System; |
| | 8 | | using Microsoft.Azure.Search.Common; |
| | 9 | | using Newtonsoft.Json; |
| | 10 | | using Serialization; |
| | 11 | |
|
| | 12 | | /// <summary> |
| | 13 | | /// Defines flags that can be combined to control how regular expressions are used in the pattern analyzer and |
| | 14 | | /// pattern tokenizer. |
| | 15 | | /// <see href="http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#field_summary"/> |
| | 16 | | /// </summary> |
| | 17 | | [JsonConverter(typeof(ExtensibleEnumConverter<RegexFlags>))] |
| | 18 | | public struct RegexFlags : IEquatable<RegexFlags> |
| | 19 | | { |
| | 20 | | private readonly string _value; |
| | 21 | |
|
| | 22 | | // MAINTENANCE NOTE: Keep these ordered the same as the table on this page: |
| | 23 | | // http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#field_summary |
| | 24 | |
|
| | 25 | | /// <summary> |
| | 26 | | /// Enables canonical equivalence. <see href="http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.h |
| | 27 | | /// </summary> |
| 2 | 28 | | public static readonly RegexFlags CanonEq = new RegexFlags("CANON_EQ"); |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// Enables case-insensitive matching. <see href="http://docs.oracle.com/javase/6/docs/api/java/util/regex/Patte |
| | 32 | | /// </summary> |
| 2 | 33 | | public static readonly RegexFlags CaseInsensitive = new RegexFlags("CASE_INSENSITIVE"); |
| | 34 | |
|
| | 35 | | /// <summary> |
| | 36 | | /// Permits whitespace and comments in the pattern. <see href="http://docs.oracle.com/javase/6/docs/api/java/uti |
| | 37 | | /// </summary> |
| 2 | 38 | | public static readonly RegexFlags Comments = new RegexFlags("COMMENTS"); |
| | 39 | |
|
| | 40 | | /// <summary> |
| | 41 | | /// Enables dotall mode. <see href="http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#DOTALL |
| | 42 | | /// </summary> |
| 2 | 43 | | public static readonly RegexFlags DotAll = new RegexFlags("DOTALL"); |
| | 44 | |
|
| | 45 | | /// <summary> |
| | 46 | | /// Enables literal parsing of the pattern. <see href="http://docs.oracle.com/javase/6/docs/api/java/util/regex/ |
| | 47 | | /// </summary> |
| 2 | 48 | | public static readonly RegexFlags Literal = new RegexFlags("LITERAL"); |
| | 49 | |
|
| | 50 | | /// <summary> |
| | 51 | | /// Enables multiline mode. <see href="http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#MUL |
| | 52 | | /// </summary> |
| 2 | 53 | | public static readonly RegexFlags Multiline = new RegexFlags("MULTILINE"); |
| | 54 | |
|
| | 55 | | /// <summary> |
| | 56 | | /// Enables Unicode-aware case folding. <see href="http://docs.oracle.com/javase/6/docs/api/java/util/regex/Patt |
| | 57 | | /// </summary> |
| 2 | 58 | | public static readonly RegexFlags UnicodeCase = new RegexFlags("UNICODE_CASE"); |
| | 59 | |
|
| | 60 | | /// <summary> |
| | 61 | | /// Enables Unix lines mode. <see href="http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#UN |
| | 62 | | /// </summary> |
| 2 | 63 | | public static readonly RegexFlags UnixLines = new RegexFlags("UNIX_LINES"); |
| | 64 | |
|
| | 65 | | private RegexFlags(string flags) |
| | 66 | | { |
| 38 | 67 | | Throw.IfArgumentNull(flags, nameof(flags)); |
| 38 | 68 | | _value = flags; |
| 38 | 69 | | } |
| | 70 | |
|
| | 71 | | /// <summary> |
| | 72 | | /// Overloads the bitwise OR operator to combines two RegexFlags. |
| | 73 | | /// </summary> |
| | 74 | | /// <param name="lhs">The left-hand side of the OR expression.</param> |
| | 75 | | /// <param name="rhs">The right-hand side of the OR expression.</param> |
| | 76 | | /// <returns> |
| | 77 | | /// A new RegexFlags that is the result of concatenating the two given RegexFlags, separated by a |
| | 78 | | /// vertical bar (|). |
| | 79 | | /// </returns> |
| 2 | 80 | | public static RegexFlags operator |(RegexFlags lhs, RegexFlags rhs) => new RegexFlags($"{lhs}|{rhs}"); |
| | 81 | |
|
| | 82 | | /// <summary> |
| | 83 | | /// Defines implicit conversion from string to RegexFlags. |
| | 84 | | /// </summary> |
| | 85 | | /// <param name="value">string to convert.</param> |
| | 86 | | /// <returns>The string as a RegexFlags.</returns> |
| 0 | 87 | | public static implicit operator RegexFlags(string value) => new RegexFlags(value); |
| | 88 | |
|
| | 89 | | /// <summary> |
| | 90 | | /// Defines explicit conversion from RegexFlags to string. |
| | 91 | | /// </summary> |
| | 92 | | /// <param name="flags">RegexFlags to convert.</param> |
| | 93 | | /// <returns>The RegexFlags as a string.</returns> |
| 0 | 94 | | public static explicit operator string(RegexFlags flags) => flags.ToString(); |
| | 95 | |
|
| | 96 | | /// <summary> |
| | 97 | | /// Compares two RegexFlags values for equality. |
| | 98 | | /// </summary> |
| | 99 | | /// <param name="lhs">The first RegexFlags to compare.</param> |
| | 100 | | /// <param name="rhs">The second RegexFlags to compare.</param> |
| | 101 | | /// <returns>true if the RegexFlags objects are equal or are both null; false otherwise.</returns> |
| 0 | 102 | | public static bool operator ==(RegexFlags lhs, RegexFlags rhs) => Equals(lhs, rhs); |
| | 103 | |
|
| | 104 | | /// <summary> |
| | 105 | | /// Compares two RegexFlags values for inequality. |
| | 106 | | /// </summary> |
| | 107 | | /// <param name="lhs">The first RegexFlags to compare.</param> |
| | 108 | | /// <param name="rhs">The second RegexFlags to compare.</param> |
| | 109 | | /// <returns>true if the RegexFlags objects are not equal; false otherwise.</returns> |
| 0 | 110 | | public static bool operator !=(RegexFlags lhs, RegexFlags rhs) => !Equals(lhs, rhs); |
| | 111 | |
|
| | 112 | | /// <summary> |
| | 113 | | /// Compares the RegexFlags for equality with another RegexFlags. |
| | 114 | | /// </summary> |
| | 115 | | /// <param name="other">The RegexFlags with which to compare.</param> |
| | 116 | | /// <returns><c>true</c> if the RegexFlags objects are equal; otherwise, <c>false</c>.</returns> |
| 20 | 117 | | public bool Equals(RegexFlags other) => _value == other._value; |
| | 118 | |
|
| | 119 | | /// <summary> |
| | 120 | | /// Determines whether the specified object is equal to the current object. |
| | 121 | | /// </summary> |
| | 122 | | /// <param name="obj">The object to compare with the current object.</param> |
| | 123 | | /// <returns><c>true</c> if the specified object is equal to the current object; otherwise, <c>false</c>.</retur |
| 0 | 124 | | public override bool Equals(object obj) => obj is RegexFlags ? Equals((RegexFlags)obj) : false; |
| | 125 | |
|
| | 126 | | /// <summary> |
| | 127 | | /// Serves as the default hash function. |
| | 128 | | /// </summary> |
| | 129 | | /// <returns>A hash code for the current object.</returns> |
| 0 | 130 | | public override int GetHashCode() => _value.GetHashCode(); |
| | 131 | |
|
| | 132 | | /// <summary> |
| | 133 | | /// Returns a string representation of the RegexFlags. |
| | 134 | | /// </summary> |
| | 135 | | /// <returns>The RegexFlags as a string.</returns> |
| 24 | 136 | | public override string ToString() => _value; |
| | 137 | | } |
| | 138 | | } |