mirror of
https://github.com/rfivet/uemacs.git
synced 2024-10-01 09:45:58 -04:00
Assert that unicode are limited to 0-10FFFF.
This commit is contained in:
parent
2cef071492
commit
bdbd2d5437
17
eval.c
17
eval.c
@ -523,10 +523,19 @@ static char *gtfun( char *fname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
break ;
|
break ;
|
||||||
case UFCHR:
|
case UFCHR: {
|
||||||
sz = unicode_to_utf8( atoi( argx), result) ;
|
unicode_t c ;
|
||||||
result[ sz] = 0 ;
|
|
||||||
retstr = result ;
|
c = atoi( argx) ;
|
||||||
|
if( c > 0x10FFFF)
|
||||||
|
retstr = errorm ;
|
||||||
|
else {
|
||||||
|
sz = unicode_to_utf8( c, result) ;
|
||||||
|
result[ sz] = 0 ;
|
||||||
|
retstr = result ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
break ;
|
break ;
|
||||||
case UFGTKEY:
|
case UFGTKEY:
|
||||||
result[0] = tgetc();
|
result[0] = tgetc();
|
||||||
|
10
utf8.c
10
utf8.c
@ -1,5 +1,7 @@
|
|||||||
#include "utf8.h"
|
#include "utf8.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* utf8_to_unicode()
|
* utf8_to_unicode()
|
||||||
*
|
*
|
||||||
@ -84,11 +86,11 @@ static void reverse_string(char *begin, char *end)
|
|||||||
* possible sequence, while utf8_to_unicode() accepts both Latin1 and
|
* possible sequence, while utf8_to_unicode() accepts both Latin1 and
|
||||||
* overlong utf-8 sequences.
|
* overlong utf-8 sequences.
|
||||||
*/
|
*/
|
||||||
unsigned unicode_to_utf8(unsigned int c, char *utf8)
|
unsigned unicode_to_utf8( unicode_t c, char *utf8) {
|
||||||
{
|
int bytes = 1 ;
|
||||||
int bytes = 1;
|
|
||||||
|
|
||||||
*utf8 = c;
|
assert( c <= 0x10FFFF) ;
|
||||||
|
*utf8 = c ;
|
||||||
if (c > 0x7f) {
|
if (c > 0x7f) {
|
||||||
int prefix = 0x40;
|
int prefix = 0x40;
|
||||||
char *p = utf8;
|
char *p = utf8;
|
||||||
|
6
utf8.h
6
utf8.h
@ -1,10 +1,10 @@
|
|||||||
#ifndef UTF8_H
|
#ifndef UTF8_H
|
||||||
#define UTF8_H
|
#define UTF8_H
|
||||||
|
|
||||||
typedef unsigned int unicode_t;
|
typedef unsigned int unicode_t ;
|
||||||
|
|
||||||
unsigned utf8_to_unicode( char *line, unsigned index, unsigned len,
|
unsigned utf8_to_unicode( char *line, unsigned index, unsigned len,
|
||||||
unicode_t *res) ;
|
unicode_t *res) ;
|
||||||
unsigned unicode_to_utf8( unsigned int c, char *utf8) ;
|
unsigned unicode_to_utf8( unicode_t c, char *utf8) ;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user