-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Method to parse bools #2870
Comments
This comment was originally written by @seaneagan should be static: static bool parse(String s, [bool ifInvalid]); |
Not sure this is a library issue. cc @floitschG. |
Library is the right area. |
This comment was originally written by @seaneagan issue #2868 is the dual of this issue for int, num, and double. I agree they should be consistent, and I would be ok with either constructors or static methods. I also like them as constructors, except for the fact that you would virtually always need to wrap calls to them in try blocks: bool x; whereas a static method could just return null, simplifying it to: bool x = bool.parse(boolString); or in the case where you want to throw an exception on an invalid bool String: final bool x = bool.parse(boolString); I slightly prefer "parse" over "fromString" since it's no less clear and yet shorter, but I wouldn't bikeshed it. There's also the question of whether the comparison should be case-insensitive (e.g. allowing "True", "faLSE"), to which I believe the answer is no, since those do not (necessarily) represent bools in Dart code. |
This comment was originally written by ladicek@gmail.com Remember that the constructor could (and probably should) actually be a factory constructor, which can also return null. I'm also a fan of calling it "parse". |
This comment was originally written by @seaneagan I think it would be strange if "new bool.parse()" ever returned null. If "new " weren't required on constructor calls, then I would probably feel differently. Also, whatever solution is used here should be consistently applied to Date.fromString (parse vs. fromString and static method vs. constructor). |
It's unclear which values should be allowed as input. Is 'true', 'True', and 'TRUE' all valid? Is 'TrUe'? I'd prefer not forcing a string representation of booleans by having an official parse function. Removed Type-Defect label. |
Since the function can be as simple as (x)=>x=="true" I'd prefer not to add it to the platform libraries. The textual representation of a boolean should generally be picked to match the context (maybe "yes"/"no" rather than "true"/"false"), and a general parsing function would only encourage using the generic name over a more suitable one. Added NotPlanned label. |
New commits included: ``` > git log --format="%C(auto) %h %s" 0e657414a472e74ca5dd76ae0db50cc060251dec..255a3091fc278b04be74d246a3bec8743ef4d0b7 255a3091 Vendor package:tar and package:chunked_stream (#2932) 86bf8b20 Handle relative git-url-paths correctly when --directory (#2919) 3716a681 Let `pub add` fail if extra arguments are passed (#2927) a03ac729 Minor cleanup to reduce risk of using path.current (#2924) e87b7b66 Added null check for name in UserInfo class (#2918) 056a8c9a pub deps --json (#2896) 53a69e27 Fix .packages entries of relative path deps when using --directory (#2916) d6308efc pub upgrade command shows count of discontinued packages (#2908) 51744805 Upgrade to the null safe versions of all dependencies (#2913) e0d538c7 Introduce .pubignore (#2787) 79f3a8b9 pub outdated: added clear message when no outdated packages. (#2898) 22463872 `cache clean` (#2904) 11e7b2ce `publish --dry-run` informs that the server might do more checks (#2883) b6977d50 Remove untrue assert (#2884) 35841f8d Merge branch 'cherry_picks_for_2_12' 0db3255b Don't fail on failed status listing (#2877) 53e8ecca Don't allow outdated taking arguments (#2872) e83a1dc1 Enable asserts when testing pub (#2754) 178f2edb Add --directory option (#2876) 5aadb70e Don't fail on failed status listing (#2877) 4bf8a927 Remove unused field (#2878) 73ad5426 Don't allow outdated taking arguments (#2872) 9a70949e Use Dart library to read and write tar files (#2817) 2f74230c Do not recommend decativating packages (#2871) b1697a27 Use full error message string in CommandResolutionFailedException (#2870) 16a6210d Upgrade `downgrade --help`: `downgrade` actually updates `pubspec.lock` (#2859) 6e240ea9 Use cached version listings as heuristic when prefetching (#2851) 58152f7c Allow trailing slash in PUB_HOSTED_URL (#2856) b1bf9a33 Handle poor package-listing responses robustly. (#2847) d941bd24 Fix request metadata when overriding dependencyType (#2848) ``` Change-Id: Id6ed5698330fc0cdb507e024eabc34f925ca9208 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192304 Commit-Queue: Sigurd Meldgaard <sigurdm@google.com> Reviewed-by: Jonas Jensen <jonasfj@google.com>
This reverts commit 633d4ac. Reason for revert: breaks dependency resolution in some cases. Original change's description: > Bump pub > > New commits included: > ``` > > git log --format="%C(auto) %h %s" 0e657414a472e74ca5dd76ae0db50cc060251dec..255a3091fc278b04be74d246a3bec8743ef4d0b7 > 255a3091 Vendor package:tar and package:chunked_stream (#2932) > 86bf8b20 Handle relative git-url-paths correctly when --directory (#2919) > 3716a681 Let `pub add` fail if extra arguments are passed (#2927) > a03ac729 Minor cleanup to reduce risk of using path.current (#2924) > e87b7b66 Added null check for name in UserInfo class (#2918) > 056a8c9a pub deps --json (#2896) > 53a69e27 Fix .packages entries of relative path deps when using --directory (#2916) > d6308efc pub upgrade command shows count of discontinued packages (#2908) > 51744805 Upgrade to the null safe versions of all dependencies (#2913) > e0d538c7 Introduce .pubignore (#2787) > 79f3a8b9 pub outdated: added clear message when no outdated packages. (#2898) > 22463872 `cache clean` (#2904) > 11e7b2ce `publish --dry-run` informs that the server might do more checks (#2883) > b6977d50 Remove untrue assert (#2884) > 35841f8d Merge branch 'cherry_picks_for_2_12' > 0db3255b Don't fail on failed status listing (#2877) > 53e8ecca Don't allow outdated taking arguments (#2872) > e83a1dc1 Enable asserts when testing pub (#2754) > 178f2edb Add --directory option (#2876) > 5aadb70e Don't fail on failed status listing (#2877) > 4bf8a927 Remove unused field (#2878) > 73ad5426 Don't allow outdated taking arguments (#2872) > 9a70949e Use Dart library to read and write tar files (#2817) > 2f74230c Do not recommend decativating packages (#2871) > b1697a27 Use full error message string in CommandResolutionFailedException (#2870) > 16a6210d Upgrade `downgrade --help`: `downgrade` actually updates `pubspec.lock` (#2859) > 6e240ea9 Use cached version listings as heuristic when prefetching (#2851) > 58152f7c Allow trailing slash in PUB_HOSTED_URL (#2856) > b1bf9a33 Handle poor package-listing responses robustly. (#2847) > d941bd24 Fix request metadata when overriding dependencyType (#2848) > ``` > > Change-Id: Id6ed5698330fc0cdb507e024eabc34f925ca9208 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192304 > Commit-Queue: Sigurd Meldgaard <sigurdm@google.com> > Reviewed-by: Jonas Jensen <jonasfj@google.com> TBR=sigurdm@google.com,jonasfj@google.com Change-Id: I364a26468a36438bbbc887e613241030decef4d3 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192748 Reviewed-by: Alexander Thomas <athom@google.com> Commit-Queue: Alexander Thomas <athom@google.com>
New commits include: ``` $ git log --format="%C(auto) %h %s" 0e657414a472e74ca5dd76ae0db50cc060251dec..00c00e8adf9706bebe8f94483b7663c5f36f59d2 00c00e8a Vendor tar (#2987) 291705ca Being gradual migration to null-safety (#2988) c5f52a37 Fix CI (#2989) 74040a45 Update to analyzer 1.5.0, migrate from deprecated AnalysisSession.getParsedUnit() (#2975) ce951d70 Fix dry-run tests for publishing by ensuring there is a server to reject requests (#2978) 018c9650 Update LICENSE (#2944) 2614f15c Revert "Vendor package:tar and package:chunked_stream (#2932)" (#2940) 12d9f457 Handle package:tar cancellations 255a3091 Vendor package:tar and package:chunked_stream (#2932) 86bf8b20 Handle relative git-url-paths correctly when --directory (#2919) 3716a681 Let `pub add` fail if extra arguments are passed (#2927) a03ac729 Minor cleanup to reduce risk of using path.current (#2924) e87b7b66 Added null check for name in UserInfo class (#2918) 056a8c9a pub deps --json (#2896) 53a69e27 Fix .packages entries of relative path deps when using --directory (#2916) d6308efc pub upgrade command shows count of discontinued packages (#2908) 51744805 Upgrade to the null safe versions of all dependencies (#2913) e0d538c7 Introduce .pubignore (#2787) 79f3a8b9 pub outdated: added clear message when no outdated packages. (#2898) 22463872 `cache clean` (#2904) 11e7b2ce `publish --dry-run` informs that the server might do more checks (#2883) b6977d50 Remove untrue assert (#2884) 35841f8d Merge branch 'cherry_picks_for_2_12' 0db3255b Don't fail on failed status listing (#2877) 53e8ecca Don't allow outdated taking arguments (#2872) e83a1dc1 Enable asserts when testing pub (#2754) 178f2edb Add --directory option (#2876) 5aadb70e Don't fail on failed status listing (#2877) 4bf8a927 Remove unused field (#2878) 73ad5426 Don't allow outdated taking arguments (#2872) 9a70949e Use Dart library to read and write tar files (#2817) 2f74230c Do not recommend decativating packages (#2871) b1697a27 Use full error message string in CommandResolutionFailedException (#2870) 16a6210d Upgrade `downgrade --help`: `downgrade` actually updates `pubspec.lock` (#2859) 6e240ea9 Use cached version listings as heuristic when prefetching (#2851) 58152f7c Allow trailing slash in PUB_HOSTED_URL (#2856) b1bf9a33 Handle poor package-listing responses robustly. (#2847) d941bd24 Fix request metadata when overriding dependencyType (#2848) ``` Change-Id: Id7cc4c09e74c02a92bcafe1a9d9bab9431900540 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/199040 Reviewed-by: Alexander Thomas <athom@google.com> Commit-Queue: Jonas Jensen <jonasfj@google.com>
This issue was originally filed by @seaneagan
The bool interface should provide a method to parse bool Strings:
interface bool {
bool parse(String s, [bool ifInvalid]);
//...
}
where parse's implementation is something like:
(String s, [bool ifInvalid]) {
if(s === null || !(s == 'true' || s == 'false')) return ifInvalid;
return s == 'true';
}
The text was updated successfully, but these errors were encountered: