mirror of
https://github.com/weechat/weechat.git
synced 2026-07-06 09:43:13 +02:00
api: add argument "strip_items" in function string_split
This commit is contained in:
@@ -1011,29 +1011,29 @@ TEST(CoreString, Split)
|
||||
char **argv;
|
||||
int argc, flags;
|
||||
|
||||
POINTERS_EQUAL(NULL, string_split (NULL, NULL, 0, 0, NULL));
|
||||
POINTERS_EQUAL(NULL, string_split (NULL, "", 0, 0, NULL));
|
||||
POINTERS_EQUAL(NULL, string_split ("", NULL, 0, 0, NULL));
|
||||
POINTERS_EQUAL(NULL, string_split ("", "", 0, 0, NULL));
|
||||
POINTERS_EQUAL(NULL, string_split (NULL, NULL, NULL, 0, 0, NULL));
|
||||
POINTERS_EQUAL(NULL, string_split (NULL, "", NULL, 0, 0, NULL));
|
||||
POINTERS_EQUAL(NULL, string_split ("", NULL, NULL, 0, 0, NULL));
|
||||
POINTERS_EQUAL(NULL, string_split ("", "", NULL, 0, 0, NULL));
|
||||
|
||||
flags = WEECHAT_STRING_SPLIT_STRIP_LEFT
|
||||
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
|
||||
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
|
||||
|
||||
argc = -1;
|
||||
POINTERS_EQUAL(NULL, string_split (NULL, NULL, flags, 0, &argc));
|
||||
POINTERS_EQUAL(NULL, string_split (NULL, NULL, NULL, flags, 0, &argc));
|
||||
LONGS_EQUAL(0, argc);
|
||||
argc = -1;
|
||||
POINTERS_EQUAL(NULL, string_split (NULL, "", flags, 0, &argc));
|
||||
POINTERS_EQUAL(NULL, string_split (NULL, "", NULL, flags, 0, &argc));
|
||||
LONGS_EQUAL(0, argc);
|
||||
argc = -1;
|
||||
POINTERS_EQUAL(NULL, string_split ("", NULL, flags, 0, &argc));
|
||||
POINTERS_EQUAL(NULL, string_split ("", NULL, NULL, flags, 0, &argc));
|
||||
LONGS_EQUAL(0, argc);
|
||||
argc = -1;
|
||||
POINTERS_EQUAL(NULL, string_split ("", "", flags, 0, &argc));
|
||||
POINTERS_EQUAL(NULL, string_split ("", "", NULL, flags, 0, &argc));
|
||||
LONGS_EQUAL(0, argc);
|
||||
argc = -1;
|
||||
POINTERS_EQUAL(NULL, string_split (" ", " ", flags, 0, &argc));
|
||||
POINTERS_EQUAL(NULL, string_split (" ", " ", NULL, flags, 0, &argc));
|
||||
LONGS_EQUAL(0, argc);
|
||||
|
||||
/* free split with NULL */
|
||||
@@ -1044,7 +1044,7 @@ TEST(CoreString, Split)
|
||||
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
|
||||
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
|
||||
argc = -1;
|
||||
argv = string_split ("abc de fghi", " ", flags, 0, &argc);
|
||||
argv = string_split ("abc de fghi", " ", NULL, flags, 0, &argc);
|
||||
LONGS_EQUAL(3, argc);
|
||||
CHECK(argv);
|
||||
STRCMP_EQUAL("abc", argv[0]);
|
||||
@@ -1058,7 +1058,7 @@ TEST(CoreString, Split)
|
||||
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
|
||||
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
|
||||
argc = -1;
|
||||
argv = string_split (" abc de fghi ", " ", flags, 0, &argc);
|
||||
argv = string_split (" abc de fghi ", " ", NULL, flags, 0, &argc);
|
||||
LONGS_EQUAL(3, argc);
|
||||
CHECK(argv);
|
||||
STRCMP_EQUAL("abc", argv[0]);
|
||||
@@ -1072,7 +1072,7 @@ TEST(CoreString, Split)
|
||||
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
|
||||
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
|
||||
argc = -1;
|
||||
argv = string_split (" abc de fghi ", " ", flags, 2, &argc);
|
||||
argv = string_split (" abc de fghi ", " ", NULL, flags, 2, &argc);
|
||||
LONGS_EQUAL(2, argc);
|
||||
CHECK(argv);
|
||||
STRCMP_EQUAL("abc", argv[0]);
|
||||
@@ -1086,7 +1086,7 @@ TEST(CoreString, Split)
|
||||
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS
|
||||
| WEECHAT_STRING_SPLIT_KEEP_EOL;
|
||||
argc = -1;
|
||||
argv = string_split (" abc de fghi ", " ", flags, 0, &argc);
|
||||
argv = string_split (" abc de fghi ", " ", NULL, flags, 0, &argc);
|
||||
LONGS_EQUAL(3, argc);
|
||||
CHECK(argv);
|
||||
STRCMP_EQUAL("abc de fghi", argv[0]);
|
||||
@@ -1101,7 +1101,7 @@ TEST(CoreString, Split)
|
||||
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS
|
||||
| WEECHAT_STRING_SPLIT_KEEP_EOL;
|
||||
argc = -1;
|
||||
argv = string_split (" abc de fghi ", " ", flags, 2, &argc);
|
||||
argv = string_split (" abc de fghi ", " ", NULL, flags, 2, &argc);
|
||||
LONGS_EQUAL(2, argc);
|
||||
CHECK(argv);
|
||||
STRCMP_EQUAL("abc de fghi", argv[0]);
|
||||
@@ -1114,7 +1114,7 @@ TEST(CoreString, Split)
|
||||
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS
|
||||
| WEECHAT_STRING_SPLIT_KEEP_EOL;
|
||||
argc = -1;
|
||||
argv = string_split (" abc de fghi ", " ", flags, 0, &argc);
|
||||
argv = string_split (" abc de fghi ", " ", NULL, flags, 0, &argc);
|
||||
LONGS_EQUAL(3, argc);
|
||||
CHECK(argv);
|
||||
STRCMP_EQUAL("abc de fghi ", argv[0]);
|
||||
@@ -1128,7 +1128,7 @@ TEST(CoreString, Split)
|
||||
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS
|
||||
| WEECHAT_STRING_SPLIT_KEEP_EOL;
|
||||
argc = -1;
|
||||
argv = string_split (" abc de fghi ", " ", flags, 2, &argc);
|
||||
argv = string_split (" abc de fghi ", " ", NULL, flags, 2, &argc);
|
||||
LONGS_EQUAL(2, argc);
|
||||
CHECK(argv);
|
||||
STRCMP_EQUAL("abc de fghi ", argv[0]);
|
||||
@@ -1141,7 +1141,7 @@ TEST(CoreString, Split)
|
||||
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
|
||||
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
|
||||
argc = -1;
|
||||
argv = string_split ("abc,de,fghi", ",", flags, 0, &argc);
|
||||
argv = string_split ("abc,de,fghi", ",", NULL, flags, 0, &argc);
|
||||
LONGS_EQUAL(3, argc);
|
||||
CHECK(argv);
|
||||
STRCMP_EQUAL("abc", argv[0]);
|
||||
@@ -1150,12 +1150,64 @@ TEST(CoreString, Split)
|
||||
POINTERS_EQUAL(NULL, argv[3]);
|
||||
string_free_split (argv);
|
||||
|
||||
/*
|
||||
* standard split with comma separator,
|
||||
* strip_items set to empty string (ignored)
|
||||
*/
|
||||
flags = WEECHAT_STRING_SPLIT_STRIP_LEFT
|
||||
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
|
||||
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
|
||||
argc = -1;
|
||||
argv = string_split (" abc ,, de ,fghi ,,", ",", "", flags, 0, &argc);
|
||||
LONGS_EQUAL(3, argc);
|
||||
CHECK(argv);
|
||||
STRCMP_EQUAL(" abc ", argv[0]);
|
||||
STRCMP_EQUAL(" de ", argv[1]);
|
||||
STRCMP_EQUAL("fghi ", argv[2]);
|
||||
POINTERS_EQUAL(NULL, argv[3]);
|
||||
string_free_split (argv);
|
||||
|
||||
/*
|
||||
* standard split with comma separator,
|
||||
* strip spaces in items (left/right)
|
||||
*/
|
||||
flags = WEECHAT_STRING_SPLIT_STRIP_LEFT
|
||||
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
|
||||
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
|
||||
argc = -1;
|
||||
argv = string_split (" abc ,, de ,fghi ,,", ",", " ", flags, 0, &argc);
|
||||
LONGS_EQUAL(3, argc);
|
||||
CHECK(argv);
|
||||
STRCMP_EQUAL("abc", argv[0]);
|
||||
STRCMP_EQUAL("de", argv[1]);
|
||||
STRCMP_EQUAL("fghi", argv[2]);
|
||||
POINTERS_EQUAL(NULL, argv[3]);
|
||||
string_free_split (argv);
|
||||
|
||||
/*
|
||||
* standard split with comma separator,
|
||||
* strip spaces and parentheses in items (left/right)
|
||||
*/
|
||||
flags = WEECHAT_STRING_SPLIT_STRIP_LEFT
|
||||
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
|
||||
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
|
||||
argc = -1;
|
||||
argv = string_split (" abc ,, (de) ,(f(g)hi) ,,", ",", " ()",
|
||||
flags, 0, &argc);
|
||||
LONGS_EQUAL(3, argc);
|
||||
CHECK(argv);
|
||||
STRCMP_EQUAL("abc", argv[0]);
|
||||
STRCMP_EQUAL("de", argv[1]);
|
||||
STRCMP_EQUAL("f(g)hi", argv[2]);
|
||||
POINTERS_EQUAL(NULL, argv[3]);
|
||||
string_free_split (argv);
|
||||
|
||||
/* standard split with comma separator and empty item (ignore this item) */
|
||||
flags = WEECHAT_STRING_SPLIT_STRIP_LEFT
|
||||
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
|
||||
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
|
||||
argc = -1;
|
||||
argv = string_split ("abc,,fghi", ",", flags, 0, &argc);
|
||||
argv = string_split ("abc,,fghi", ",", NULL, flags, 0, &argc);
|
||||
LONGS_EQUAL(2, argc);
|
||||
CHECK(argv);
|
||||
STRCMP_EQUAL("abc", argv[0]);
|
||||
@@ -1166,7 +1218,7 @@ TEST(CoreString, Split)
|
||||
/* standard split with comma separtor and empty item (keep this item) */
|
||||
flags = 0;
|
||||
argc = -1;
|
||||
argv = string_split ("abc,,fghi", ",", flags, 0, &argc);
|
||||
argv = string_split ("abc,,fghi", ",", NULL, flags, 0, &argc);
|
||||
LONGS_EQUAL(3, argc);
|
||||
CHECK(argv);
|
||||
STRCMP_EQUAL("abc", argv[0]);
|
||||
@@ -1178,7 +1230,7 @@ TEST(CoreString, Split)
|
||||
/* standard split with comma separtor and empty items (keep them) */
|
||||
flags = 0;
|
||||
argc = -1;
|
||||
argv = string_split (",abc,,fghi,", ",", flags, 0, &argc);
|
||||
argv = string_split (",abc,,fghi,", ",", NULL, flags, 0, &argc);
|
||||
LONGS_EQUAL(5, argc);
|
||||
CHECK(argv);
|
||||
STRCMP_EQUAL("", argv[0]);
|
||||
@@ -1195,7 +1247,7 @@ TEST(CoreString, Split)
|
||||
*/
|
||||
flags = 0;
|
||||
argc = -1;
|
||||
argv = string_split (",abc,,fghi,", ",", flags, 2, &argc);
|
||||
argv = string_split (",abc,,fghi,", ",", NULL, flags, 2, &argc);
|
||||
LONGS_EQUAL(2, argc);
|
||||
CHECK(argv);
|
||||
STRCMP_EQUAL("", argv[0]);
|
||||
@@ -1209,7 +1261,7 @@ TEST(CoreString, Split)
|
||||
*/
|
||||
flags = 0;
|
||||
argc = -1;
|
||||
argv = string_split (",abc,,fghi,", ",", flags, 3, &argc);
|
||||
argv = string_split (",abc,,fghi,", ",", NULL, flags, 3, &argc);
|
||||
LONGS_EQUAL(3, argc);
|
||||
CHECK(argv);
|
||||
STRCMP_EQUAL("", argv[0]);
|
||||
@@ -1224,7 +1276,7 @@ TEST(CoreString, Split)
|
||||
*/
|
||||
flags = 0;
|
||||
argc = -1;
|
||||
argv = string_split (",abc,,fghi,", ",", flags, 4, &argc);
|
||||
argv = string_split (",abc,,fghi,", ",", NULL, flags, 4, &argc);
|
||||
LONGS_EQUAL(4, argc);
|
||||
CHECK(argv);
|
||||
STRCMP_EQUAL("", argv[0]);
|
||||
@@ -1250,15 +1302,19 @@ TEST(CoreString, SplitShared)
|
||||
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
|
||||
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
|
||||
|
||||
POINTERS_EQUAL(NULL, string_split_shared (NULL, NULL, flags, 0, NULL));
|
||||
POINTERS_EQUAL(NULL, string_split_shared (NULL, "", flags, 0, NULL));
|
||||
POINTERS_EQUAL(NULL, string_split_shared ("", NULL, flags, 0, NULL));
|
||||
POINTERS_EQUAL(NULL, string_split_shared ("", "", flags, 0, NULL));
|
||||
POINTERS_EQUAL(NULL, string_split_shared (NULL, NULL, NULL,
|
||||
flags, 0, NULL));
|
||||
POINTERS_EQUAL(NULL, string_split_shared (NULL, "", NULL,
|
||||
flags, 0, NULL));
|
||||
POINTERS_EQUAL(NULL, string_split_shared ("", NULL, NULL,
|
||||
flags, 0, NULL));
|
||||
POINTERS_EQUAL(NULL, string_split_shared ("", "", NULL,
|
||||
flags, 0, NULL));
|
||||
|
||||
flags = WEECHAT_STRING_SPLIT_STRIP_LEFT
|
||||
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
|
||||
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
|
||||
argv = string_split_shared (" abc de abc ", " ", flags, 0, &argc);
|
||||
argv = string_split_shared (" abc de abc ", " ", NULL, flags, 0, &argc);
|
||||
LONGS_EQUAL(3, argc);
|
||||
CHECK(argv);
|
||||
STRCMP_EQUAL("abc", argv[0]);
|
||||
@@ -1441,7 +1497,7 @@ TEST(CoreString, SplitBuildWithSplitString)
|
||||
flags = WEECHAT_STRING_SPLIT_STRIP_LEFT
|
||||
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
|
||||
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
|
||||
argv = string_split (" abc de fghi ", " ", flags, 0, &argc);
|
||||
argv = string_split (" abc de fghi ", " ", NULL, flags, 0, &argc);
|
||||
|
||||
str = string_build_with_split_string ((const char **)argv, NULL);
|
||||
STRCMP_EQUAL("abcdefghi", str);
|
||||
|
||||
Reference in New Issue
Block a user