mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Util: add ffCharIsDigit and use it
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
#include "util/stringUtils.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
|
||||
static const char* detectWithBacklight(FFlist* result)
|
||||
@@ -58,14 +57,14 @@ static const char* detectWithBacklight(FFlist* result)
|
||||
{
|
||||
ffStrbufSubstrBeforeLastC(&brightness->name, '/'); // remove "/edid"
|
||||
ffStrbufSubstrAfterLastC(&brightness->name, '/'); // try getting DRM connector name
|
||||
if(isdigit(brightness->name.chars[0]))
|
||||
if(ffCharIsDigit(brightness->name.chars[0]))
|
||||
{
|
||||
// PCI address or some unknown path, give up
|
||||
ffStrbufSetS(&brightness->name, entry->d_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(ffStrbufStartsWithS(&brightness->name, "card") && isdigit(brightness->name.chars[4]))
|
||||
if(ffStrbufStartsWithS(&brightness->name, "card") && ffCharIsDigit(brightness->name.chars[4]))
|
||||
ffStrbufSubstrAfterFirstC(&brightness->name, '-');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <sys/sysinfo.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include "common/settings.h"
|
||||
@@ -139,7 +138,7 @@ static bool detectFrequency(FFCPUResult* cpu, const FFCPUOptions* options)
|
||||
struct dirent* entry;
|
||||
while ((entry = readdir(dir)) != NULL)
|
||||
{
|
||||
if (ffStrStartsWith(entry->d_name, "policy") && isdigit(entry->d_name[strlen("policy")]))
|
||||
if (ffStrStartsWith(entry->d_name, "policy") && ffCharIsDigit(entry->d_name[strlen("policy")]))
|
||||
{
|
||||
ffStrbufAppendS(&path, entry->d_name);
|
||||
uint32_t fbase = getFrequency(&path, "/base_frequency", NULL, &buffer);
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "util/mallocHelper.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -320,7 +319,7 @@ static const char* getFromProcesses(FFDisplayServerResult* result)
|
||||
while((dirent = readdir(procdir)) != NULL)
|
||||
{
|
||||
//Match only folders starting with a number (the pid folders)
|
||||
if(dirent->d_type != DT_DIR || !isdigit(dirent->d_name[0]))
|
||||
if(dirent->d_type != DT_DIR || !ffCharIsDigit(dirent->d_name[0]))
|
||||
continue;
|
||||
|
||||
ffStrbufAppendS(&procPath, dirent->d_name);
|
||||
|
||||
@@ -114,7 +114,7 @@ const char* ffDetectEditor(FFEditorResult* result)
|
||||
for (uint32_t iStart = 0; iStart < result->version.length; ++iStart)
|
||||
{
|
||||
char c = result->version.chars[iStart];
|
||||
if (c >= '0' && c <= '9')
|
||||
if (ffCharIsDigit(c))
|
||||
{
|
||||
for (uint32_t iEnd = iStart + 1; iEnd < result->version.length; ++iEnd)
|
||||
{
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
#include "common/io/io.h"
|
||||
#include "util/stringUtils.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
|
||||
static void detectGamepad(FFlist* devices, FFstrbuf* name, FFstrbuf* path)
|
||||
{
|
||||
uint32_t baseLen = path->length;
|
||||
@@ -71,7 +68,7 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
|
||||
{
|
||||
if (!ffStrStartsWith(entry->d_name, "js"))
|
||||
continue;
|
||||
if (!isdigit(entry->d_name[2]))
|
||||
if (!ffCharIsDigit(entry->d_name[2]))
|
||||
continue;
|
||||
|
||||
ffStrbufAppendS(&path, entry->d_name);
|
||||
|
||||
@@ -4,6 +4,7 @@ extern "C" {
|
||||
}
|
||||
#include "util/windows/unicode.hpp"
|
||||
#include "util/windows/wmi.hpp"
|
||||
#include "util/stringUtils.h"
|
||||
|
||||
static const char* getOsNameByWmi(FFstrbuf* osName)
|
||||
{
|
||||
@@ -73,8 +74,8 @@ void ffDetectOSImpl(FFOSResult* os)
|
||||
if(ffStrbufEndsWithC(&os->prettyName, 'r'))
|
||||
{
|
||||
if(os->variant.chars[0] == 'R' &&
|
||||
isdigit(os->variant.chars[1]) &&
|
||||
(os->variant.chars[2] == '\0' || os->variant.chars[2] == ' '))
|
||||
ffCharIsDigit(os->variant.chars[1]) &&
|
||||
(os->variant.chars[2] == '\0' || os->variant.chars[2] == ' '))
|
||||
{
|
||||
ffStrbufAppendF(&os->version, " R%c", os->variant.chars[1]);
|
||||
ffStrbufSubstrAfter(&os->variant, strlen("Rx ") - 1);
|
||||
|
||||
@@ -141,11 +141,11 @@ static bool isValidNixPkg(FFstrbuf* pkg)
|
||||
switch (state)
|
||||
{
|
||||
case START:
|
||||
if (c >= '0' && c <= '9')
|
||||
if (ffCharIsDigit(c))
|
||||
state = DIGIT;
|
||||
break;
|
||||
case DIGIT:
|
||||
if (c >= '0' && c <= '9')
|
||||
if (ffCharIsDigit(c))
|
||||
continue;
|
||||
if (c == '.')
|
||||
state = DOT;
|
||||
@@ -153,7 +153,7 @@ static bool isValidNixPkg(FFstrbuf* pkg)
|
||||
state = START;
|
||||
break;
|
||||
case DOT:
|
||||
if (c >= '0' && c <= '9')
|
||||
if (ffCharIsDigit(c))
|
||||
state = MATCH;
|
||||
else
|
||||
state = START;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#include "processes.h"
|
||||
|
||||
#include "common/io/io.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include "util/stringUtils.h"
|
||||
|
||||
const char* ffDetectProcesses(uint32_t* result)
|
||||
{
|
||||
@@ -15,7 +14,7 @@ const char* ffDetectProcesses(uint32_t* result)
|
||||
struct dirent* entry;
|
||||
while ((entry = readdir(dir)) != NULL)
|
||||
{
|
||||
if (entry->d_type == DT_DIR && isdigit(entry->d_name[0]))
|
||||
if (entry->d_type == DT_DIR && ffCharIsDigit(entry->d_name[0]))
|
||||
++num;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -113,7 +113,7 @@ void ffLogoPrintChars(const char* data, bool doColorReplacement)
|
||||
ffStrbufAppendS(&result, "\e[");
|
||||
data += 2;
|
||||
|
||||
while(isdigit(*data) || *data == ';')
|
||||
while(ffCharIsDigit(*data) || *data == ';')
|
||||
ffStrbufAppendC(&result, *data++); // number
|
||||
|
||||
//We have a valid control sequence, print it and continue with next char
|
||||
|
||||
@@ -74,3 +74,8 @@ static inline bool ffCharIsEnglishAlphabet(char c)
|
||||
{
|
||||
return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
|
||||
}
|
||||
|
||||
static inline bool ffCharIsDigit(char c)
|
||||
{
|
||||
return '0' <= c && c <= '9';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user