buffer2array: use GLib's g_ascii_isspace()
g_ascii_isspace() includes \r and \n. This means that lines from a text file don't have to be chopped prior to buffer2array().
This commit is contained in:
parent
4b3a055ffe
commit
2598cdd868
@ -17,14 +17,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "buffer2array.h"
|
#include "buffer2array.h"
|
||||||
#include "os_compat.h"
|
|
||||||
|
|
||||||
static inline
|
#include <glib.h>
|
||||||
int
|
|
||||||
isWhiteSpace(char c)
|
#include <string.h>
|
||||||
{
|
|
||||||
return (c == ' ' || c == '\t');
|
|
||||||
}
|
|
||||||
|
|
||||||
int buffer2array(char *buffer, char *array[], const int max)
|
int buffer2array(char *buffer, char *array[], const int max)
|
||||||
{
|
{
|
||||||
@ -44,19 +40,20 @@ int buffer2array(char *buffer, char *array[], const int max)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while (isWhiteSpace(*c))
|
c = g_strchug(c);
|
||||||
++c;
|
|
||||||
array[i++] = c++;
|
|
||||||
if (*c == '\0')
|
if (*c == '\0')
|
||||||
return i;
|
return i;
|
||||||
while (!isWhiteSpace(*c) && *c != '\0')
|
|
||||||
|
array[i++] = c++;
|
||||||
|
|
||||||
|
while (!g_ascii_isspace(*c) && *c != '\0')
|
||||||
++c;
|
++c;
|
||||||
}
|
}
|
||||||
if (*c == '\0')
|
if (*c == '\0')
|
||||||
return i;
|
return i;
|
||||||
*(c++) = '\0';
|
*(c++) = '\0';
|
||||||
while (isWhiteSpace(*c))
|
|
||||||
++c;
|
c = g_strchug(c);
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user