26 #ifndef _UTF8REWIND_INTERNAL_BASE_H_
27 #define _UTF8REWIND_INTERNAL_BASE_H_
38 #if defined(__GNUC__) && !defined(COMPILER_ICC)
39 #define UTF8_UNUSED(_parameter) _parameter __attribute__ ((unused))
41 #define UTF8_UNUSED(_parameter) _parameter
44 #define UTF8_SET_ERROR(_error) \
45 if (errors != 0) { *errors = UTF8_ERR_ ## _error; }
50 #define UTF8_VALIDATE_PARAMETERS_CHAR(_inputType, _result) \
52 UTF8_SET_ERROR(INVALID_DATA); \
55 else if (inputSize < sizeof(_inputType)) { \
57 if (targetSize < 3) { \
58 UTF8_SET_ERROR(NOT_ENOUGH_SPACE); \
61 memcpy(target, REPLACEMENT_CHARACTER_STRING, REPLACEMENT_CHARACTER_STRING_LENGTH); \
63 UTF8_SET_ERROR(INVALID_DATA); \
64 return _result + REPLACEMENT_CHARACTER_STRING_LENGTH; \
66 if (target != 0 && targetSize == 0) { \
67 UTF8_SET_ERROR(NOT_ENOUGH_SPACE); \
70 if ((char*)input == target) { \
71 UTF8_SET_ERROR(OVERLAPPING_PARAMETERS); \
75 char* input_center = (char*)input + (inputSize / 2); \
76 char* target_center = target + (targetSize / 2); \
77 size_t delta = (size_t)((input_center > target_center) ? (input_center - target_center) : (target_center - input_center)); \
78 if (delta < (inputSize + targetSize) / 2) { \
79 UTF8_SET_ERROR(OVERLAPPING_PARAMETERS); \
84 #define UTF8_VALIDATE_PARAMETERS(_inputType, _outputType, _result) \
86 UTF8_SET_ERROR(INVALID_DATA); \
89 else if (inputSize < sizeof(_inputType)) { \
91 if (targetSize < sizeof(_outputType)) { \
92 UTF8_SET_ERROR(NOT_ENOUGH_SPACE); \
95 *target = REPLACEMENT_CHARACTER; \
97 UTF8_SET_ERROR(INVALID_DATA); \
98 return _result + sizeof(_outputType); \
100 if (target != 0 && targetSize < sizeof(_outputType)) { \
101 UTF8_SET_ERROR(NOT_ENOUGH_SPACE); \
104 if ((char*)input == (char*)target) { \
105 UTF8_SET_ERROR(OVERLAPPING_PARAMETERS); \
109 char* input_center = (char*)input + (inputSize / 2); \
110 char* target_center = (char*)target + (targetSize / 2); \
111 size_t delta = (size_t)((input_center > target_center) ? (input_center - target_center) : (target_center - input_center)); \
112 if (delta < (inputSize + targetSize) / 2) { \
113 UTF8_SET_ERROR(OVERLAPPING_PARAMETERS); \
Public interface for UTF-8 functions.