experiments with word wrap

This commit is contained in:
Andrew Pamment 2018-02-28 09:10:27 +10:00
parent 735fe035d7
commit d087e13f61

View File

@ -707,11 +707,12 @@ static char *www_wordwrap(char *content, int cutoff) {
char *ret;
int at = 0;
int extra = 0;
int quote_line = 0;
for (i=0;i<len;i++) {
if (content[i] == '\n') {
continue;
}
}
content[at++] = content[i];
}
@ -720,20 +721,30 @@ static char *www_wordwrap(char *content, int cutoff) {
len = strlen(content);
for (i=0;i<len-1;i++) {
if (content[i] == '>' && line_count < 4) {
quote_line = 1;
}
if (content[i] == '\r' && content[i+1] != '\r') {
if (content[i+1] == ' ') {
if (content[i+1] == ' ' || quote_line == 1) {
content[at++] = '\r';
line_count = 0;
quote_line = 0;
} else {
if (at > 0 && content[at-1] != '\r' && content[at-1] != ' ') {
content[at++] = ' ';
line_count++;
}
}
} else if (content[i] == '\r' && content[i+1] == '\r') {
content[at++] = '\r';
content[at++] = '\r';
line_count = 0;
quote_line = 0;
i++;
} else {
content[at++] = content[i];
line_count++;
}
}
//content[at++] = content[i];
@ -748,6 +759,9 @@ static char *www_wordwrap(char *content, int cutoff) {
return NULL;
}
line_count = 0;
quote_line = 0;
for (i=0;i<len;i++) {
if (content[i] != '\r') {
ret[at] = content[i];
@ -755,7 +769,9 @@ static char *www_wordwrap(char *content, int cutoff) {
last_space = &ret[at];
}
at++;
} else if (content[i] == '>' && line_count < 4) {
quote_line = 1;
ret[at++] = content[i];
} else {
ret[at++] = content[i];
}
@ -764,12 +780,21 @@ static char *www_wordwrap(char *content, int cutoff) {
if (content[i] == '\r') {
line_count = 0;
last_space = NULL;
quote_line == 0;
} else if (line_count == cutoff) {
// wrap
if (last_space != NULL) {
if (quote_line == 1) {
while (content[i] != '\r') {
i++;
}
last_space = NULL;
line_count = 0;
quote_line = 0;
} else if (last_space != NULL) {
*last_space = '\r';
line_count = strlen(&last_space[1]);
last_space = NULL;
quote_line = 0;
} else {
extra++;
ret = (char *)realloc(ret, strlen(content) + extra + 1);
@ -780,6 +805,7 @@ static char *www_wordwrap(char *content, int cutoff) {
ret[at] = '\0';
last_space = NULL;
line_count = 0;
quote_line = 0;
}
} else {
line_count++;