Przeglądaj źródła

str: faux_str_unclosed_quotes()

Serj Kalichev 1 rok temu
rodzic
commit
9a4c677117
3 zmienionych plików z 27 dodań i 0 usunięć
  1. 1 0
      faux/faux.map
  2. 1 0
      faux/str.h
  3. 25 0
      faux/str/str.c

+ 1 - 0
faux/faux.map

@@ -316,6 +316,7 @@ FAUX_2.0 {
 		faux_str_encode;
 		faux_str_equal_part;
 		faux_str_getline;
+		faux_str_unclosed_quotes;
 
 		faux_sysdb_getpwnam;
 		faux_sysdb_getpwuid;

+ 1 - 0
faux/str.h

@@ -47,6 +47,7 @@ char *faux_str_c_bin(const char *src, size_t n);
 char *faux_str_nextword(const char *str, const char **saveptr,
 	const char *alt_quotes, bool_t *qclosed);
 char *faux_str_getline(const char *str, const char **saveptr);
+bool_t faux_str_unclosed_quotes(const char *str, const char *alt_quotes);
 
 C_DECL_END
 

+ 25 - 0
faux/str/str.c

@@ -972,3 +972,28 @@ char *faux_str_getline(const char *str, const char **saveptr)
 
 	return faux_str_dup(str);
 }
+
+
+/** @brief Indicates if string has unclosed quotes.
+ *
+ * @param [in] str String to analyze.
+ * @return BOOL_TRUE if string has unclosed quotes, BOOL_FALSE if doesn't.
+ */
+bool_t faux_str_unclosed_quotes(const char *str, const char *alt_quotes)
+{
+	const char *saveptr = str;
+	char *word = NULL;
+
+	if (faux_str_is_empty(str))
+		return BOOL_FALSE;
+
+	do {
+		bool_t closed_quotes = BOOL_TRUE;
+		word = faux_str_nextword(saveptr, &saveptr, alt_quotes, &closed_quotes);
+		faux_str_free(word);
+		if (!closed_quotes)
+			return BOOL_TRUE;
+	} while (word);
+
+	return BOOL_FALSE;
+}