forked from github/server
also remove trailing spaces.
This commit is contained in:
parent
97e91fd8eb
commit
e0add2275f
|
@ -34,8 +34,8 @@
|
||||||
|
|
||||||
int unicode_utf8_trim(utf8_t *buf)
|
int unicode_utf8_trim(utf8_t *buf)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0, ts = 0;
|
||||||
utf8_t *op = buf, *ip = buf;
|
utf8_t *op = buf, *ip = buf, *lc = buf;
|
||||||
while (*ip) {
|
while (*ip) {
|
||||||
ucs4_t ucs = *ip;
|
ucs4_t ucs = *ip;
|
||||||
size_t size = 1;
|
size_t size = 1;
|
||||||
|
@ -53,13 +53,18 @@ int unicode_utf8_trim(utf8_t *buf)
|
||||||
memcpy(op, ip, size);
|
memcpy(op, ip, size);
|
||||||
}
|
}
|
||||||
op += size;
|
op += size;
|
||||||
|
if (iswspace(ucs)) ++ts;
|
||||||
|
else {
|
||||||
|
lc = op;
|
||||||
|
ts = 0;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
++result;
|
++result;
|
||||||
}
|
}
|
||||||
ip += size;
|
ip += size;
|
||||||
}
|
}
|
||||||
*op = '\0';
|
*lc = '\0';
|
||||||
return result;
|
return result + ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
int unicode_utf8_mkname(utf8_t * op, size_t outlen, const utf8_t * ip)
|
int unicode_utf8_mkname(utf8_t * op, size_t outlen, const utf8_t * ip)
|
||||||
|
|
|
@ -13,6 +13,10 @@ static void test_unicode_trim(CuTest * tc)
|
||||||
CuAssertIntEquals(tc, 0, unicode_utf8_trim(buffer));
|
CuAssertIntEquals(tc, 0, unicode_utf8_trim(buffer));
|
||||||
CuAssertStrEquals(tc, "Hello Word", buffer);
|
CuAssertStrEquals(tc, "Hello Word", buffer);
|
||||||
|
|
||||||
|
strcpy(buffer, " Hello Word ");
|
||||||
|
CuAssertIntEquals(tc, 4, unicode_utf8_trim(buffer));
|
||||||
|
CuAssertStrEquals(tc, "Hello Word", buffer);
|
||||||
|
|
||||||
strcpy(buffer, "Hello Word\n");
|
strcpy(buffer, "Hello Word\n");
|
||||||
CuAssertIntEquals(tc, 1, unicode_utf8_trim(buffer));
|
CuAssertIntEquals(tc, 1, unicode_utf8_trim(buffer));
|
||||||
CuAssertStrEquals(tc, "Hello Word", buffer);
|
CuAssertStrEquals(tc, "Hello Word", buffer);
|
||||||
|
|
Loading…
Reference in New Issue