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 c565d4f commit d66aad9
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions sdk/lib/_internal/js_runtime/lib/js_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -380,22 +380,31 @@ class Primitives {
}

static bool? parseBool(String source, bool caseSensitive) {
checkNotNullable(source, "source");
checkNotNullable(source, "source");
checkNotNullable(caseSensitive, "caseSensitive");
//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;
}

/// [: r"$".codeUnitAt(0) :]
Expand Down

0 comments on commit d66aad9

Please sign in to comment.