Skip to content

Commit 3ba8992

Browse files
committed
Util: add ffCharIsDigit and use it
1 parent 5fa18a8 commit 3ba8992

File tree

10 files changed

+20
-21
lines changed

10 files changed

+20
-21
lines changed

src/detection/brightness/brightness_linux.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "util/stringUtils.h"
55

66
#include <dirent.h>
7-
#include <ctype.h>
87
#include <limits.h>
98

109
static const char* detectWithBacklight(FFlist* result)
@@ -58,14 +57,14 @@ static const char* detectWithBacklight(FFlist* result)
5857
{
5958
ffStrbufSubstrBeforeLastC(&brightness->name, '/'); // remove "/edid"
6059
ffStrbufSubstrAfterLastC(&brightness->name, '/'); // try getting DRM connector name
61-
if(isdigit(brightness->name.chars[0]))
60+
if(ffCharIsDigit(brightness->name.chars[0]))
6261
{
6362
// PCI address or some unknown path, give up
6463
ffStrbufSetS(&brightness->name, entry->d_name);
6564
}
6665
else
6766
{
68-
if(ffStrbufStartsWithS(&brightness->name, "card") && isdigit(brightness->name.chars[4]))
67+
if(ffStrbufStartsWithS(&brightness->name, "card") && ffCharIsDigit(brightness->name.chars[4]))
6968
ffStrbufSubstrAfterFirstC(&brightness->name, '-');
7069
}
7170
}

src/detection/cpu/cpu_linux.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <sys/sysinfo.h>
1010
#include <stdlib.h>
1111
#include <unistd.h>
12-
#include <ctype.h>
1312

1413
#ifdef __ANDROID__
1514
#include "common/settings.h"
@@ -139,7 +138,7 @@ static bool detectFrequency(FFCPUResult* cpu, const FFCPUOptions* options)
139138
struct dirent* entry;
140139
while ((entry = readdir(dir)) != NULL)
141140
{
142-
if (ffStrStartsWith(entry->d_name, "policy") && isdigit(entry->d_name[strlen("policy")]))
141+
if (ffStrStartsWith(entry->d_name, "policy") && ffCharIsDigit(entry->d_name[strlen("policy")]))
143142
{
144143
ffStrbufAppendS(&path, entry->d_name);
145144
uint32_t fbase = getFrequency(&path, "/base_frequency", NULL, &buffer);

src/detection/displayserver/linux/wmde.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "util/mallocHelper.h"
55

66
#include <stdlib.h>
7-
#include <ctype.h>
87
#include <string.h>
98
#include <unistd.h>
109

@@ -320,7 +319,7 @@ static const char* getFromProcesses(FFDisplayServerResult* result)
320319
while((dirent = readdir(procdir)) != NULL)
321320
{
322321
//Match only folders starting with a number (the pid folders)
323-
if(dirent->d_type != DT_DIR || !isdigit(dirent->d_name[0]))
322+
if(dirent->d_type != DT_DIR || !ffCharIsDigit(dirent->d_name[0]))
324323
continue;
325324

326325
ffStrbufAppendS(&procPath, dirent->d_name);

src/detection/editor/editor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const char* ffDetectEditor(FFEditorResult* result)
114114
for (uint32_t iStart = 0; iStart < result->version.length; ++iStart)
115115
{
116116
char c = result->version.chars[iStart];
117-
if (c >= '0' && c <= '9')
117+
if (ffCharIsDigit(c))
118118
{
119119
for (uint32_t iEnd = iStart + 1; iEnd < result->version.length; ++iEnd)
120120
{

src/detection/gamepad/gamepad_linux.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
#include "common/io/io.h"
33
#include "util/stringUtils.h"
44

5-
#include <dirent.h>
6-
#include <ctype.h>
7-
85
static void detectGamepad(FFlist* devices, FFstrbuf* name, FFstrbuf* path)
96
{
107
uint32_t baseLen = path->length;
@@ -71,7 +68,7 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
7168
{
7269
if (!ffStrStartsWith(entry->d_name, "js"))
7370
continue;
74-
if (!isdigit(entry->d_name[2]))
71+
if (!ffCharIsDigit(entry->d_name[2]))
7572
continue;
7673

7774
ffStrbufAppendS(&path, entry->d_name);

src/detection/os/os_windows.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ extern "C" {
44
}
55
#include "util/windows/unicode.hpp"
66
#include "util/windows/wmi.hpp"
7+
#include "util/stringUtils.h"
78

89
static const char* getOsNameByWmi(FFstrbuf* osName)
910
{
@@ -73,8 +74,8 @@ void ffDetectOSImpl(FFOSResult* os)
7374
if(ffStrbufEndsWithC(&os->prettyName, 'r'))
7475
{
7576
if(os->variant.chars[0] == 'R' &&
76-
isdigit(os->variant.chars[1]) &&
77-
(os->variant.chars[2] == '\0' || os->variant.chars[2] == ' '))
77+
ffCharIsDigit(os->variant.chars[1]) &&
78+
(os->variant.chars[2] == '\0' || os->variant.chars[2] == ' '))
7879
{
7980
ffStrbufAppendF(&os->version, " R%c", os->variant.chars[1]);
8081
ffStrbufSubstrAfter(&os->variant, strlen("Rx ") - 1);

src/detection/packages/packages_linux.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,19 @@ static bool isValidNixPkg(FFstrbuf* pkg)
141141
switch (state)
142142
{
143143
case START:
144-
if (c >= '0' && c <= '9')
144+
if (ffCharIsDigit(c))
145145
state = DIGIT;
146146
break;
147147
case DIGIT:
148-
if (c >= '0' && c <= '9')
148+
if (ffCharIsDigit(c))
149149
continue;
150150
if (c == '.')
151151
state = DOT;
152152
else
153153
state = START;
154154
break;
155155
case DOT:
156-
if (c >= '0' && c <= '9')
156+
if (ffCharIsDigit(c))
157157
state = MATCH;
158158
else
159159
state = START;

src/detection/processes/processes_linux.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#include "processes.h"
22

33
#include "common/io/io.h"
4-
5-
#include <ctype.h>
4+
#include "util/stringUtils.h"
65

76
const char* ffDetectProcesses(uint32_t* result)
87
{
@@ -15,7 +14,7 @@ const char* ffDetectProcesses(uint32_t* result)
1514
struct dirent* entry;
1615
while ((entry = readdir(dir)) != NULL)
1716
{
18-
if (entry->d_type == DT_DIR && isdigit(entry->d_name[0]))
17+
if (entry->d_type == DT_DIR && ffCharIsDigit(entry->d_name[0]))
1918
++num;
2019
}
2120

src/logo/logo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void ffLogoPrintChars(const char* data, bool doColorReplacement)
113113
ffStrbufAppendS(&result, "\e[");
114114
data += 2;
115115

116-
while(isdigit(*data) || *data == ';')
116+
while(ffCharIsDigit(*data) || *data == ';')
117117
ffStrbufAppendC(&result, *data++); // number
118118

119119
//We have a valid control sequence, print it and continue with next char

src/util/stringUtils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,8 @@ static inline bool ffCharIsEnglishAlphabet(char c)
7474
{
7575
return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
7676
}
77+
78+
static inline bool ffCharIsDigit(char c)
79+
{
80+
return '0' <= c && c <= '9';
81+
}

0 commit comments

Comments
 (0)