1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:47:45 +00:00

AK: Make string-to-number conversion helpers return Optional

Get rid of the weird old signature:

- int StringType::to_int(bool& ok) const

And replace it with sensible new signature:

- Optional<int> StringType::to_int() const
This commit is contained in:
Andreas Kling 2020-06-12 21:07:52 +02:00
parent 15f4043a7a
commit fdfda6dec2
55 changed files with 354 additions and 455 deletions

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/Optional.h>
#include <AK/String.h>
#include <LibCore/DateTime.h>
#include <stdio.h>
@ -44,12 +45,12 @@ int main(int argc, char** argv)
return 0;
}
if (argc == 3 && !strcmp(argv[1], "-s")) {
bool ok;
timespec ts = { String(argv[2]).to_uint(ok), 0 };
if (!ok) {
auto number = StringView(argv[2]).to_uint();
if (!number.has_value()) {
fprintf(stderr, "date: Invalid timestamp value");
return 1;
}
timespec ts = { number.value(), 0 };
if (clock_settime(CLOCK_REALTIME, &ts) < 0) {
perror("clock_settime");
return 1;