Browse Source

faux.str: Test for faux_str_nextword(). Doesn't work yet.

Serj Kalichev 3 years ago
parent
commit
6a6b4a6bd1
5 changed files with 29 additions and 10 deletions
  1. 2 2
      faux/argv/argv.c
  2. 3 3
      faux/str.h
  3. 1 1
      faux/str/str.c
  4. 17 1
      faux/str/testc_str.c
  5. 6 3
      faux/testc_module/testc_module.c

+ 2 - 2
faux/argv/argv.c

@@ -106,7 +106,7 @@ void faux_argv_quotes(faux_argv_t *fargv, const char *quotes)
 	fargv->quotes = faux_str_dup(quotes);
 }
 
-
+/*
 ssize_t faux_argv_parse_str(faux_argv_t *fargv, const char *str)
 {
 	assert(fargv);
@@ -116,4 +116,4 @@ ssize_t faux_argv_parse_str(faux_argv_t *fargv, const char *str)
 
 	return 0;
 }
-
+*/

+ 3 - 3
faux/str.h

@@ -38,6 +38,9 @@ char *faux_str_chars(const char *str, const char *chars_to_search);
 char *faux_str_c_esc(const char *src);
 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);
+
 
 //const char *faux_str_suffix(const char *string);
 /*
@@ -57,9 +60,6 @@ char *faux_str_c_bin(const char *src, size_t n);
 //char *faux_str_encode(const char *string, const char *escape_chars);
 //unsigned int faux_str_equal_part(const char *str1, const char *str2,
 //	bool_t utf8);
-//const char *faux_str_nextword(const char *string,
-//	size_t *len, size_t *offset, size_t *quoted);
-//unsigned int faux_str_wordcount(const char *line);
 
 C_DECL_END
 

+ 1 - 1
faux/str/str.c

@@ -706,7 +706,7 @@ char *faux_str_nextword(const char *str, const char **saveptr,
 				word = string;
 				len = 0;
 			// Start of alt quoted string
-			} else if ((p = strchr(alt_quotes, *string))) {
+			} else if (alt_quotes && (p = strchr(alt_quotes, *string))) {
 				if (len > 0) {
 					char *s = faux_str_deesc(word, len);
 					faux_str_cat(&result, s);

+ 17 - 1
faux/str/testc_str.c

@@ -1,11 +1,27 @@
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
 
 #include "faux/str.h"
 
 
 int testc_faux_str_nextword(void)
 {
+	const char* line = "asd\"\\\"\"mmm   lll";
+	const char* etalon = "asd\"mmm";
+	char *res = NULL;
+	int retval = -1;
 
-	return 0;
+	printf("Line   : [%s]\n", line);
+	printf("Etalon : [%s]\n", etalon);
+
+	res = faux_str_nextword(line, NULL, NULL);
+	if (!res)
+		printf("The faux_str_nextword() return value is NULL\n");
+	else
+		printf("Result : [%s]\n", res);
+	retval = strcmp(etalon, res);
+	faux_str_free(res);
+
+	return retval;
 }

+ 6 - 3
faux/testc_module/testc_module.c

@@ -6,9 +6,12 @@ const unsigned char testc_version_minor = 0;
 const char *testc_module[][2] = {
 
 	// Demo
-	{"testc_faux_ini_bad", "INI bad"}, // demo
-	{"testc_faux_ini_signal", "Interrupted by signal"}, // demo
-	{"testc_faux_ini_good", "INI subsystem good"}, // demo
+//	{"testc_faux_ini_bad", "INI bad"}, // demo
+//	{"testc_faux_ini_signal", "Interrupted by signal"}, // demo
+//	{"testc_faux_ini_good", "INI subsystem good"}, // demo
+
+	// Str
+	{"testc_faux_str_nextword", "Find next word (quotation)"},
 
 	// INI
 	{"testc_faux_ini_parse_file", "Complex test of INI file parsing"},