forked from github/server
delete leading spaces from names.
This commit is contained in:
parent
f03e8f3b62
commit
7b412399b7
2 changed files with 20 additions and 14 deletions
|
@ -35,22 +35,27 @@
|
||||||
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)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
bool iss = true;
|
||||||
while (*ip) {
|
while (*ip) {
|
||||||
ucs4_t ucs = *ip;
|
|
||||||
size_t size = 1;
|
size_t size = 1;
|
||||||
bool isp = false;
|
bool isp = false;
|
||||||
// bool iss = false;
|
do {
|
||||||
if (ucs & 0x80) {
|
ucs4_t ucs = *ip;
|
||||||
ret = unicode_utf8_to_ucs4(&ucs, ip, &size);
|
if (ucs & 0x80) {
|
||||||
if (ret !=0) {
|
ret = unicode_utf8_to_ucs4(&ucs, ip, &size);
|
||||||
return ret;
|
if (ret !=0) {
|
||||||
}
|
return ret;
|
||||||
isp = iswprint(ucs);
|
}
|
||||||
// iss = iswspace(ucs);
|
isp = iswprint(ucs);
|
||||||
} else {
|
iss &= !!iswspace(ucs);
|
||||||
isp = isprint(ucs);
|
} else {
|
||||||
// iss = isspace(ucs);
|
isp = isprint(ucs);
|
||||||
}
|
iss &= !!isspace(ucs);
|
||||||
|
}
|
||||||
|
if (iss) {
|
||||||
|
ip += size;
|
||||||
|
}
|
||||||
|
} while (iss);
|
||||||
if (size > outlen) {
|
if (size > outlen) {
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,10 @@
|
||||||
static void test_unicode_mkname(CuTest * tc)
|
static void test_unicode_mkname(CuTest * tc)
|
||||||
{
|
{
|
||||||
char buffer[32];
|
char buffer[32];
|
||||||
|
CuAssertIntEquals(tc, 0, unicode_utf8_mkname(buffer, sizeof(buffer), " HeLlO W0Rld"));
|
||||||
|
CuAssertStrEquals(tc, "HeLlO W0Rld", buffer);
|
||||||
CuAssertIntEquals(tc, 0, unicode_utf8_mkname(buffer, sizeof(buffer), "HeLlO W0Rld"));
|
CuAssertIntEquals(tc, 0, unicode_utf8_mkname(buffer, sizeof(buffer), "HeLlO W0Rld"));
|
||||||
CuAssertStrEquals(tc, "HeLlO W0Rld", buffer);
|
CuAssertStrEquals(tc, "HeLlO W0Rld", buffer);
|
||||||
memset(buffer, 0, sizeof(buffer));
|
|
||||||
CuAssertIntEquals(tc, 1, unicode_utf8_mkname(buffer, sizeof(buffer), "HeLlO\nW0Rld"));
|
CuAssertIntEquals(tc, 1, unicode_utf8_mkname(buffer, sizeof(buffer), "HeLlO\nW0Rld"));
|
||||||
CuAssertStrEquals(tc, "HeLlOW0Rld", buffer);
|
CuAssertStrEquals(tc, "HeLlOW0Rld", buffer);
|
||||||
memset(buffer, 0, sizeof(buffer));
|
memset(buffer, 0, sizeof(buffer));
|
||||||
|
|
Loading…
Reference in a new issue