Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
srburton committed Jan 25, 2023
1 parent d66aad9 commit c3dcc73
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions sdk/lib/_internal/vm_shared/lib/bool_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,47 @@ class bool {

@patch
static bool parse(String source, {bool? caseSensitive}) {
checkNotNullable(source, "source");
checkNotNullable(source, "source");
//The caseSensitive defaults to true.
if (caseSensitive == null || caseSensitive == true)
return source == "true" ? true : source == "false" ? false : throw ArgumentError(source);
//Ignore case-sensitive when caseSensitive is false.
return _compareIgnoreCase(source, "true")? true : _compareIgnoreCase(source, "false")? false : throw ArgumentError(source);
if (caseSensitive == null || caseSensitive == true)
return source == "true"
? true
: source == "false"
? false
: throw ArgumentError(source);
//Ignore case-sensitive when caseSensitive is false.
return _compareIgnoreCase(source, "true")
? true
: _compareIgnoreCase(source, "false")
? false
: throw ArgumentError(source);
}

@patch
static bool? tryParse(String source, {bool? caseSensitive}) {
checkNotNullable(source, "source");
checkNotNullable(source, "source");
//The caseSensitive defaults to true.
if (caseSensitive == null || caseSensitive == true)
return source == "true" ? true : source == "false" ? false : null;
//Ignore case-sensitive when caseSensitive is false.
return _compareIgnoreCase(source, "true")? true : _compareIgnoreCase(source, "false")? false : null;
if (caseSensitive == null || caseSensitive == true)
return source == "true"
? true
: source == "false"
? false
: null;
//Ignore case-sensitive when caseSensitive is false.
return _compareIgnoreCase(source, "true")
? true
: _compareIgnoreCase(source, "false")
? false
: null;
}

static bool _compareIgnoreCase(String input, String lowerCaseTarget) {
if (input.length != lowerCaseTarget.length) return false;
for (var i = 0; i < input.length; i++) {
if (input.codeUnitAt(i) | 0x20 != lowerCaseTarget.codeUnitAt(i)) {
return false;
}
}
return true;
if (input.length != lowerCaseTarget.length) return false;
for (var i = 0; i < input.length; i++) {
if (input.codeUnitAt(i) | 0x20 != lowerCaseTarget.codeUnitAt(i)) {
return false;
}
}
return true;
}
}

0 comments on commit c3dcc73

Please sign in to comment.