value.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*
  2. * Copyright [2021] JD.com, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. const unsigned char internal_tolower_table_[256] = {
  17. 0x00,
  18. 0x01,
  19. 0x02,
  20. 0x03,
  21. 0x04,
  22. 0x05,
  23. 0x06,
  24. 0x07,
  25. 0x08,
  26. 0x09,
  27. 0x0A,
  28. 0x0B,
  29. 0x0C,
  30. 0x0D,
  31. 0x0E,
  32. 0x0F,
  33. 0x10,
  34. 0x11,
  35. 0x12,
  36. 0x13,
  37. 0x14,
  38. 0x15,
  39. 0x16,
  40. 0x17,
  41. 0x18,
  42. 0x19,
  43. 0x1A,
  44. 0x1B,
  45. 0x1C,
  46. 0x1D,
  47. 0x1E,
  48. 0x1F,
  49. 0x20,
  50. 0x21,
  51. 0x22,
  52. 0x23,
  53. 0x24,
  54. 0x25,
  55. 0x26,
  56. 0x27,
  57. 0x28,
  58. 0x29,
  59. 0x2A,
  60. 0x2B,
  61. 0x2C,
  62. 0x2D,
  63. 0x2E,
  64. 0x2F,
  65. 0x30,
  66. 0x31,
  67. 0x32,
  68. 0x33,
  69. 0x34,
  70. 0x35,
  71. 0x36,
  72. 0x37,
  73. 0x38,
  74. 0x39,
  75. 0x3A,
  76. 0x3B,
  77. 0x3C,
  78. 0x3D,
  79. 0x3E,
  80. 0x3F,
  81. 0x40,
  82. 0x61,
  83. 0x62,
  84. 0x63,
  85. 0x64,
  86. 0x65,
  87. 0x66,
  88. 0x67,
  89. 0x68,
  90. 0x69,
  91. 0x6A,
  92. 0x6B,
  93. 0x6C,
  94. 0x6D,
  95. 0x6E,
  96. 0x6F,
  97. 0x70,
  98. 0x71,
  99. 0x72,
  100. 0x73,
  101. 0x74,
  102. 0x75,
  103. 0x76,
  104. 0x77,
  105. 0x78,
  106. 0x79,
  107. 0x7A,
  108. 0x5B,
  109. 0x5C,
  110. 0x5D,
  111. 0x5E,
  112. 0x5F,
  113. 0x60,
  114. 0x61,
  115. 0x62,
  116. 0x63,
  117. 0x64,
  118. 0x65,
  119. 0x66,
  120. 0x67,
  121. 0x68,
  122. 0x69,
  123. 0x6A,
  124. 0x6B,
  125. 0x6C,
  126. 0x6D,
  127. 0x6E,
  128. 0x6F,
  129. 0x70,
  130. 0x71,
  131. 0x72,
  132. 0x73,
  133. 0x74,
  134. 0x75,
  135. 0x76,
  136. 0x77,
  137. 0x78,
  138. 0x79,
  139. 0x7A,
  140. 0x7B,
  141. 0x7C,
  142. 0x7D,
  143. 0x7E,
  144. 0x7F,
  145. 0x80,
  146. 0x81,
  147. 0x82,
  148. 0x83,
  149. 0x84,
  150. 0x85,
  151. 0x86,
  152. 0x87,
  153. 0x88,
  154. 0x89,
  155. 0x8A,
  156. 0x8B,
  157. 0x8C,
  158. 0x8D,
  159. 0x8E,
  160. 0x8F,
  161. 0x90,
  162. 0x91,
  163. 0x92,
  164. 0x93,
  165. 0x94,
  166. 0x95,
  167. 0x96,
  168. 0x97,
  169. 0x98,
  170. 0x99,
  171. 0x9A,
  172. 0x9B,
  173. 0x9C,
  174. 0x9D,
  175. 0x9E,
  176. 0x9F,
  177. 0xA0,
  178. 0xA1,
  179. 0xA2,
  180. 0xA3,
  181. 0xA4,
  182. 0xA5,
  183. 0xA6,
  184. 0xA7,
  185. 0xA8,
  186. 0xA9,
  187. 0xAA,
  188. 0xAB,
  189. 0xAC,
  190. 0xAD,
  191. 0xAE,
  192. 0xAF,
  193. 0xB0,
  194. 0xB1,
  195. 0xB2,
  196. 0xB3,
  197. 0xB4,
  198. 0xB5,
  199. 0xB6,
  200. 0xB7,
  201. 0xB8,
  202. 0xB9,
  203. 0xBA,
  204. 0xBB,
  205. 0xBC,
  206. 0xBD,
  207. 0xBE,
  208. 0xBF,
  209. 0xC0,
  210. 0xC1,
  211. 0xC2,
  212. 0xC3,
  213. 0xC4,
  214. 0xC5,
  215. 0xC6,
  216. 0xC7,
  217. 0xC8,
  218. 0xC9,
  219. 0xCA,
  220. 0xCB,
  221. 0xCC,
  222. 0xCD,
  223. 0xCE,
  224. 0xCF,
  225. 0xD0,
  226. 0xD1,
  227. 0xD2,
  228. 0xD3,
  229. 0xD4,
  230. 0xD5,
  231. 0xD6,
  232. 0xD7,
  233. 0xD8,
  234. 0xD9,
  235. 0xDA,
  236. 0xDB,
  237. 0xDC,
  238. 0xDD,
  239. 0xDE,
  240. 0xDF,
  241. 0xE0,
  242. 0xE1,
  243. 0xE2,
  244. 0xE3,
  245. 0xE4,
  246. 0xE5,
  247. 0xE6,
  248. 0xE7,
  249. 0xE8,
  250. 0xE9,
  251. 0xEA,
  252. 0xEB,
  253. 0xEC,
  254. 0xED,
  255. 0xEE,
  256. 0xEF,
  257. 0xF0,
  258. 0xF1,
  259. 0xF2,
  260. 0xF3,
  261. 0xF4,
  262. 0xF5,
  263. 0xF6,
  264. 0xF7,
  265. 0xF8,
  266. 0xF9,
  267. 0xFA,
  268. 0xFB,
  269. 0xFC,
  270. 0xFD,
  271. 0xFE,
  272. 0xFF,
  273. };
  274. #define TOLOWER(x) internal_tolower_table_[x]
  275. int mystrcmp(const char *s1, const char *s2, int l)
  276. {
  277. const unsigned char *p1 = (const unsigned char *)s1;
  278. const unsigned char *p2 = (const unsigned char *)s2;
  279. int result = 0;
  280. if (p1 == p2)
  281. return 0;
  282. while (l > 0 && (result = TOLOWER(*p1) - TOLOWER(*p2++)) == 0)
  283. if (*p1++ == '\0')
  284. break;
  285. else
  286. l--;
  287. return result;
  288. }