projects
/
gnulib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Tweak last commit.
[gnulib.git]
/
lib
/
trim.c
diff --git
a/lib/trim.c
b/lib/trim.c
index
62f8ebf
..
155063e
100644
(file)
--- a/
lib/trim.c
+++ b/
lib/trim.c
@@
-1,5
+1,5
@@
/* Removes leading and/or trailing whitespaces
/* Removes leading and/or trailing whitespaces
- Copyright (C) 2006-201
0
Free Software Foundation, Inc.
+ Copyright (C) 2006-201
1
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@
-38,14
+38,14
@@
#endif
char *
#endif
char *
-trim2(const char *s, int how)
+trim2
(const char *s, int how)
{
char *d;
{
char *d;
- d = strdup(s);
+ d = strdup
(s);
if (!d)
if (!d)
- xalloc_die();
+ xalloc_die
();
if (MB_CUR_MAX > 1)
{
if (MB_CUR_MAX > 1)
{
@@
-65,7
+65,7
@@
trim2(const char *s, int how)
/* Trim trailing whitespaces. */
if (how != TRIM_LEADING)
{
/* Trim trailing whitespaces. */
if (how != TRIM_LEADING)
{
- int state = 0;
+
unsigned
int state = 0;
char *r IF_LINT (= NULL); /* used only while state = 2 */
mbi_init (i, d, strlen (d));
char *r IF_LINT (= NULL); /* used only while state = 2 */
mbi_init (i, d, strlen (d));
@@
-73,10
+73,7
@@
trim2(const char *s, int how)
for (; mbi_avail (i); mbi_advance (i))
{
if (state == 0 && mb_isspace (mbi_cur (i)))
for (; mbi_avail (i); mbi_advance (i))
{
if (state == 0 && mb_isspace (mbi_cur (i)))
- {
- state = 0;
- continue;
- }
+ continue;
if (state == 0 && !mb_isspace (mbi_cur (i)))
{
if (state == 0 && !mb_isspace (mbi_cur (i)))
{
@@
-85,10
+82,7
@@
trim2(const char *s, int how)
}
if (state == 1 && !mb_isspace (mbi_cur (i)))
}
if (state == 1 && !mb_isspace (mbi_cur (i)))
- {
- state = 1;
- continue;
- }
+ continue;
if (state == 1 && mb_isspace (mbi_cur (i)))
{
if (state == 1 && mb_isspace (mbi_cur (i)))
{
@@
-97,7
+91,7
@@
trim2(const char *s, int how)
}
else if (state == 2 && mb_isspace (mbi_cur (i)))
{
}
else if (state == 2 && mb_isspace (mbi_cur (i)))
{
- state = 2;
+ /* empty */
}
else
{
}
else
{
@@
-114,20
+108,22
@@
trim2(const char *s, int how)
char *p;
/* Trim leading whitespaces. */
char *p;
/* Trim leading whitespaces. */
- if (how != TRIM_TRAILING) {
- for (p = d; *p && isspace ((unsigned char) *p); p++)
- ;
+ if (how != TRIM_TRAILING)
+ {
+ for (p = d; *p && isspace ((unsigned char) *p); p++)
+ ;
- memmove (d, p, strlen (p) + 1);
- }
+
memmove (d, p, strlen (p) + 1);
+
}
/* Trim trailing whitespaces. */
/* Trim trailing whitespaces. */
- if (how != TRIM_LEADING) {
- for (p = d + strlen (d) - 1; p >= d && isspace ((unsigned char) *p); p--)
- *p = '\0';
- }
+ if (how != TRIM_LEADING)
+ {
+ for (p = d + strlen (d) - 1;
+ p >= d && isspace ((unsigned char) *p); p--)
+ *p = '\0';
+ }
}
return d;
}
}
return d;
}
-