/* Removes leading and/or trailing whitespaces
- Copyright (C) 2006-2010 Free Software Foundation, Inc.
+ Copyright (C) 2006-2013 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
#include "mbiter.h"
#include "xalloc.h"
-/* Use this to suppress gcc's `...may be used before initialized' warnings. */
+/* Use this to suppress gcc's "...may be used before initialized" warnings. */
#ifdef lint
# define IF_LINT(Code) Code
#else
/* 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));
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 == 1 && !mb_isspace (mbi_cur (i)))
- {
- state = 1;
- continue;
- }
+ continue;
if (state == 1 && mb_isspace (mbi_cur (i)))
{
}
else if (state == 2 && mb_isspace (mbi_cur (i)))
{
- state = 2;
+ /* empty */
}
else
{
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. */
- 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;
}
-