mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 06:25:30 +00:00
ICU-647 update API docs and reinstate readable _SAFE macros from version 1.8
X-SVN-Rev: 3201
This commit is contained in:
parent
96c50174b4
commit
e09b328887
1 changed files with 28 additions and 95 deletions
|
@ -16,7 +16,7 @@
|
|||
|
||||
/**
|
||||
* \file
|
||||
* \brief Description of UTF-16 macros
|
||||
* \brief C API: UTF-16 macros
|
||||
*
|
||||
* This file defines macros to deal with UTF-16 code units and code points.
|
||||
* "Safe" macros check for length overruns and illegal sequences, and
|
||||
|
@ -77,8 +77,7 @@
|
|||
} \
|
||||
}
|
||||
|
||||
#define _UTF16_GET_CHAR_SAFE_1(s, start, i, length, c) \
|
||||
{ \
|
||||
#define UTF16_GET_CHAR_SAFE(s, start, i, length, c, strict) { \
|
||||
(c)=(s)[i]; \
|
||||
if(UTF_IS_SURROGATE(c)) { \
|
||||
uint16_t __c2; \
|
||||
|
@ -86,54 +85,23 @@
|
|||
if((i)+1<(length) && UTF_IS_SECOND_SURROGATE(__c2=(s)[(i)+1])) { \
|
||||
(c)=UTF16_GET_PAIR_VALUE((c), __c2); \
|
||||
/* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() */ \
|
||||
}
|
||||
|
||||
#define _UTF16_GET_CHAR_SAFE_2(s, start, i, length, c) \
|
||||
} else if(strict) {\
|
||||
/* unmatched first surrogate */ \
|
||||
(c)=UTF_ERROR_VALUE; \
|
||||
} \
|
||||
} else { \
|
||||
if((i)>(start) && UTF_IS_FIRST_SURROGATE(__c2=(s)[(i)-1])) { \
|
||||
(c)=UTF16_GET_PAIR_VALUE(__c2, (c)); \
|
||||
/* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() */ \
|
||||
}
|
||||
|
||||
#define _UTF16_SAFE_ERROR(c) \
|
||||
{ \
|
||||
/* unmatched first surrogate */ \
|
||||
} else if(strict) {\
|
||||
/* unmatched second surrogate */ \
|
||||
(c)=UTF_ERROR_VALUE; \
|
||||
}
|
||||
|
||||
#define _UTF16_GET_CHAR_SAFE_END \
|
||||
} \
|
||||
} \
|
||||
/* else strict: (c)==0xfffe is caught by UTF_IS_ERROR() */ \
|
||||
} \
|
||||
}
|
||||
|
||||
#define UTF16_GET_CHAR_SAFE(s, start, i, length, c, strict) \
|
||||
_UTF16_GET_CHAR_SAFE_1(s, start, i, length, c) \
|
||||
else if(strict) \
|
||||
_UTF16_SAFE_ERROR(c) \
|
||||
_UTF16_GET_CHAR_SAFE_2(s, start, i, length, c) \
|
||||
else if(strict) \
|
||||
_UTF16_SAFE_ERROR(c) \
|
||||
_UTF16_GET_CHAR_SAFE_END
|
||||
|
||||
/*
|
||||
* The following two macros will get around compilers complaining
|
||||
* about constant conditional statements.
|
||||
*/
|
||||
#define UTF16_GET_CHAR_SAFE_STRICT(s, start, i, length, c) \
|
||||
_UTF16_GET_CHAR_SAFE_1(s, start, i, length, c) \
|
||||
else \
|
||||
_UTF16_SAFE_ERROR(c) \
|
||||
_UTF16_GET_CHAR_SAFE_2(s, start, i, length, c) \
|
||||
else \
|
||||
_UTF16_SAFE_ERROR(c) \
|
||||
_UTF16_GET_CHAR_SAFE_END
|
||||
|
||||
#define UTF16_GET_CHAR_SAFE_LENIENT(s, start, i, length, c) \
|
||||
_UTF16_GET_CHAR_SAFE_1(s, start, i, length, c) \
|
||||
_UTF16_GET_CHAR_SAFE_2(s, start, i, length, c) \
|
||||
_UTF16_GET_CHAR_SAFE_END
|
||||
|
||||
/* definitions with forward iteration --------------------------------------- */
|
||||
|
||||
/*
|
||||
|
@ -196,7 +164,7 @@
|
|||
|
||||
/* safe versions with error-checking and optional regularity-checking */
|
||||
|
||||
#define _UTF16_NEXT_CHAR_SAFE_1(s, i, length, c) \
|
||||
#define UTF16_NEXT_CHAR_SAFE(s, i, length, c, strict) { \
|
||||
(c)=(s)[(i)++]; \
|
||||
if(UTF_IS_FIRST_SURROGATE(c)) { \
|
||||
uint16_t __c2; \
|
||||
|
@ -204,33 +172,14 @@
|
|||
++(i); \
|
||||
(c)=UTF16_GET_PAIR_VALUE((c), __c2); \
|
||||
/* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() */ \
|
||||
}
|
||||
|
||||
#define _UTF16_NEXT_CHAR_SAFE_END \
|
||||
} \
|
||||
}
|
||||
|
||||
#define UTF16_NEXT_CHAR_SAFE(s, i, length, c, strict) \
|
||||
{ \
|
||||
_UTF16_NEXT_CHAR_SAFE_1(s, i, length, c) \
|
||||
else if(strict) \
|
||||
_UTF16_SAFE_ERROR(c) \
|
||||
} else if(strict && UTF_IS_SECOND_SURROGATE(c)) \
|
||||
_UTF16_SAFE_ERROR(c) \
|
||||
}
|
||||
|
||||
#define UTF16_NEXT_CHAR_SAFE_STRICT(s, i, length, c) \
|
||||
{ \
|
||||
_UTF16_NEXT_CHAR_SAFE_1(s, i, length, c) \
|
||||
else \
|
||||
_UTF16_SAFE_ERROR(c) \
|
||||
} else if(UTF_IS_SECOND_SURROGATE(c)) \
|
||||
_UTF16_SAFE_ERROR(c) \
|
||||
}
|
||||
|
||||
#define UTF16_NEXT_CHAR_SAFE_LENIENT(s, i, length, c) \
|
||||
{ \
|
||||
_UTF16_NEXT_CHAR_SAFE_1(s, i, length, c) \
|
||||
} else if(strict) {\
|
||||
/* unmatched first surrogate */ \
|
||||
(c)=UTF_ERROR_VALUE; \
|
||||
} \
|
||||
} else if(strict && UTF_IS_SECOND_SURROGATE(c)) { \
|
||||
/* unmatched second surrogate */ \
|
||||
(c)=UTF_ERROR_VALUE; \
|
||||
/* else strict: (c)==0xfffe is caught by UTF_IS_ERROR() */ \
|
||||
} \
|
||||
}
|
||||
|
||||
|
@ -240,7 +189,7 @@
|
|||
} else if((uint32_t)(c)<=0x10ffff) { \
|
||||
if((i)+1<(length)) { \
|
||||
(s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \
|
||||
(s)[(i)++]=(uint16_t)((c)&0x3ff|0xdc00); \
|
||||
(s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \
|
||||
} else /* not enough space */ { \
|
||||
(s)[(i)++]=UTF_ERROR_VALUE; \
|
||||
} \
|
||||
|
@ -323,7 +272,7 @@
|
|||
|
||||
/* safe versions with error-checking and optional regularity-checking */
|
||||
|
||||
#define _UTF16_PREV_CHAR_SAFE_1(s, start, i, c) \
|
||||
#define UTF16_PREV_CHAR_SAFE(s, start, i, c, strict) { \
|
||||
(c)=(s)[--(i)]; \
|
||||
if(UTF_IS_SECOND_SURROGATE(c)) { \
|
||||
uint16_t __c2; \
|
||||
|
@ -331,30 +280,14 @@
|
|||
--(i); \
|
||||
(c)=UTF16_GET_PAIR_VALUE(__c2, (c)); \
|
||||
/* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() */ \
|
||||
}
|
||||
|
||||
|
||||
#define UTF16_PREV_CHAR_SAFE(s, start, i, c, strict) \
|
||||
{ \
|
||||
_UTF16_PREV_CHAR_SAFE_1(s, start, i, c) \
|
||||
else if(strict) \
|
||||
_UTF16_SAFE_ERROR(c) \
|
||||
} else if(strict && UTF_IS_FIRST_SURROGATE(c)) \
|
||||
_UTF16_SAFE_ERROR(c) \
|
||||
}
|
||||
|
||||
#define UTF16_PREV_CHAR_SAFE_STRICT(s, start, i, c) \
|
||||
{ \
|
||||
_UTF16_PREV_CHAR_SAFE_1(s, start, i, c) \
|
||||
else \
|
||||
_UTF16_SAFE_ERROR(c) \
|
||||
} else if (UTF_IS_FIRST_SURROGATE(c)) \
|
||||
_UTF16_SAFE_ERROR(c) \
|
||||
}
|
||||
|
||||
#define UTF16_PREV_CHAR_SAFE_LENIENT(s, start, i, c) \
|
||||
{ \
|
||||
_UTF16_PREV_CHAR_SAFE_1(s, start, i, c) \
|
||||
} else if(strict) {\
|
||||
/* unmatched second surrogate */ \
|
||||
(c)=UTF_ERROR_VALUE; \
|
||||
} \
|
||||
} else if(strict && UTF_IS_FIRST_SURROGATE(c)) { \
|
||||
/* unmatched first surrogate */ \
|
||||
(c)=UTF_ERROR_VALUE; \
|
||||
/* else strict: (c)==0xfffe is caught by UTF_IS_ERROR() */ \
|
||||
} \
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue