mirror of
https://github.com/swaywm/sway.git
synced 2026-04-29 06:46:22 -04:00
stringop: Add is_empty() for checking for empty strings
This commit is contained in:
parent
22f37db15e
commit
69c7062f15
2 changed files with 23 additions and 0 deletions
|
|
@ -293,6 +293,24 @@ static bool has_whitespace(const char *str) {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns true if the string contains only whitespace and false otherwise.
|
||||
*/
|
||||
bool is_empty(const char *str) {
|
||||
bool ret = true;
|
||||
if (str) {
|
||||
while (*str != '\0') {
|
||||
if (!isspace(*(const unsigned char*)str)) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add quotes around any argv with whitespaces.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#ifndef _SWAY_STRINGOP_H
|
||||
#define _SWAY_STRINGOP_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "list.h"
|
||||
|
||||
#if !HAVE_DECL_SETENV
|
||||
|
|
@ -14,6 +16,9 @@ void strip_whitespace(char *str);
|
|||
char *strip_comments(char *str);
|
||||
void strip_quotes(char *str);
|
||||
|
||||
// Returns true if the string contains only whitespace.
|
||||
bool is_empty(const char *str);
|
||||
|
||||
// strcmp that also handles null pointers.
|
||||
int lenient_strcmp(char *a, char *b);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue