volume_id: code shrink
function old new delta volume_id_set_unicode16 200 173 -27 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
@ -31,25 +31,29 @@ void volume_id_set_unicode16(char *str, size_t len, const uint8_t *buf, enum end
|
|||||||
c = (buf[i+1] << 8) | buf[i];
|
c = (buf[i+1] << 8) | buf[i];
|
||||||
else
|
else
|
||||||
c = (buf[i] << 8) | buf[i+1];
|
c = (buf[i] << 8) | buf[i+1];
|
||||||
if (c == 0) {
|
if (c == 0)
|
||||||
str[j] = '\0';
|
|
||||||
break;
|
break;
|
||||||
} else if (c < 0x80) {
|
if (j+1 >= len)
|
||||||
if (j+1 >= len)
|
break;
|
||||||
break;
|
if (c < 0x80) {
|
||||||
str[j++] = (uint8_t) c;
|
/* 0xxxxxxx */
|
||||||
} else if (c < 0x800) {
|
} else {
|
||||||
|
uint8_t topbits = 0xc0;
|
||||||
if (j+2 >= len)
|
if (j+2 >= len)
|
||||||
break;
|
break;
|
||||||
str[j++] = (uint8_t) (0xc0 | (c >> 6));
|
if (c < 0x800) {
|
||||||
str[j++] = (uint8_t) (0x80 | (c & 0x3f));
|
/* 110yyyxx 10xxxxxx */
|
||||||
} else {
|
} else {
|
||||||
if (j+3 >= len)
|
if (j+3 >= len)
|
||||||
break;
|
break;
|
||||||
str[j++] = (uint8_t) (0xe0 | (c >> 12));
|
/* 1110yyyy 10yyyyxx 10xxxxxx */
|
||||||
str[j++] = (uint8_t) (0x80 | ((c >> 6) & 0x3f));
|
str[j++] = (uint8_t) (0xe0 | (c >> 12));
|
||||||
str[j++] = (uint8_t) (0x80 | (c & 0x3f));
|
topbits = 0x80;
|
||||||
|
}
|
||||||
|
str[j++] = (uint8_t) (topbits | ((c >> 6) & 0x3f));
|
||||||
|
c = 0x80 | (c & 0x3f);
|
||||||
}
|
}
|
||||||
|
str[j++] = (uint8_t) c;
|
||||||
}
|
}
|
||||||
str[j] = '\0';
|
str[j] = '\0';
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user