* util.c (trim): Handle short strings even better - don't use
dots unless necessary.
Этот коммит содержится в:
родитель
9af6bedb04
Коммит
08440f7e8d
@ -1,5 +1,8 @@
|
|||||||
2002-09-10 Pavel Roskin <proski@gnu.org>
|
2002-09-10 Pavel Roskin <proski@gnu.org>
|
||||||
|
|
||||||
|
* util.c (trim): Handle short strings even better - don't use
|
||||||
|
dots unless necessary.
|
||||||
|
|
||||||
* main.c (load_prompt): Don't shorten the prompt if COLS is 8 or
|
* main.c (load_prompt): Don't shorten the prompt if COLS is 8 or
|
||||||
less.
|
less.
|
||||||
|
|
||||||
|
22
src/util.c
22
src/util.c
@ -117,18 +117,24 @@ trim (char *s, char *d, int len)
|
|||||||
{
|
{
|
||||||
int source_len;
|
int source_len;
|
||||||
|
|
||||||
if (len < 3) {
|
/* Sanity check */
|
||||||
len = max (len, 0);
|
len = max (len, 0);
|
||||||
memset (d, '.', len);
|
|
||||||
d[len] = 0;
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
source_len = strlen (s);
|
source_len = strlen (s);
|
||||||
if (source_len > len) {
|
if (source_len > len) {
|
||||||
memset (d, '.', 3);
|
/* Cannot fit the whole line */
|
||||||
strcpy (d + 3, s + 3 + source_len - len);
|
if (len <= 3) {
|
||||||
|
/* We only have room for the dots */
|
||||||
|
memset (d, '.', len);
|
||||||
|
d[len] = 0;
|
||||||
|
return d;
|
||||||
|
} else {
|
||||||
|
/* Begin with ... and add the rest of the source string */
|
||||||
|
memset (d, '.', 3);
|
||||||
|
strcpy (d + 3, s + 3 + source_len - len);
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
|
/* We can copy the whole line */
|
||||||
strcpy (d, s);
|
strcpy (d, s);
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
Загрузка…
Ссылка в новой задаче
Block a user