projects
/
platform
/
upstream
/
libxkbcommon.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
packaging: make a option to select enable/disable tools
[platform/upstream/libxkbcommon.git]
/
src
/
utf8.c
diff --git
a/src/utf8.c
b/src/utf8.c
index
a7fa82e
..
d37ba8e
100644
(file)
--- a/
src/utf8.c
+++ b/
src/utf8.c
@@
-24,12
+24,19
@@
* Author: Rob Bradford <rob@linux.intel.com>
*/
* Author: Rob Bradford <rob@linux.intel.com>
*/
+#include "config.h"
+
#include <stddef.h>
#include <stdbool.h>
#include <inttypes.h>
#include "utf8.h"
#include <stddef.h>
#include <stdbool.h>
#include <inttypes.h>
#include "utf8.h"
+/* Conformant encoding form conversion from UTF-32 to UTF-8.
+ *
+ * See https://www.unicode.org/versions/Unicode15.0.0/ch03.pdf#G28875
+ * for further details.
+*/
int
utf32_to_utf8(uint32_t unichar, char *buffer)
{
int
utf32_to_utf8(uint32_t unichar, char *buffer)
{
@@
-45,21
+52,20
@@
utf32_to_utf8(uint32_t unichar, char *buffer)
length = 2;
head = 0xc0;
}
length = 2;
head = 0xc0;
}
+ /* Handle surrogates */
+ else if (0xd800 <= unichar && unichar <= 0xdfff) {
+ goto ill_formed_code_unit_subsequence;
+ }
else if (unichar <= 0xffff) {
length = 3;
head = 0xe0;
}
else if (unichar <= 0xffff) {
length = 3;
head = 0xe0;
}
- else if (unichar <= 0x1
f
ffff) {
+ else if (unichar <= 0x1
0
ffff) {
length = 4;
head = 0xf0;
}
length = 4;
head = 0xf0;
}
- else if (unichar <= 0x3ffffff) {
- length = 5;
- head = 0xf8;
- }
else {
else {
- length = 6;
- head = 0xfc;
+ goto ill_formed_code_unit_subsequence;
}
for (count = length - 1, shift = 0; count > 0; count--, shift += 6)
}
for (count = length - 1, shift = 0; count > 0; count--, shift += 6)
@@
-69,6
+75,10
@@
utf32_to_utf8(uint32_t unichar, char *buffer)
buffer[length] = '\0';
return length + 1;
buffer[length] = '\0';
return length + 1;
+
+ill_formed_code_unit_subsequence:
+ buffer[0] = '\0';
+ return 0;
}
bool
}
bool