better naming of strbuf methods

This commit is contained in:
Linus Dierheimer
2021-06-26 15:34:01 +02:00
parent 19b71d9ce0
commit 582d5b6473
8 changed files with 57 additions and 47 deletions
+5 -7
View File
@@ -152,25 +152,23 @@ static void detectGTK(FFinstance* instance, const char* version, const char* env
FFstrbuf buffer;
ffStrbufInitA(&buffer, 128);
uint32_t lastIndex;
// From ENV: GTK*_RC_FILES
ffStrbufSetS(&buffer, getenv(envVariable));
lastIndex = 0;
while (lastIndex < buffer.length)
uint32_t startIndex = 0;
while (startIndex < buffer.length)
{
uint32_t colonIndex = ffStrbufFirstIndexAfterC(&buffer, lastIndex, ':');
uint32_t colonIndex = ffStrbufNextIndexC(&buffer, startIndex, ':');
buffer.chars[colonIndex] = '\0';
detectGTKFromConfigFile(buffer.chars + lastIndex, result);
detectGTKFromConfigFile(buffer.chars + startIndex, result);
if(allPropertiesSet(result))
{
ffStrbufDestroy(&buffer);
return;
}
lastIndex = colonIndex + 1;
startIndex = colonIndex + 1;
}
//From DConf / GSettings
+2 -2
View File
@@ -210,7 +210,7 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, const FFst
}
// fastforward to the end of the if without printing the in between
i = ffStrbufFirstIndexAfterS(formatstr, i, "{?}") + 2; // 2 is the length of "{?}" -1 because the loop will increament it again directly after continue
i = ffStrbufNextIndexS(formatstr, i, "{?}") + 2; // 2 is the length of "{?}" - 1 because the loop will increament it again directly after continue
ffStrbufDestroy(&placeholderValue);
continue;
}
@@ -247,7 +247,7 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, const FFst
}
// fastforward to the end of the if without printing the in between
i = ffStrbufFirstIndexAfterS(formatstr, i, "{/}") + 2; // 2 is the length of "{/}" -1 because the loop will increament it again directly after continue
i = ffStrbufNextIndexS(formatstr, i, "{/}") + 2; // 2 is the length of "{/}" - 1 because the loop will increament it again directly after continue
ffStrbufDestroy(&placeholderValue);
continue;
}
+8 -6
View File
@@ -22,19 +22,21 @@ static void initConfigDirs(FFstate* state)
}
FFstrbuf xdgConfigDirs;
ffStrbufInitAS(&xdgConfigDirs, 64, getenv("XDG_CONFIG_DIRS"));
uint32_t lastIndex = 0;
while (lastIndex < xdgConfigDirs.length)
ffStrbufInitA(&xdgConfigDirs, 64);
ffStrbufAppendS(&xdgConfigDirs, getenv("XDG_CONFIG_DIRS"));
uint32_t startIndex = 0;
while (startIndex < xdgConfigDirs.length)
{
uint32_t colonIndex = ffStrbufFirstIndexAfterC(&xdgConfigDirs, lastIndex, ':');
uint32_t colonIndex = ffStrbufNextIndexC(&xdgConfigDirs, startIndex, ':');
xdgConfigDirs.chars[colonIndex] = '\0';
FFstrbuf* buffer = (FFstrbuf*) ffListAdd(&state->configDirs);
ffStrbufInitA(buffer, 64);
ffStrbufAppendS(buffer, xdgConfigDirs.chars + lastIndex);
ffStrbufAppendS(buffer, xdgConfigDirs.chars + startIndex);
ffStrbufTrimRight(buffer, '/');
lastIndex = colonIndex + 1;
startIndex = colonIndex + 1;
}
#define FF_ENSURE_ONLY_ONCE_IN_LIST(element) \
+10 -10
View File
@@ -128,14 +128,14 @@ static bool printCachedValue(FFinstance* instance, const char* moduleName, const
uint8_t moduleCounter = 1;
uint32_t lastIndex = 0;
while(lastIndex < content.length)
uint32_t startIndex = 0;
while(startIndex < content.length)
{
uint32_t nullByteIndex = ffStrbufFirstIndexAfterC(&content, lastIndex, '\0');
uint32_t nullByteIndex = ffStrbufNextIndexC(&content, startIndex, '\0');
uint8_t moduleIndex = (moduleCounter == 1 && nullByteIndex == content.length) ? 0 : moduleCounter;
ffPrintLogoAndKey(instance, moduleName, moduleIndex, customKeyFormat);
puts(content.chars + lastIndex);
lastIndex = nullByteIndex + 1;
puts(content.chars + startIndex);
startIndex = nullByteIndex + 1;
++moduleCounter;
}
@@ -160,14 +160,14 @@ static bool printCachedFormat(FFinstance* instance, const char* moduleName, cons
FFformatarg* arguments = calloc(numArgs, sizeof(FFformatarg));
uint32_t argumentCounter = 0;
uint32_t lastIndex = 0;
while(lastIndex < content.length)
uint32_t startIndex = 0;
while(startIndex < content.length)
{
arguments[argumentCounter].type = FF_FORMAT_ARG_TYPE_STRING;
arguments[argumentCounter].value = &content.chars[lastIndex];
arguments[argumentCounter].value = &content.chars[startIndex];
++argumentCounter;
uint32_t nullByteIndex = ffStrbufFirstIndexAfterC(&content, lastIndex, '\0');
uint32_t nullByteIndex = ffStrbufNextIndexC(&content, startIndex, '\0');
if(argumentCounter == numArgs)
{
@@ -177,7 +177,7 @@ static bool printCachedFormat(FFinstance* instance, const char* moduleName, cons
argumentCounter = 0;
}
lastIndex = nullByteIndex + 1;
startIndex = nullByteIndex + 1;
}
free(arguments);
+5 -5
View File
@@ -1079,15 +1079,15 @@ static void run(FFinstance* instance, FFdata* data)
ffStart(instance);
uint32_t lastIndex = 0;
while (lastIndex < data->structure.length)
uint32_t startIndex = 0;
while (startIndex < data->structure.length)
{
uint32_t colonIndex = ffStrbufFirstIndexAfterC(&data->structure, lastIndex, ':');
uint32_t colonIndex = ffStrbufNextIndexC(&data->structure, startIndex, ':');
data->structure.chars[colonIndex] = '\0';
parseStructureCommand(instance, data, data->structure.chars + lastIndex);
parseStructureCommand(instance, data, data->structure.chars + startIndex);
lastIndex = colonIndex + 1;
startIndex = colonIndex + 1;
}
ffFinish(instance);
+5 -5
View File
@@ -114,15 +114,15 @@ void ffPrintDisk(FFinstance* instance)
return;
}
uint32_t lastIndex = 0;
while (lastIndex < instance->config.diskFolders.length)
uint32_t startIndex = 0;
while (startIndex < instance->config.diskFolders.length)
{
uint32_t colonIndex = ffStrbufFirstIndexAfterC(&instance->config.diskFolders, lastIndex, ':');
uint32_t colonIndex = ffStrbufNextIndexC(&instance->config.diskFolders, startIndex, ':');
instance->config.diskFolders.chars[colonIndex] = '\0';
printFolder(instance, instance->config.diskFolders.chars + lastIndex);
printFolder(instance, instance->config.diskFolders.chars + startIndex);
lastIndex = colonIndex + 1;
startIndex = colonIndex + 1;
}
}
}
+17 -8
View File
@@ -381,7 +381,7 @@ void ffStrbufRemoveStrings(FFstrbuf* strbuf, uint32_t numStrings, ...)
va_end(argp);
}
uint32_t ffStrbufFirstIndexAfterC(const FFstrbuf* strbuf, uint32_t start, const char c)
uint32_t ffStrbufNextIndexC(const FFstrbuf* strbuf, uint32_t start, char c)
{
for(uint32_t i = start; i < strbuf->length; i++)
{
@@ -391,14 +391,14 @@ uint32_t ffStrbufFirstIndexAfterC(const FFstrbuf* strbuf, uint32_t start, const
return strbuf->length;
}
uint32_t ffStrbufFirstIndexC(const FFstrbuf* strbuf, const char c)
uint32_t ffStrbufFirstIndexC(const FFstrbuf* strbuf, char c)
{
return ffStrbufFirstIndexAfterC(strbuf, 0, c);
return ffStrbufNextIndexC(strbuf, 0, c);
}
uint32_t ffStrbufFirstIndexAfterS(const FFstrbuf* strbuf, uint32_t start, const char* str)
uint32_t ffStrbufNextIndexS(const FFstrbuf* strbuf, uint32_t start, const char* str)
{
for(uint32_t i = start + 1; i < strbuf->length; i++)
for(uint32_t i = start; i < strbuf->length; i++)
{
bool found = true;
@@ -417,18 +417,22 @@ uint32_t ffStrbufFirstIndexAfterS(const FFstrbuf* strbuf, uint32_t start, const
if(found)
return i;
}
return strbuf->length;
}
uint32_t ffStrbufFirstIndexS(const FFstrbuf* strbuf, const char* str)
{
return ffStrbufFirstIndexAfterS(strbuf, 0, str);
return ffStrbufNextIndexS(strbuf, 0, str);
}
uint32_t ffStrbufLastIndexC(const FFstrbuf* strbuf, const char c)
uint32_t ffStrbufPreviousIndexC(const FFstrbuf* strbuf, uint32_t start, char c)
{
if(start >= strbuf->length)
return strbuf->length;
//We need to loop one higher than the actual index, because uint32_t is guranteed to be >= 0, so this statement would always be true
for(uint32_t i = strbuf->length; i > 0; i--)
for(uint32_t i = start + 1; i > 0; i--)
{
if(strbuf->chars[i - 1] == c)
return i - 1;
@@ -436,6 +440,11 @@ uint32_t ffStrbufLastIndexC(const FFstrbuf* strbuf, const char c)
return strbuf->length;
}
uint32_t ffStrbufLastIndexC(const FFstrbuf* strbuf, char c)
{
return ffStrbufPreviousIndexC(strbuf, strbuf->length - 1, c);
}
void ffStrbufSubstrBefore(FFstrbuf* strbuf, uint32_t index)
{
if(strbuf->length <= index)
+5 -4
View File
@@ -72,11 +72,12 @@ void ffStrbufRemoveStringsA(FFstrbuf* strbuf, uint32_t numStrings, const char* s
void ffStrbufRemoveStringsV(FFstrbuf* strbuf, uint32_t numStrings, va_list arguments);
void ffStrbufRemoveStrings(FFstrbuf* strbuf, uint32_t numStrings, ...);
uint32_t ffStrbufFirstIndexAfterC(const FFstrbuf* strbuf, uint32_t start, const char c);
uint32_t ffStrbufFirstIndexC(const FFstrbuf* strbuf, const char c);
uint32_t ffStrbufFirstIndexAfterS(const FFstrbuf* strbuf, uint32_t start, const char* str);
uint32_t ffStrbufNextIndexC(const FFstrbuf* strbuf, uint32_t start, char c);
uint32_t ffStrbufFirstIndexC(const FFstrbuf* strbuf, char c);
uint32_t ffStrbufNextIndexS(const FFstrbuf* strbuf, uint32_t start, const char* str);
uint32_t ffStrbufFirstIndexS(const FFstrbuf* strbuf, const char* str);
uint32_t ffStrbufLastIndexC(const FFstrbuf* strbuf, const char c);
uint32_t ffStrbufPreviousIndexC(const FFstrbuf* strbuf, uint32_t start, char c);
uint32_t ffStrbufLastIndexC(const FFstrbuf* strbuf, char c);
void ffStrbufSubstrBefore(FFstrbuf* strbuf, uint32_t index);
void ffStrbufSubstrBeforeFirstC(FFstrbuf* strbuf, const char c);