Skip to content

Commit

Permalink
Some fixes, per analyzers
Browse files Browse the repository at this point in the history
  • Loading branch information
Entomy committed Mar 10, 2020
1 parent 3b3d7fe commit efcaf59
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Core/Extensions/AsChars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ public static Char[] AsChars(this Rune rune) {
/// <exception cref="InvalidOperationException">There was an issue with the internal buffers.</exception>
public static Char[] AsChars(this Int32 codepoint) => new Rune(codepoint).AsChars();
}
}
}
2 changes: 1 addition & 1 deletion Core/Extensions/ParseInt32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ public static Int32 ParseInt32(this String @string, IFormatProvider provider) {
return Int32.Parse(@string, provider);
}
}
}
}
2 changes: 1 addition & 1 deletion Core/Extensions/ToLower.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ public static Rune ToLower(this Rune rune, CultureInfo culture) {
/// <returns>The lowercase equivalent of the <paramref name="rune"/> parameter, or the unchanged value of <paramref name="rune"/>, if <paramref name="rune"/> is already lowercase or not alphabetic.</returns>
public static Rune ToLowerInvariant(this Rune rune) => Rune.ToLowerInvariant(rune);
}
}
}
38 changes: 37 additions & 1 deletion Core/SurrogatePair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Stringier {
/// Represents a UTF-16 Surrogate Pair.
/// </summary>
[StructLayout(LayoutKind.Auto)]
public readonly struct SurrogatePair {
public readonly struct SurrogatePair : IEquatable<SurrogatePair> {
/// <summary>
/// The high surrogate
/// </summary>
Expand Down Expand Up @@ -54,5 +54,41 @@ public SurrogatePair(CodePoint codePoint) {
/// Gets the <see cref="CodePoint"/> this <see cref="SurrogatePair"/> represents.
/// </summary>
public CodePoint CodePoint => new CodePoint(Unsafe.Utf16Decode(High.value, Low.value));

/// <summary>
/// Returns a value that indicates whether this instance is equal to a specified object.
/// </summary>
/// <param name="obj">The object to compare to.</param>
/// <returns><see langword="true"/> if equal to the value of this instance; otherwise, <see langword="false"/>.</returns>
public override Boolean Equals(Object obj) {
switch (obj) {
case SurrogatePair other:
return Equals(other);
default:
return false;
}
}

/// <summary>
/// Returns a value that indicates whether this instance is equal to a specified object.
/// </summary>
/// <param name="other">The object to compare to.</param>
/// <returns><see langword="true"/> if equal to the value of this instance; otherwise, <see langword="false"/>.</returns>
public Boolean Equals(SurrogatePair other) => High.Equals(other.High) && Low.Equals(other.Low);

/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>A 32-bit signed integer hash code.</returns>
/// <remarks>
/// The hash code of a <see cref="CodePoint"/> is always the integer value of the code point.
/// </remarks>
public override Int32 GetHashCode() => High.GetHashCode() ^ Low.GetHashCode();

/// <summary>
/// Converts the value of this instance to its equivalent string representation.
/// </summary>
/// <returns>The string representation of the value of this instance.</returns>
public override String ToString() => $"({High}, {Low})";
}
}

0 comments on commit efcaf59

Please sign in to comment.