Skip to content

Commit

Permalink
Update BoolTypeDecider.cs
Browse files Browse the repository at this point in the history
Try the system Bool parser first.
  • Loading branch information
jas88 committed Jun 24, 2024
1 parent df68f74 commit ca8d34f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions TypeGuesser/Deciders/BoolTypeDecider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ protected override IDecideTypesForStrings CloneImpl(CultureInfo newCulture)
/// <inheritdoc />
protected override object? ParseImpl(ReadOnlySpan<char> candidateString)
{
if (bool.TryParse(candidateString, out var sysResult)) return sysResult;

candidateString = StripWhitespace(candidateString);

return candidateString.Length switch
Expand Down Expand Up @@ -53,13 +55,13 @@ private static ReadOnlySpan<char> StripWhitespace(ReadOnlySpan<char> candidateSt
/// <inheritdoc/>
protected override bool IsAcceptableAsTypeImpl(ReadOnlySpan<char> candidateString,IDataTypeSize? size)
{
candidateString = StripWhitespace(candidateString);
var strippedString = StripWhitespace(candidateString);

// "Y" / "N" is boolean unless the settings say it can't
if (!Settings.CharCanBeBoolean && candidateString.Length == 1)
if (!Settings.CharCanBeBoolean && strippedString.Length == 1 && char.IsAsciiLetter(strippedString[0]))
return false;

return candidateString.Length switch
return bool.TryParse(candidateString, out _) || candidateString.Length switch
{
1 => "1tTyYjJ0fFnN".IndexOf(candidateString[0]) != -1,
2 => candidateString.Equals("ja",StringComparison.OrdinalIgnoreCase) ||
Expand Down

0 comments on commit ca8d34f

Please sign in to comment.