mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 18:47:41 +00:00
Replace various copies of parse_uint(String) with String::to_uint().
This commit is contained in:
parent
cea631d90c
commit
b5b44a29bb
4 changed files with 6 additions and 70 deletions
|
@ -116,21 +116,6 @@ inline bool is_valid_final_character(byte ch)
|
||||||
return ch >= 0x40 && ch <= 0x7e;
|
return ch >= 0x40 && ch <= 0x7e;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned parse_uint(const String& str, bool& ok)
|
|
||||||
{
|
|
||||||
unsigned value = 0;
|
|
||||||
for (int i = 0; i < str.length(); ++i) {
|
|
||||||
if (str[i] < '0' || str[i] > '9') {
|
|
||||||
ok = false;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
value = value * 10;
|
|
||||||
value += str[i] - '0';
|
|
||||||
}
|
|
||||||
ok = true;
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline Color lookup_color(unsigned color)
|
static inline Color lookup_color(unsigned color)
|
||||||
{
|
{
|
||||||
return Color::from_rgb(xterm_colors[color]);
|
return Color::from_rgb(xterm_colors[color]);
|
||||||
|
@ -397,7 +382,7 @@ void Terminal::execute_xterm_command()
|
||||||
{
|
{
|
||||||
m_final = '@';
|
m_final = '@';
|
||||||
bool ok;
|
bool ok;
|
||||||
unsigned value = parse_uint(String::copy(m_xterm_param1), ok);
|
unsigned value = String::copy(m_xterm_param1).to_uint(ok);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -421,7 +406,7 @@ void Terminal::execute_escape_sequence(byte final)
|
||||||
ParamVector params;
|
ParamVector params;
|
||||||
for (auto& parampart : paramparts) {
|
for (auto& parampart : paramparts) {
|
||||||
bool ok;
|
bool ok;
|
||||||
unsigned value = parse_uint(parampart, ok);
|
unsigned value = parampart.to_uint(ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
m_parameters.clear_with_capacity();
|
m_parameters.clear_with_capacity();
|
||||||
m_intermediates.clear_with_capacity();
|
m_intermediates.clear_with_capacity();
|
||||||
|
|
|
@ -128,21 +128,6 @@ inline bool is_valid_final_character(byte ch)
|
||||||
return ch >= 0x40 && ch <= 0x7e;
|
return ch >= 0x40 && ch <= 0x7e;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned parse_uint(const String& str, bool& ok)
|
|
||||||
{
|
|
||||||
unsigned value = 0;
|
|
||||||
for (int i = 0; i < str.length(); ++i) {
|
|
||||||
if (str[i] < '0' || str[i] > '9') {
|
|
||||||
ok = false;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
value = value * 10;
|
|
||||||
value += str[i] - '0';
|
|
||||||
}
|
|
||||||
ok = true;
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum class VGAColor : byte {
|
enum class VGAColor : byte {
|
||||||
Black = 0,
|
Black = 0,
|
||||||
Blue,
|
Blue,
|
||||||
|
@ -324,7 +309,7 @@ void VirtualConsole::execute_escape_sequence(byte final)
|
||||||
Vector<unsigned> params;
|
Vector<unsigned> params;
|
||||||
for (auto& parampart : paramparts) {
|
for (auto& parampart : paramparts) {
|
||||||
bool ok;
|
bool ok;
|
||||||
unsigned value = parse_uint(parampart, ok);
|
unsigned value = parampart.to_uint(ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
// FIXME: Should we do something else?
|
// FIXME: Should we do something else?
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -4,25 +4,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <AK/AKString.h>
|
#include <AK/AKString.h>
|
||||||
|
|
||||||
static unsigned parse_uint(const String& str, bool& ok)
|
|
||||||
{
|
|
||||||
if (str.is_empty()) {
|
|
||||||
ok = false;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
unsigned value = 0;
|
|
||||||
for (int i = 0; i < str.length(); ++i) {
|
|
||||||
if (str[i] < '0' || str[i] > '9') {
|
|
||||||
ok = false;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
value = value * 10;
|
|
||||||
value += (unsigned)(str[i] - '0');
|
|
||||||
}
|
|
||||||
ok = true;
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void print_usage_and_exit()
|
static void print_usage_and_exit()
|
||||||
{
|
{
|
||||||
printf("usage: kill [-signal] <PID>\n");
|
printf("usage: kill [-signal] <PID>\n");
|
||||||
|
@ -40,13 +21,13 @@ int main(int argc, char** argv)
|
||||||
pid_argi = 2;
|
pid_argi = 2;
|
||||||
if (argv[1][0] != '-')
|
if (argv[1][0] != '-')
|
||||||
print_usage_and_exit();
|
print_usage_and_exit();
|
||||||
signum = parse_uint(&argv[1][1], ok);
|
signum = String(&argv[1][1]).to_uint(ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
printf("'%s' is not a valid signal number\n", &argv[1][1]);
|
printf("'%s' is not a valid signal number\n", &argv[1][1]);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unsigned pid = parse_uint(argv[pid_argi], ok);
|
unsigned pid = String(argv[pid_argi]).to_uint(ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
printf("'%s' is not a valid PID\n", argv[pid_argi]);
|
printf("'%s' is not a valid PID\n", argv[pid_argi]);
|
||||||
return 3;
|
return 3;
|
||||||
|
|
|
@ -3,21 +3,6 @@
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <AK/AKString.h>
|
#include <AK/AKString.h>
|
||||||
|
|
||||||
static unsigned parse_uint(const String& str, bool& ok)
|
|
||||||
{
|
|
||||||
unsigned value = 0;
|
|
||||||
for (int i = 0; i < str.length(); ++i) {
|
|
||||||
if (str[i] < '0' || str[i] > '9') {
|
|
||||||
ok = false;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
value = value * 10;
|
|
||||||
value += str[i] - '0';
|
|
||||||
}
|
|
||||||
ok = true;
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void handle_sigint(int)
|
void handle_sigint(int)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -29,7 +14,7 @@ int main(int argc, char** argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
bool ok;
|
bool ok;
|
||||||
unsigned secs = parse_uint(argv[1], ok);
|
unsigned secs = String(argv[1]).to_uint(ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
fprintf(stderr, "Not a valid number of seconds: \"%s\"\n", argv[1]);
|
fprintf(stderr, "Not a valid number of seconds: \"%s\"\n", argv[1]);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue