tweaks: rename a function for aptness, and two variables for shortness
Этот коммит содержится в:
родитель
954cab81b4
Коммит
04cfe5a258
@ -530,7 +530,6 @@ ssize_t break_line(const char *line, ssize_t goal, bool snap_at_nl);
|
|||||||
size_t indent_length(const char *line);
|
size_t indent_length(const char *line);
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_JUSTIFY
|
#ifdef ENABLE_JUSTIFY
|
||||||
void justify_format(filestruct *paragraph, size_t skip);
|
|
||||||
bool begpar(const filestruct *const foo, int depth);
|
bool begpar(const filestruct *const foo, int depth);
|
||||||
bool inpar(const filestruct *const foo);
|
bool inpar(const filestruct *const foo);
|
||||||
void do_justify(bool full_justify);
|
void do_justify(bool full_justify);
|
||||||
|
26
src/text.c
26
src/text.c
@ -1669,15 +1669,15 @@ size_t indent_length(const char *line)
|
|||||||
* but keep two spaces (if there are two) after any closing punctuation,
|
* but keep two spaces (if there are two) after any closing punctuation,
|
||||||
* and remove all blanks from the end of the line. Leave the first skip
|
* and remove all blanks from the end of the line. Leave the first skip
|
||||||
* number of characters untreated. */
|
* number of characters untreated. */
|
||||||
void justify_format(filestruct *paragraph, size_t skip)
|
void squeeze(filestruct *line, size_t skip)
|
||||||
{
|
{
|
||||||
char *end, *new_end, *new_paragraph_data;
|
char *end, *new_end, *newdata;
|
||||||
size_t shift = 0;
|
size_t shift = 0;
|
||||||
|
|
||||||
end = paragraph->data + skip;
|
end = line->data + skip;
|
||||||
new_paragraph_data = charalloc(strlen(paragraph->data) + 1);
|
newdata = charalloc(strlen(line->data) + 1);
|
||||||
strncpy(new_paragraph_data, paragraph->data, skip);
|
strncpy(newdata, line->data, skip);
|
||||||
new_end = new_paragraph_data + skip;
|
new_end = newdata + skip;
|
||||||
|
|
||||||
while (*end != '\0') {
|
while (*end != '\0') {
|
||||||
int end_len;
|
int end_len;
|
||||||
@ -1759,17 +1759,17 @@ void justify_format(filestruct *paragraph, size_t skip)
|
|||||||
*new_end = *end;
|
*new_end = *end;
|
||||||
|
|
||||||
/* If there are spaces at the end of the line, remove them. */
|
/* If there are spaces at the end of the line, remove them. */
|
||||||
while (new_end > new_paragraph_data + skip && *(new_end - 1) == ' ') {
|
while (new_end > newdata + skip && *(new_end - 1) == ' ') {
|
||||||
new_end--;
|
new_end--;
|
||||||
shift++;
|
shift++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shift > 0) {
|
if (shift > 0) {
|
||||||
null_at(&new_paragraph_data, new_end - new_paragraph_data);
|
null_at(&newdata, new_end - newdata);
|
||||||
free(paragraph->data);
|
free(line->data);
|
||||||
paragraph->data = new_paragraph_data;
|
line->data = newdata;
|
||||||
} else
|
} else
|
||||||
free(new_paragraph_data);
|
free(newdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the length of the quote part of the given line. The "quote part"
|
/* Return the length of the quote part of the given line. The "quote part"
|
||||||
@ -1971,7 +1971,7 @@ void justify_paragraph(filestruct **line, size_t par_len)
|
|||||||
concat_paragraph(line, par_len);
|
concat_paragraph(line, par_len);
|
||||||
|
|
||||||
/* Change all blank characters to spaces and remove excess spaces. */
|
/* Change all blank characters to spaces and remove excess spaces. */
|
||||||
justify_format(*line, quote_len + indent_length((*line)->data + quote_len));
|
squeeze(*line, quote_len + indent_length((*line)->data + quote_len));
|
||||||
|
|
||||||
/* Rewrap the line into multiple lines, accounting for the leading part. */
|
/* Rewrap the line into multiple lines, accounting for the leading part. */
|
||||||
rewrap_paragraph(line, lead_string, lead_len);
|
rewrap_paragraph(line, lead_string, lead_len);
|
||||||
@ -2177,7 +2177,7 @@ void do_justify(bool full_justify)
|
|||||||
|
|
||||||
/* Now justify the extracted region. */
|
/* Now justify the extracted region. */
|
||||||
concat_paragraph(&cutbuffer, par_len);
|
concat_paragraph(&cutbuffer, par_len);
|
||||||
justify_format(cutbuffer, lead_len);
|
squeeze(cutbuffer, lead_len);
|
||||||
line = cutbuffer;
|
line = cutbuffer;
|
||||||
if (the_second_lead != NULL) {
|
if (the_second_lead != NULL) {
|
||||||
rewrap_paragraph(&line, the_second_lead, second_lead_len);
|
rewrap_paragraph(&line, the_second_lead, second_lead_len);
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user