public static bool TryParseSpan(ReadOnlySpan <char> input, out Ulid ulid) { if (input.Length != VALID_ULID_STRING_LENGTH) { ulid = default; return(false); } Span <int> index = stackalloc int[VALID_ULID_STRING_LENGTH]; for (int i = 0; i < input.Length; ++i) { char c = char.ToUpperInvariant(input[i]); bool found = false; for (int v = 0; v < CrockfordsBase32.Length; ++v) { if (CrockfordsBase32[v] == c) { index[i] = v; found = true; break; } } if (!found) { ulid = default; return(false); } } ulid = UlidStringHelper.FromString(index); return(true); }
public int CompareTo(Ulid other) { int result = 0, index = 0; var thisHelper = new UlidStringHelper(this); var otherHelper = new UlidStringHelper(other); while (result == 0 && index < VALID_ULID_STRING_LENGTH) { result = thisHelper[index].CompareTo(otherHelper[index]); ++index; } return(result); }