Ver código fonte

str: Add faux_str_has_content() function

Serj Kalichev 11 meses atrás
pai
commit
889e5b9700
3 arquivos alterados com 27 adições e 0 exclusões
  1. 1 0
      faux/faux.map
  2. 1 0
      faux/str.h
  3. 25 0
      faux/str/str.c

+ 1 - 0
faux/faux.map

@@ -312,6 +312,7 @@ FAUX_2.0 {
 		faux_str_charsn;
 		faux_str_chars;
 		faux_str_is_empty;
+		faux_str_has_content;
 		faux_str_c_esc;
 		faux_str_c_bin;
 		faux_str_nextword;

+ 1 - 0
faux/str.h

@@ -40,6 +40,7 @@ char *faux_str_casestr(const char *haystack, const char *needle);
 char *faux_str_charsn(const char *str, const char *chars_to_search, size_t n);
 char *faux_str_chars(const char *str, const char *chars_to_search);
 bool_t faux_str_is_empty(const char *str);
+bool_t faux_str_has_content(const char *str);
 
 char *faux_str_c_esc(const char *src);
 char *faux_str_c_bin(const char *src, size_t n);

+ 25 - 0
faux/str/str.c

@@ -997,3 +997,28 @@ bool_t faux_str_unclosed_quotes(const char *str, const char *alt_quotes)
 
 	return BOOL_FALSE;
 }
+
+
+/** @brief Indicates is string has content.
+ *
+ * Empty string has no content. String contains only spaces is considered
+ * doesn't have content too.
+ *
+ * @param [in] str String to analyze.
+ * @return BOOL_TRUE if string has content, BOOL_FALSE if doesn't.
+ */
+bool_t faux_str_has_content(const char *str)
+{
+	const char *l = str;
+
+	if (faux_str_is_empty(l))
+		return BOOL_FALSE;
+
+	while (*l) {
+		if (!isspace(*l))
+			return BOOL_TRUE;
+		l++;
+	}
+
+	return BOOL_FALSE;
+}