utf8proc
diff utf8proc.c @ 15:15450ff3d454
Contribution from libmojibake fork
| author | Jiahao Chen, Steven G. Johnson, Anthony David Kelman |
|---|---|
| date | Fri Nov 21 08:27:44 2014 -0500 (2014-11-21) |
| parents | d0bab6ca89a5 |
| children |
line diff
1.1 --- a/utf8proc.c Wed Nov 27 12:00:00 2013 +0100 1.2 +++ b/utf8proc.c Fri Nov 21 08:27:44 2014 -0500 1.3 @@ -43,7 +43,7 @@ 1.4 #include "utf8proc_data.c" 1.5 1.6 1.7 -const int8_t utf8proc_utf8class[256] = { 1.8 +DLLEXPORT const int8_t utf8proc_utf8class[256] = { 1.9 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.10 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.11 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.12 @@ -95,11 +95,11 @@ 1.13 #define UTF8PROC_BOUNDCLASS_LVT 10 1.14 1.15 1.16 -const char *utf8proc_version(void) { 1.17 +DLLEXPORT const char *utf8proc_version(void) { 1.18 return "1.1.6"; 1.19 } 1.20 1.21 -const char *utf8proc_errmsg(ssize_t errcode) { 1.22 +DLLEXPORT const char *utf8proc_errmsg(ssize_t errcode) { 1.23 switch (errcode) { 1.24 case UTF8PROC_ERROR_NOMEM: 1.25 return "Memory for processing UTF-8 data could not be allocated."; 1.26 @@ -112,11 +112,11 @@ 1.27 case UTF8PROC_ERROR_INVALIDOPTS: 1.28 return "Invalid options for UTF-8 processing chosen."; 1.29 default: 1.30 - return "An unknown error occured while processing UTF-8 data."; 1.31 + return "An unknown error occurred while processing UTF-8 data."; 1.32 } 1.33 } 1.34 1.35 -ssize_t utf8proc_iterate( 1.36 +DLLEXPORT ssize_t utf8proc_iterate( 1.37 const uint8_t *str, ssize_t strlen, int32_t *dst 1.38 ) { 1.39 int length; 1.40 @@ -156,14 +156,14 @@ 1.41 return length; 1.42 } 1.43 1.44 -bool utf8proc_codepoint_valid(int32_t uc) { 1.45 +DLLEXPORT bool utf8proc_codepoint_valid(int32_t uc) { 1.46 if (uc < 0 || uc >= 0x110000 || 1.47 ((uc & 0xFFFF) >= 0xFFFE) || (uc >= 0xD800 && uc < 0xE000) || 1.48 (uc >= 0xFDD0 && uc < 0xFDF0)) return false; 1.49 else return true; 1.50 } 1.51 1.52 -ssize_t utf8proc_encode_char(int32_t uc, uint8_t *dst) { 1.53 +DLLEXPORT ssize_t utf8proc_encode_char(int32_t uc, uint8_t *dst) { 1.54 if (uc < 0x00) { 1.55 return 0; 1.56 } else if (uc < 0x80) { 1.57 @@ -193,7 +193,7 @@ 1.58 } else return 0; 1.59 } 1.60 1.61 -const utf8proc_property_t *utf8proc_get_property(int32_t uc) { 1.62 +DLLEXPORT const utf8proc_property_t *utf8proc_get_property(int32_t uc) { 1.63 /* ASSERT: uc >= 0 && uc < 0x110000 */ 1.64 return utf8proc_properties + ( 1.65 utf8proc_stage2table[ 1.66 @@ -206,7 +206,7 @@ 1.67 return utf8proc_decompose_char((replacement_uc), dst, bufsize, \ 1.68 options & ~UTF8PROC_LUMP, last_boundclass) 1.69 1.70 -ssize_t utf8proc_decompose_char(int32_t uc, int32_t *dst, ssize_t bufsize, 1.71 +DLLEXPORT ssize_t utf8proc_decompose_char(int32_t uc, int32_t *dst, ssize_t bufsize, 1.72 int options, int *last_boundclass) { 1.73 /* ASSERT: uc >= 0 && uc < 0x110000 */ 1.74 const utf8proc_property_t *property; 1.75 @@ -351,7 +351,7 @@ 1.76 return 1; 1.77 } 1.78 1.79 -ssize_t utf8proc_decompose( 1.80 +DLLEXPORT ssize_t utf8proc_decompose( 1.81 const uint8_t *str, ssize_t strlen, 1.82 int32_t *buffer, ssize_t bufsize, int options 1.83 ) { 1.84 @@ -370,7 +370,7 @@ 1.85 while (1) { 1.86 if (options & UTF8PROC_NULLTERM) { 1.87 rpos += utf8proc_iterate(str + rpos, -1, &uc); 1.88 - /* checking of return value is not neccessary, 1.89 + /* checking of return value is not necessary, 1.90 as 'uc' is < 0 in case of error */ 1.91 if (uc < 0) return UTF8PROC_ERROR_INVALIDUTF8; 1.92 if (rpos < 0) return UTF8PROC_ERROR_OVERFLOW; 1.93 @@ -413,7 +413,7 @@ 1.94 return wpos; 1.95 } 1.96 1.97 -ssize_t utf8proc_reencode(int32_t *buffer, ssize_t length, int options) { 1.98 +DLLEXPORT ssize_t utf8proc_reencode(int32_t *buffer, ssize_t length, int options) { 1.99 /* UTF8PROC_NULLTERM option will be ignored, 'length' is never ignored 1.100 ASSERT: 'buffer' has one spare byte of free space at the end! */ 1.101 if (options & (UTF8PROC_NLF2LS | UTF8PROC_NLF2PS | UTF8PROC_STRIPCC)) { 1.102 @@ -528,7 +528,7 @@ 1.103 } 1.104 } 1.105 1.106 -ssize_t utf8proc_map( 1.107 +DLLEXPORT ssize_t utf8proc_map( 1.108 const uint8_t *str, ssize_t strlen, uint8_t **dstptr, int options 1.109 ) { 1.110 int32_t *buffer; 1.111 @@ -536,7 +536,7 @@ 1.112 *dstptr = NULL; 1.113 result = utf8proc_decompose(str, strlen, NULL, 0, options); 1.114 if (result < 0) return result; 1.115 - buffer = malloc(result * sizeof(int32_t) + 1); 1.116 + buffer = (int32_t *) malloc(result * sizeof(int32_t) + 1); 1.117 if (!buffer) return UTF8PROC_ERROR_NOMEM; 1.118 result = utf8proc_decompose(str, strlen, buffer, result, options); 1.119 if (result < 0) { 1.120 @@ -550,35 +550,35 @@ 1.121 } 1.122 { 1.123 int32_t *newptr; 1.124 - newptr = realloc(buffer, (size_t)result+1); 1.125 + newptr = (int32_t *) realloc(buffer, (size_t)result+1); 1.126 if (newptr) buffer = newptr; 1.127 } 1.128 *dstptr = (uint8_t *)buffer; 1.129 return result; 1.130 } 1.131 1.132 -uint8_t *utf8proc_NFD(const uint8_t *str) { 1.133 +DLLEXPORT uint8_t *utf8proc_NFD(const uint8_t *str) { 1.134 uint8_t *retval; 1.135 utf8proc_map(str, 0, &retval, UTF8PROC_NULLTERM | UTF8PROC_STABLE | 1.136 UTF8PROC_DECOMPOSE); 1.137 return retval; 1.138 } 1.139 1.140 -uint8_t *utf8proc_NFC(const uint8_t *str) { 1.141 +DLLEXPORT uint8_t *utf8proc_NFC(const uint8_t *str) { 1.142 uint8_t *retval; 1.143 utf8proc_map(str, 0, &retval, UTF8PROC_NULLTERM | UTF8PROC_STABLE | 1.144 UTF8PROC_COMPOSE); 1.145 return retval; 1.146 } 1.147 1.148 -uint8_t *utf8proc_NFKD(const uint8_t *str) { 1.149 +DLLEXPORT uint8_t *utf8proc_NFKD(const uint8_t *str) { 1.150 uint8_t *retval; 1.151 utf8proc_map(str, 0, &retval, UTF8PROC_NULLTERM | UTF8PROC_STABLE | 1.152 UTF8PROC_DECOMPOSE | UTF8PROC_COMPAT); 1.153 return retval; 1.154 } 1.155 1.156 -uint8_t *utf8proc_NFKC(const uint8_t *str) { 1.157 +DLLEXPORT uint8_t *utf8proc_NFKC(const uint8_t *str) { 1.158 uint8_t *retval; 1.159 utf8proc_map(str, 0, &retval, UTF8PROC_NULLTERM | UTF8PROC_STABLE | 1.160 UTF8PROC_COMPOSE | UTF8PROC_COMPAT);