tweaks: elide two variables, and condense some statements
Also, remove an assert and adjust some comments.master
parent
6500f769aa
commit
99ecd33c18
34
src/text.c
34
src/text.c
|
@ -1622,17 +1622,15 @@ bool do_wrap(filestruct *line)
|
||||||
ssize_t break_line(const char *line, ssize_t goal, bool snap_at_nl)
|
ssize_t break_line(const char *line, ssize_t goal, bool snap_at_nl)
|
||||||
{
|
{
|
||||||
ssize_t blank_loc = -1;
|
ssize_t blank_loc = -1;
|
||||||
/* Current tentative return value. Index of the last blank we
|
/* The index of the last blank we found. */
|
||||||
* found with short enough display width. */
|
|
||||||
ssize_t cur_loc = 0;
|
ssize_t cur_loc = 0;
|
||||||
/* Current index in line. */
|
/* Current index in line. */
|
||||||
size_t cur_pos = 0;
|
size_t cur_pos = 0;
|
||||||
/* Current column position in line. */
|
/* The column position that corresponds with cur_loc. */
|
||||||
int char_len = 0;
|
int char_len = 0;
|
||||||
/* Length of current character, in bytes. */
|
/* Length of current character, in bytes. */
|
||||||
|
|
||||||
assert(line != NULL);
|
/* Find the last blank that does not overshoot the target column. */
|
||||||
|
|
||||||
while (*line != '\0' && goal >= cur_pos) {
|
while (*line != '\0' && goal >= cur_pos) {
|
||||||
char_len = parse_mbchar(line, NULL, &cur_pos);
|
char_len = parse_mbchar(line, NULL, &cur_pos);
|
||||||
|
|
||||||
|
@ -1654,26 +1652,20 @@ ssize_t break_line(const char *line, ssize_t goal, bool snap_at_nl)
|
||||||
#ifndef DISABLE_HELP
|
#ifndef DISABLE_HELP
|
||||||
/* If we're wrapping a help text and no blank was found, or was
|
/* If we're wrapping a help text and no blank was found, or was
|
||||||
* found only as the first character, force a line break. */
|
* found only as the first character, force a line break. */
|
||||||
if (snap_at_nl && blank_loc < 1) {
|
if (snap_at_nl && blank_loc < 1)
|
||||||
cur_loc -= char_len;
|
return (cur_loc - char_len);
|
||||||
return cur_loc;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* If no blank was found within the goal width, try to find a
|
/* If no blank was found within the goal width, try to find a
|
||||||
* blank beyond it. */
|
* blank beyond it. */
|
||||||
if (blank_loc == -1) {
|
if (blank_loc == -1) {
|
||||||
bool found_blank = FALSE;
|
|
||||||
ssize_t found_blank_loc = 0;
|
|
||||||
|
|
||||||
while (*line != '\0') {
|
while (*line != '\0') {
|
||||||
char_len = parse_mbchar(line, NULL, NULL);
|
char_len = parse_mbchar(line, NULL, NULL);
|
||||||
|
|
||||||
if (is_blank_mbchar(line)) {
|
if (is_blank_mbchar(line))
|
||||||
found_blank = TRUE;
|
blank_loc = cur_loc;
|
||||||
found_blank_loc = cur_loc;
|
else if (blank_loc > 0)
|
||||||
} else if (found_blank)
|
return blank_loc;
|
||||||
return found_blank_loc;
|
|
||||||
|
|
||||||
line += char_len;
|
line += char_len;
|
||||||
cur_loc += char_len;
|
cur_loc += char_len;
|
||||||
|
@ -1682,12 +1674,10 @@ ssize_t break_line(const char *line, ssize_t goal, bool snap_at_nl)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Move to the last blank after blank_loc, if there is one. */
|
line += blank_loc - cur_loc;
|
||||||
line -= cur_loc;
|
line += parse_mbchar(line, NULL, NULL);
|
||||||
line += blank_loc;
|
|
||||||
char_len = parse_mbchar(line, NULL, NULL);
|
|
||||||
line += char_len;
|
|
||||||
|
|
||||||
|
/* Move to the last consecutive blank after blank_loc. */
|
||||||
while (*line != '\0' && is_blank_mbchar(line)) {
|
while (*line != '\0' && is_blank_mbchar(line)) {
|
||||||
char_len = parse_mbchar(line, NULL, NULL);
|
char_len = parse_mbchar(line, NULL, NULL);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue