Skip to content
Snippets Groups Projects
Commit 0e30b9f6 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Include blank lines in messages edited with internal editor

Needed a version of strListSplit() that doesn't treat consecutive delimiters (e.g. "\r\n\r\n") as a single delimiter: so introducing strListDivide(). Like strListSplit(), strListDivide() modifies the input string (replacing first occurrences of delimiter with NUL).

Since we don't want "\r\n" to be counted as 2 lines, we need to just split/divide on '\n' and then truncate any line endings (i.e. '\r') chars off the ends of the split strings.

Reported by phigan in #synchronet
parent eded40f1
No related branches found
No related tags found
No related merge requests found
......@@ -931,7 +931,7 @@ ulong sbbs_t::msgeditor(char *buf, const char *top, char *title)
maxlines=cfg.level_linespermsg[useron.level];
if((str = strListSplit(NULL, buf, "\r\n")) == NULL) {
if((str = strListDivide(NULL, buf, "\n")) == NULL) {
errormsg(WHERE,ERR_ALLOC,"msgeditor",sizeof(char *)*(maxlines+1));
return(0);
}
......@@ -939,6 +939,7 @@ ulong sbbs_t::msgeditor(char *buf, const char *top, char *title)
while(lines > maxlines)
free(str[--lines]);
str[lines] = NULL;
strListTruncateTrailingLineEndings(str);
if(lines)
bprintf("\r\nMessage editor: Read in %d lines\r\n",lines);
bprintf(text[EnterMsgNow],maxlines);
......
......@@ -384,6 +384,7 @@ char* strListInsertFormat(str_list_t* list, size_t index, const char* format, ..
}
#endif
// Consecutive delimiters are treated as one (empty strings are skipped)
str_list_t strListSplit(str_list_t* lp, char* str, const char* delimit)
{
size_t count;
......@@ -430,6 +431,38 @@ str_list_t strListSplitCopy(str_list_t* list, const char* str, const char* delim
return(new_list);
}
// Consecutive delimiters are treated as multiple (empty strings are supported)
str_list_t strListDivide(str_list_t* lp, char* str, const char* delimit)
{
size_t count;
char* p = str;
char* np;
char* end;
str_list_t list;
if(str == NULL || delimit == NULL)
return NULL;
if(lp == NULL) {
if((list = strListInit()) == NULL)
return NULL;
lp = &list;
count = 0;
} else
count = strListCount(*lp);
end = str + strlen(str);
while(p < end) {
np = p + strcspn(p, delimit);
*np = '\0';
strListAppend(lp, p, count++);
p = np + 1;
}
return *lp;
}
size_t strListMerge(str_list_t* list, str_list_t add_list)
{
size_t i;
......
......@@ -103,12 +103,16 @@ DLLEXPORT BOOL strListSwap(const str_list_t, size_t index1, size_t index2);
#define strListPop(list) strListRemove(list, STR_LIST_LAST_INDEX)
/* Add to an existing or new string list by splitting specified string (str) */
/* into multiple strings, separated by one of the delimit characters */
/* into multiple (non-empty) strings, separated by one or more of the delimit characters */
DLLEXPORT str_list_t strListSplit(str_list_t*, char* str, const char* delimit);
/* Same as above, but copies str to temporary heap buffer first */
DLLEXPORT str_list_t strListSplitCopy(str_list_t*, const char* str, const char* delimit);
/* Add to an existing or new string list by splitting specified string (str) */
/* into multiple (possibly empty) strings, separated by one of the delimit characters */
DLLEXPORT str_list_t strListDivide(str_list_t*, char* str, const char* delimit);
/* Merge 2 string lists (no copying of string data) */
DLLEXPORT size_t strListMerge(str_list_t*, str_list_t append_list);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment