1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:57:44 +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/ElapsedTimer.h>
#include <stdio.h>
@ -36,7 +37,9 @@ void usage(void)
exit(1);
}
enum Unit { Bytes, KiloBytes, MegaBytes };
enum Unit { Bytes,
KiloBytes,
MegaBytes };
int main(int argc, char** argv)
{
@ -44,11 +47,11 @@ int main(int argc, char** argv)
Unit unit = MegaBytes;
if (argc >= 2) {
bool ok;
count = String(argv[1]).to_uint(ok);
if (!ok) {
auto number = String(argv[1]).to_uint();
if (!number.has_value()) {
usage();
}
count = number.value();
}
if (argc >= 3) {