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

Add widest_line(), returns widest (display width) of lines in char*

does not (yet) support UTF-8
parent 8506c2b6
No related branches found
No related tags found
No related merge requests found
......@@ -794,3 +794,25 @@ char* make_newsgroup_name(char* str)
str[c] = '_';
return str;
}
size_t widest_line(const char* str)
{
size_t widest = 0;
size_t width = 0;
for (size_t i = 0; str[i] != '\0'; ++i) {
if (str[i] == '\n') {
if (width > widest)
widest = width;
width = 0;
} else if(str[i] == CTRL_A) {
++i;
if (str[i] == '\0' || str[i] == 'Z')
break;
} else if(str[i] != '\r')
++width;
}
if (width > widest)
return width;
return widest;
}
......@@ -67,6 +67,7 @@ DLLEXPORT bool str_is_ascii(const char*);
DLLEXPORT char * utf8_to_cp437_inplace(char* str);
DLLEXPORT char * separate_thousands(const char* src, char *dest, size_t maxlen, char sep);
DLLEXPORT char * make_newsgroup_name(char* str);
DLLEXPORT size_t widest_line(const char* str);
#ifdef __cplusplus
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment