sublatin.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. #ifdef NEED_SUBLATIN_C
  2. #include "sublatin.h"
  3. // AccentedChars = "ÀÁÂÃÄÅàáâãäåÈÉÊËèéêëÌÍÎÏìíîïÒÓÔÕÖØòóôõöøÙÚÛÜùúûüÝÿýÑñÇç"
  4. // deAccentedChars = "AAAAAAaaaaaaEEEEeeeeIIIIiiiiOOOOOOooooooUUUUuuuuYyyNnCc"
  5. // deAccentedLowerChars = "aaaaaaaaaaaaeeeeeeeeiiiiiiiioooooooooooouuuuuuuuyyynncc"
  6. // upperCaseAccentedChars = "ÀÁÂÃÄÅÈÉÊËÌÍÎÏÒÓÔÕÖØÙÚÛÜÝ"
  7. // lowerCaseAccentedChars = "àáâãäåèéêëìíîïòóôõöøùúûüý"
  8. // upperCaseChars = "ABCDEFGHIJKLMNOPQRSTUVWXZY"
  9. // lowerCaseChars = "abcdefghijklmnopqrstuvwxzy"
  10. const unsigned char deAccentMapTable[] = { //0
  11. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, //16
  12. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, //32
  13. 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, //48
  14. 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, //64
  15. 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, //80
  16. 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, //96
  17. 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, //112
  18. 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, //128
  19. 65, 65, 65, 65, 65, 65, 134, 67, 69, 69, 69, 69, 73, 73, 73, 73, //144
  20. 144, 78, 79, 79, 79, 79, 79, 151, 79, 85, 85, 85, 85, 89, 158, 159, //160
  21. 97, 97, 97, 97, 97, 97, 166, 99, 101, 101, 101, 101, 105, 105, 105, 105, //176
  22. 176, 110, 111, 111, 111, 111, 111, 183, 111, 117, 117, 117, 117, 121, 190, 121, //192
  23. 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, //208
  24. 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, //224
  25. 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, //240
  26. 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
  27. };
  28. const unsigned char toLowerMapTable[] = { //0
  29. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, //16
  30. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, //32
  31. 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, //48
  32. 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, //64
  33. 64, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, //80
  34. 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 91, 92, 93, 94, 95, //96
  35. 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, //112
  36. 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, //128
  37. 160, 161, 162, 163, 164, 165, 134, 167, 168, 169, 170, 171, 172, 173, 174, 175, //144
  38. 144, 177, 178, 179, 180, 181, 182, 151, 184, 185, 186, 187, 188, 189, 158, 159, //160
  39. 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, //176
  40. 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, //192
  41. 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, //208
  42. 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, //224
  43. 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, //240
  44. 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
  45. };
  46. const unsigned char toUpperMapTable[] = { //0
  47. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, //16
  48. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, //32
  49. 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, //48
  50. 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, //64
  51. 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, //80
  52. 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, //96
  53. 96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, //112
  54. 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 123, 124, 125, 126, 127, //128
  55. 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, //144
  56. 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, //160
  57. 128, 129, 130, 131, 132, 133, 166, 135, 136, 137, 138, 139, 140, 141, 142, 143, //176
  58. 176, 145, 146, 147, 148, 149, 150, 183, 152, 153, 154, 155, 156, 157, 190, 191, //192
  59. 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, //208
  60. 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, //224
  61. 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, //240
  62. 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
  63. };
  64. const unsigned char toLowerDeaccentedMapTable[] = { //0
  65. 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,//16
  66. 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,//32
  67. 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,//48
  68. 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,//64
  69. 64,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,//80
  70. 112,113,114,115,116,117,118,119,120,121,122,91,92,93,94,95,//96
  71. 96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,//112
  72. 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,//128
  73. 97,97,97,97,97,97,134,99,101,101,101,101,105,105,105,105,//144
  74. 144,110,111,111,111,111,111,151,111,117,117,117,117,121,158,159,//160
  75. 97,97,97,97,97,97,166,99,101,101,101,101,105,105,105,105,//176
  76. 176,110,111,111,111,111,111,183,111,117,117,117,117,121,190,121,//192
  77. 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,//208
  78. 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,//224
  79. 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,//240
  80. 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
  81. };
  82. const unsigned char isLowerMapTable[] = { //0
  83. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //16
  84. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //32
  85. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //48
  86. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //64
  87. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //80
  88. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //96
  89. 0, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, //112
  90. 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 0, 0, 0, 0, 0, //128
  91. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //144
  92. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //160
  93. 160, 161, 162, 163, 164, 165, 0, 167, 168, 169, 170, 171, 172, 173, 174, 175, //176
  94. 0, 177, 178, 179, 180, 181, 182, 0, 184, 185, 186, 187, 188, 189, 0, 0, //192
  95. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //208
  96. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //224
  97. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //240
  98. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  99. };
  100. const unsigned char isUpperMapTable[] = { //0
  101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //16
  102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //32
  103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //48
  104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //64
  105. 0, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, //80
  106. 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 0, 0, 0, 0, 0, //96
  107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //112
  108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //128
  109. 128, 129, 130, 131, 132, 133, 0, 135, 136, 137, 138, 139, 140, 141, 142, 143, //144
  110. 0, 145, 146, 147, 148, 149, 150, 0, 152, 153, 154, 155, 156, 157, 0, 0, //160
  111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //176
  112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //192
  113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //208
  114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //224
  115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //240
  116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117. };
  118. int nstrLenSubSetLatinUtf8( const char *str, int n )
  119. {
  120. int result = 0;
  121. const unsigned char *pstr = ( const unsigned char * )str;
  122. while ( *pstr && (--n >= 0) ) {
  123. // an error when an utf8 char is formed by 195#195 ???
  124. if ( *pstr != 195 ) ++result;
  125. ++pstr;
  126. }
  127. return result;
  128. }
  129. int strLenSubSetLatinUtf8( const char *str ) {
  130. int result = 0;
  131. const unsigned char *pstr = ( const unsigned char * )str;
  132. while ( *pstr ) {
  133. // an error when an utf8 char is formed by 195#195 ???
  134. if ( *pstr != 195 ) ++result;
  135. ++pstr;
  136. }
  137. return result;
  138. }
  139. int isDeaccentableSubSetLatinUtf8( const char *str ) {
  140. unsigned int c1, c2;
  141. const unsigned char *pstr = ( const unsigned char * )str;
  142. if ( *pstr == 195 ) {
  143. c1 = *( pstr + 1 );
  144. c2 = deAccentMap( c1 );
  145. if ( c1 != c2 ) return c2;
  146. }
  147. return 0;
  148. }
  149. char *toLowerDeaccentSubSetLatinUtf8( char *str ) {
  150. unsigned char *ptrStr, *ptrStr2;
  151. if ( !str ) return str;
  152. ptrStr2 = ptrStr = ( unsigned char* )str;
  153. while ( *ptrStr ) {
  154. if ( *ptrStr == 195 ) ++ptrStr;
  155. *ptrStr2 = toLowerDeaccentedMap( *ptrStr );
  156. ++ptrStr;
  157. ++ptrStr2;
  158. }
  159. *ptrStr2 = 0;
  160. return str;
  161. }
  162. char *deAccentSubSetLatinUtf8( char *str ) {
  163. unsigned char *ptrStr, *ptrStr2;
  164. if ( !str ) return str;
  165. ptrStr2 = ptrStr = ( unsigned char* )str;
  166. while ( *ptrStr ) {
  167. if ( *ptrStr == 195 ) ++ptrStr;
  168. *ptrStr2 = deAccentMap( *ptrStr );
  169. ++ptrStr;
  170. ++ptrStr2;
  171. }
  172. *ptrStr2 = 0;
  173. return str;
  174. }
  175. char *toLowerSubSetLatinUtf8( char *str ) {
  176. unsigned char *ptrStr;
  177. if ( !str ) return str;
  178. ptrStr = ( unsigned char * )str;
  179. while ( *ptrStr ) {
  180. if ( *ptrStr == 195 ) ++ptrStr;
  181. *ptrStr = toLowerMap( *ptrStr );
  182. ++ptrStr;
  183. }
  184. return str;
  185. }
  186. char *toUpperSubSetLatinUtf8( char *str ) {
  187. unsigned char *ptrStr;
  188. if ( !str ) return str;
  189. ptrStr = ( unsigned char * )str;
  190. while ( *ptrStr ) {
  191. if ( *ptrStr == 195 ) ++ptrStr;
  192. *ptrStr = toUpperMap( *ptrStr );
  193. ++ptrStr;
  194. }
  195. return str;
  196. }
  197. #define checkToLowerSubSetLatinUtf8( a, b ) \
  198. if ( (*(const unsigned char *)b) == 195 ) ++b;\
  199. a = toLowerMap(*b)
  200. int strICmpSubSetLatinUtf8( const char *zLeft, const char *zRight ) {
  201. const unsigned char *a, *b;
  202. unsigned char a2, b2;
  203. a2 = b2 = '\0';
  204. a = (const unsigned char* )zLeft;
  205. b = ( const unsigned char* )zRight;
  206. while ( *a && *b) {
  207. checkToLowerSubSetLatinUtf8( a2, a );
  208. checkToLowerSubSetLatinUtf8( b2, b );
  209. if ( a2 != b2 ) break;
  210. a++;
  211. b++;
  212. }
  213. return a2 - b2;
  214. }
  215. #define checkLowerDeAccentSubSetLatinUtf8( a, b ) \
  216. if ( (*(const unsigned char *)b) == 195 ) b++;\
  217. a = toLowerDeaccentedMap(*b)
  218. int strICmpSubSetLatinUtf8NoAccents( const char *zLeft, const char *zRight ) {
  219. const unsigned char *a, *b;
  220. unsigned char a2, b2;
  221. a2 = b2 = '\0';
  222. a = ( const unsigned char * )zLeft;
  223. b = ( const unsigned char * )zRight;
  224. while ( *a && *b) {
  225. checkLowerDeAccentSubSetLatinUtf8( a2, a );
  226. checkLowerDeAccentSubSetLatinUtf8( b2, b );
  227. if ( a2 - b2 ) break;
  228. a++;
  229. b++;
  230. }
  231. return a2 - b2;
  232. }
  233. #define checkDeAccentSubSetLatinUtf8( a, b ) \
  234. if ( (*(const unsigned char *)b) == 195 ) b++;\
  235. a = deAccentMap(*b)
  236. int strCmpSubSetLatinUtf8NoAccents( const char *zLeft, const char *zRight ) {
  237. const unsigned char *a, *b;
  238. unsigned char a2, b2;
  239. a2 = b2 = '\0';
  240. a = ( const unsigned char * )zLeft;
  241. b = ( const unsigned char * )zRight;
  242. while ( *a && *b) {
  243. checkDeAccentSubSetLatinUtf8( a2, a );
  244. checkDeAccentSubSetLatinUtf8( b2, b );
  245. if ( a2 - b2 ) break;
  246. a++;
  247. b++;
  248. }
  249. return ( a2 - b2 );
  250. }
  251. // the N parameter is expected to be utf8 chars count
  252. int strNICmpSubSetLatinUtf8( const char *zLeft, const char *zRight, int n ) {
  253. const unsigned char *a, *b;
  254. unsigned char a2, b2;
  255. a2 = b2 = '\0';
  256. a = ( const unsigned char * )zLeft;
  257. b = ( const unsigned char * )zRight;
  258. while ( *a && *b ) {
  259. if ( --n < 0 ) break;
  260. checkToLowerSubSetLatinUtf8( a2, a );
  261. checkToLowerSubSetLatinUtf8( b2, b );
  262. if ( a2 != b2 ) break;
  263. a++;
  264. b++;
  265. }
  266. return ( a2 - b2 );
  267. }
  268. // the N parameter is expected to be utf8 chars count
  269. int strNICmpSubSetLatinUtf8NoAccents( const char *zLeft, const char *zRight, int n ) {
  270. const unsigned char *a, *b;
  271. unsigned char a2, b2;
  272. a2 = b2 = '\0';
  273. a = ( const unsigned char * )zLeft;
  274. b = ( const unsigned char * )zRight;
  275. while ( *a && *b) {
  276. if ( --n < 0 ) break;
  277. checkLowerDeAccentSubSetLatinUtf8( a2, a );
  278. checkLowerDeAccentSubSetLatinUtf8( b2, b );
  279. if ( a2 - b2 ) break;
  280. a++;
  281. b++;
  282. }
  283. return( a2 - b2 );
  284. }
  285. // the N parameter is expected to be utf8 chars count
  286. int strNCmpSubSetLatinUtf8NoAccents( const char *zLeft, const char *zRight, int n ) {
  287. const unsigned char *a, *b;
  288. unsigned char a2, b2;
  289. a2 = b2 = '\0';
  290. a = ( const unsigned char * )zLeft;
  291. b = ( const unsigned char * )zRight;
  292. while ( *a && *b) {
  293. if ( --n < 0 ) break;
  294. checkDeAccentSubSetLatinUtf8( a2, a );
  295. checkDeAccentSubSetLatinUtf8( b2, b );
  296. if ( a2 != b2 ) break;
  297. a++;
  298. b++;
  299. }
  300. return( a2 - b2 );
  301. }
  302. /*
  303. ** Compare two UTF-8 strings for equality where the first string is
  304. ** a "LIKE" expression. Return true (1) if they are the same and
  305. ** false (0) if they are different.
  306. */
  307. static int subLatinLikeCompare0(
  308. const char *zPattern, //* LIKE pattern */
  309. const char *zString, //* The UTF-8 string to compare against */
  310. char cEsc, //* The escape character */
  311. int deaccent //if to compare deaccented
  312. ) {
  313. char MATCH_ONE, MATCH_ALL, cPattern, cString, c;
  314. int iPattern, iString;
  315. int prevEscape;
  316. #define checkStringChar() \
  317. if( *(const unsigned char*)(zString+iString) == 195 ) iString++;
  318. #define nextStringChar() \
  319. iString++;\
  320. if( *(const unsigned char*)(zString+iString) == 195 ) iString++;
  321. #define checkPatternChar()\
  322. if( *(const unsigned char*)(zPattern+iPattern) == 195 ) iPattern++;
  323. #define nextPatternChar()\
  324. iPattern++;\
  325. if( *(const unsigned char*)(zPattern+iPattern) == 195 ) iPattern++;
  326. MATCH_ONE = '_';
  327. MATCH_ALL = '%';
  328. iPattern = 0; //* Current byte index in zPattern */
  329. iString = 0; //* Current byte index in zString */
  330. prevEscape = 0; //* True if the previous character was uEsc */
  331. //what if the pattern is a 195##195 ?????
  332. checkPatternChar();
  333. checkStringChar();
  334. while ( *( zPattern + iPattern ) ) {
  335. //* Read (and consume) the next character from the input pattern. */
  336. cPattern = *( zPattern + iPattern );
  337. nextPatternChar();
  338. //assert(uPattern!=0);
  339. /* There are now 4 possibilities:
  340. **
  341. ** 1. uPattern is an unescaped match-all character "%",
  342. ** 2. uPattern is an unescaped match-one character "_",
  343. ** 3. uPattern is an unescaped escape character, or
  344. ** 4. uPattern is to be handled as an ordinary character
  345. */
  346. if ( ( ! prevEscape ) && ( cPattern == MATCH_ALL ) ) {
  347. ///* Case 1. */
  348. /* Skip any MATCH_ALL or MATCH_ONE characters that follow a
  349. ** MATCH_ALL. For each MATCH_ONE, skip one character in the
  350. ** test string.
  351. */
  352. c = *( zPattern + iPattern );
  353. while ( ( c == MATCH_ALL ) || ( c == MATCH_ONE ) ) {
  354. if ( c == MATCH_ONE ) {
  355. if ( !*( zString + iString ) ) return 0;
  356. //U8_FWD_1_UNSAFE(zString, iString);
  357. nextStringChar();
  358. }
  359. nextPatternChar();
  360. c = *( zPattern + iPattern );
  361. }
  362. if ( !*( zPattern + iPattern ) ) return 1;
  363. while ( *( zString + iString ) ) {
  364. if ( subLatinLikeCompare0( zPattern + iPattern, zString + iString, cEsc, deaccent ) ) return 1;
  365. //U8_FWD_1_UNSAFE(zString, iString);
  366. nextStringChar();
  367. }
  368. return 0;
  369. } else if ( ( ! prevEscape ) && ( cPattern == MATCH_ONE ) ) {
  370. //* Case 2. */
  371. if ( !*( zString + iString ) ) return 0;
  372. //U8_FWD_1_UNSAFE(zString, iString);
  373. nextStringChar();
  374. } else if ( ( ! prevEscape ) && ( cPattern == cEsc ) ) {
  375. //* Case 3. */
  376. prevEscape = 1;
  377. } else {
  378. //* Case 4. */
  379. //UChar32 uString;
  380. //U8_NEXT_UNSAFE(zString, iString, uString);
  381. cString = *( zString + iString );
  382. if ( deaccent ) {
  383. if ( toLowerDeaccentedMap( cString ) != toLowerDeaccentedMap( cPattern ) ) return 0;
  384. } else {
  385. if ( toLowerMap( cString ) != toLowerMap( cPattern ) ) return 0;
  386. }
  387. prevEscape = 0;
  388. nextStringChar();
  389. }
  390. }
  391. if ( !*( zString + iString ) ) return 1;
  392. else return 0;
  393. }
  394. int subLatinLikeCompare(
  395. const char *zPattern, //* LIKE pattern */
  396. const char *zString, //* The UTF-8 string to compare against */
  397. char cEsc //* The escape character */
  398. ) {
  399. return subLatinLikeCompare0( zPattern, zString, cEsc, 0 );
  400. }
  401. int subLatinLikeCompareNoAccents(
  402. const char *zPattern, //* LIKE pattern */
  403. const char *zString, //* The UTF-8 string to compare against */
  404. char cEsc //* The escape character */
  405. ) {
  406. return subLatinLikeCompare0( zPattern, zString, cEsc, 1 );
  407. }
  408. #endif //NEED_SUBLATIN_C