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_RETURN(_error, _result) \
45 if (errors != 0) { *errors = UTF8_ERR_ ## _error; } \
51 #define UTF8_VALIDATE_PARAMETERS_CHAR(_inputType, _result) \
52 if (input == 0) { UTF8_RETURN(INVALID_DATA, _result); } \
53 else if (inputSize < sizeof(_inputType)) { \
55 if (targetSize < 3) { UTF8_RETURN(NOT_ENOUGH_SPACE, _result); } \
56 memcpy(target, REPLACEMENT_CHARACTER_STRING, REPLACEMENT_CHARACTER_STRING_LENGTH); \
58 UTF8_RETURN(INVALID_DATA, _result + REPLACEMENT_CHARACTER_STRING_LENGTH); \
60 if (target != 0 && targetSize == 0) { UTF8_RETURN(NOT_ENOUGH_SPACE, _result); } \
61 if ((char*)input == target) { UTF8_RETURN(OVERLAPPING_PARAMETERS, _result); } \
63 char* input_center = (char*)input + (inputSize / 2); \
64 char* target_center = target + (targetSize / 2); \
65 size_t delta = (size_t)((input_center > target_center) ? (input_center - target_center) : (target_center - input_center)); \
66 if (delta < (inputSize + targetSize) / 2) { UTF8_RETURN(OVERLAPPING_PARAMETERS, _result); } \
69 #define UTF8_VALIDATE_PARAMETERS(_inputType, _outputType, _result) \
70 if (input == 0) { UTF8_RETURN(INVALID_DATA, _result); } \
71 else if (inputSize < sizeof(_inputType)) { \
73 if (targetSize < sizeof(_outputType)) { UTF8_RETURN(NOT_ENOUGH_SPACE, _result); } \
74 *target = REPLACEMENT_CHARACTER; \
76 UTF8_RETURN(INVALID_DATA, _result + sizeof(_outputType)); \
78 if (target != 0 && targetSize < sizeof(_outputType)) { UTF8_RETURN(NOT_ENOUGH_SPACE, _result); } \
79 if ((char*)input == (char*)target) { UTF8_RETURN(OVERLAPPING_PARAMETERS, _result); } \
81 char* input_center = (char*)input + (inputSize / 2); \
82 char* target_center = (char*)target + (targetSize / 2); \
83 size_t delta = (size_t)((input_center > target_center) ? (input_center - target_center) : (target_center - input_center)); \
84 if (delta < (inputSize + targetSize) / 2) { UTF8_RETURN(OVERLAPPING_PARAMETERS, _result); } \
Public interface for UTF-8 functions.