ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

405 lines
7.4 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
  4. //
  5. // See accompanying file COPYING.TXT file for licensing details.
  6. //
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #ifndef CPPCMS_ENCODING_VALIDATORS_H
  9. #define CPPCMS_ENCODING_VALIDATORS_H
  10. #include "utf_iterator.h"
  11. namespace cppcms { namespace encoding {
  12. template<typename Iterator>
  13. bool utf8_valid(Iterator p,Iterator e,size_t &count)
  14. {
  15. return utf8::validate(p,e,count,true);
  16. }
  17. template<typename Iterator>
  18. bool ascii_valid(Iterator p,Iterator e,size_t &count)
  19. {
  20. while(p!=e) {
  21. count++;
  22. unsigned c=(unsigned char)*p++;
  23. if(c==0x09 || c==0xA || c==0xD)
  24. continue;
  25. if(c<0x20 || 0x7E < c)
  26. return false;
  27. }
  28. return true;
  29. }
  30. template<typename Iterator>
  31. bool iso_8859_1_2_4_5_9_10_13_14_15_16_valid(Iterator p,Iterator e,size_t &count)
  32. {
  33. while(p!=e) {
  34. count++;
  35. unsigned c=(unsigned char)*p++;
  36. if(c==0x09 || c==0xA || c==0xD)
  37. continue;
  38. if(c<0x20 || (0x7F<=c && c<0xA0))
  39. return false;
  40. }
  41. return true;
  42. }
  43. template<typename Iterator>
  44. bool iso_8859_3_valid(Iterator p,Iterator e,size_t &count)
  45. {
  46. while(p!=e) {
  47. count++;
  48. unsigned c=(unsigned char)*p++;
  49. if(c==0x09 || c==0xA || c==0xD)
  50. continue;
  51. if(c<0x20 || (0x7F<=c && c<0xA0))
  52. return false;
  53. switch(c) {
  54. case 0xA5:
  55. case 0xAE:
  56. case 0xBE:
  57. case 0xC3:
  58. case 0xD0:
  59. case 0xE3:
  60. case 0xF0:
  61. return false;
  62. }
  63. }
  64. return true;
  65. }
  66. template<typename Iterator>
  67. bool iso_8859_6_valid(Iterator p,Iterator e,size_t &count)
  68. {
  69. while(p!=e) {
  70. count++;
  71. unsigned c=(unsigned char)*p++;
  72. if(c==0x09 || c==0xA || c==0xD)
  73. continue;
  74. if(c<0x20 || (0x7F<=c && c<0xA0))
  75. return false;
  76. if( (0xA1<=c && c<=0xA3) ||
  77. (0xA5 <=c && c<= 0xAB) ||
  78. (0xAE <=c && c<= 0xBA) ||
  79. (0xBC <=c && c<= 0xBE) ||
  80. 0xC0 == c ||
  81. (0xDB <=c && c<= 0xDF) ||
  82. (0xF3 <=c && c<= 0xFF))
  83. {
  84. return false;
  85. }
  86. }
  87. return true;
  88. }
  89. template<typename Iterator>
  90. bool iso_8859_7_valid(Iterator p,Iterator e,size_t &count)
  91. {
  92. while(p!=e) {
  93. count++;
  94. unsigned c=(unsigned char)*p++;
  95. if(c==0x09 || c==0xA || c==0xD)
  96. continue;
  97. if(c<0x20 || (0x7F<=c && c<0xA0))
  98. return false;
  99. switch(c) {
  100. case 0xAE:
  101. case 0xD2:
  102. case 0xFF:
  103. return false;
  104. }
  105. }
  106. return true;
  107. }
  108. template<typename Iterator>
  109. bool iso_8859_8_valid(Iterator p,Iterator e,size_t &count)
  110. {
  111. while(p!=e) {
  112. count++;
  113. unsigned c=(unsigned char)*p++;
  114. if(c==0x09 || c==0xA || c==0xD)
  115. continue;
  116. if(c<0x20 || (0x7F<=c && c<0xA0))
  117. return false;
  118. switch(c) {
  119. case 0xA1:
  120. case 0xFB:
  121. case 0xFC:
  122. case 0xFF:
  123. return false;
  124. }
  125. if(0xBF <=c && c<=0xDE)
  126. return false;
  127. }
  128. return true;
  129. }
  130. template<typename Iterator>
  131. bool iso_8859_11_valid(Iterator p,Iterator e,size_t &count)
  132. {
  133. while(p!=e) {
  134. count++;
  135. unsigned c=(unsigned char)*p++;
  136. if(c==0x09 || c==0xA || c==0xD)
  137. continue;
  138. if(c<0x20 || (0x7F<=c && c<0xA0))
  139. return false;
  140. switch(c) {
  141. case 0xDB:
  142. case 0xDC:
  143. case 0xDD:
  144. case 0xDE:
  145. case 0xFC:
  146. case 0xFD:
  147. case 0xFE:
  148. case 0xFF:
  149. return false;
  150. }
  151. }
  152. return true;
  153. }
  154. template<typename Iterator>
  155. bool windows_1250_valid(Iterator p,Iterator e,size_t &count)
  156. {
  157. while(p!=e) {
  158. count++;
  159. unsigned c=(unsigned char)*p++;
  160. if(c==0x09 || c==0xA || c==0xD)
  161. continue;
  162. if(c<0x20 || 0x7F==c)
  163. return false;
  164. switch(c) {
  165. case 0x81:
  166. case 0x83:
  167. case 0x88:
  168. case 0x90:
  169. case 0x98:
  170. return false;
  171. }
  172. }
  173. return true;
  174. }
  175. template<typename Iterator>
  176. bool windows_1251_valid(Iterator p,Iterator e,size_t &count)
  177. {
  178. while(p!=e) {
  179. count++;
  180. unsigned c=(unsigned char)*p++;
  181. if(c==0x09 || c==0xA || c==0xD)
  182. continue;
  183. if(c<0x20 || 0x7F==c || c==152)
  184. return false;
  185. }
  186. return true;
  187. }
  188. template<typename Iterator>
  189. bool windows_1252_valid(Iterator p,Iterator e,size_t &count)
  190. {
  191. while(p!=e) {
  192. count++;
  193. unsigned c=(unsigned char)*p++;
  194. if(c==0x09 || c==0xA || c==0xD)
  195. continue;
  196. if(c<0x20 || 0x7F==c)
  197. return false;
  198. switch(c) {
  199. case 0x81:
  200. case 0x8D:
  201. case 0x8F:
  202. case 0x90:
  203. case 0x9D:
  204. return false;
  205. }
  206. }
  207. return true;
  208. }
  209. template<typename Iterator>
  210. bool windows_1253_valid(Iterator p,Iterator e,size_t &count)
  211. {
  212. while(p!=e) {
  213. count++;
  214. unsigned c=(unsigned char)*p++;
  215. if(c==0x09 || c==0xA || c==0xD)
  216. continue;
  217. if(c<0x20 || 0x7F==c)
  218. return false;
  219. switch(c) {
  220. case 0x81:
  221. case 0x88:
  222. case 0x8A:
  223. case 0x8C:
  224. case 0x8D:
  225. case 0x8E:
  226. case 0x8F:
  227. case 0x90:
  228. case 0x98:
  229. case 0x9A:
  230. case 0x9C:
  231. case 0x9D:
  232. case 0x9E:
  233. case 0x9F:
  234. case 0xAA:
  235. case 0xD2:
  236. case 0xFF:
  237. return false;
  238. }
  239. }
  240. return true;
  241. }
  242. template<typename Iterator>
  243. bool windows_1254_valid(Iterator p,Iterator e,size_t &count)
  244. {
  245. while(p!=e) {
  246. count++;
  247. unsigned c=(unsigned char)*p++;
  248. if(c==0x09 || c==0xA || c==0xD)
  249. continue;
  250. if(c<0x20 || 0x7F==c)
  251. return false;
  252. switch(c) {
  253. case 0x81:
  254. case 0x8D:
  255. case 0x8E:
  256. case 0x8F:
  257. case 0x90:
  258. case 0x9D:
  259. case 0x9E:
  260. return false;
  261. }
  262. }
  263. return true;
  264. }
  265. template<typename Iterator>
  266. bool windows_1255_valid(Iterator p,Iterator e,size_t &count)
  267. {
  268. while(p!=e) {
  269. count++;
  270. unsigned c=(unsigned char)*p++;
  271. if(c==0x09 || c==0xA || c==0xD)
  272. continue;
  273. if(c<0x20 || 0x7F==c)
  274. return false;
  275. switch(c) {
  276. case 0x81:
  277. case 0x8A:
  278. case 0x8C:
  279. case 0x8D:
  280. case 0x8E:
  281. case 0x8F:
  282. case 0x90:
  283. case 0x9A:
  284. case 0x9C:
  285. case 0x9D:
  286. case 0x9E:
  287. case 0x9F:
  288. case 0xD9:
  289. case 0xDA:
  290. case 0xDB:
  291. case 0xDC:
  292. case 0xDD:
  293. case 0xDE:
  294. case 0xDF:
  295. case 0xCA:
  296. case 0xFB:
  297. case 0xFC:
  298. case 0xFF:
  299. return false;
  300. }
  301. }
  302. return true;
  303. }
  304. template<typename Iterator>
  305. bool windows_1256_valid(Iterator p,Iterator e,size_t &count)
  306. {
  307. while(p!=e) {
  308. count++;
  309. unsigned c=(unsigned char)*p++;
  310. if(c==0x09 || c==0xA || c==0xD)
  311. continue;
  312. if(c<0x20 || 0x7F==c)
  313. return false;
  314. }
  315. return true;
  316. }
  317. template<typename Iterator>
  318. bool windows_1257_valid(Iterator p,Iterator e,size_t &count)
  319. {
  320. while(p!=e) {
  321. count++;
  322. unsigned c=(unsigned char)*p++;
  323. if(c==0x09 || c==0xA || c==0xD)
  324. continue;
  325. if(c<0x20 || 0x7F==c)
  326. return false;
  327. switch(c) {
  328. case 0x81:
  329. case 0x83:
  330. case 0x88:
  331. case 0x8A:
  332. case 0x8C:
  333. case 0x90:
  334. case 0x98:
  335. case 0x9A:
  336. case 0x9C:
  337. case 0x9F:
  338. case 0xA1:
  339. case 0xA5:
  340. return false;
  341. }
  342. }
  343. return true;
  344. }
  345. template<typename Iterator>
  346. bool windows_1258_valid(Iterator p,Iterator e,size_t &count)
  347. {
  348. while(p!=e) {
  349. count++;
  350. unsigned c=(unsigned char)*p++;
  351. if(c==0x09 || c==0xA || c==0xD)
  352. continue;
  353. if(c<0x20 || c==0x7F)
  354. return false;
  355. switch(c) {
  356. case 0x81:
  357. case 0x8A:
  358. case 0x8D:
  359. case 0x8E:
  360. case 0x8F:
  361. case 0x90:
  362. case 0x9A:
  363. case 0x9D:
  364. case 0x9E:
  365. return false;
  366. }
  367. }
  368. return true;
  369. }
  370. template<typename Iterator>
  371. bool koi8_valid(Iterator p,Iterator e,size_t &count)
  372. {
  373. while(p!=e) {
  374. count++;
  375. unsigned c=(unsigned char)*p++;
  376. if(c==0x09 || c==0xA || c==0xD)
  377. continue;
  378. if(c<0x20 || 0x7F==c)
  379. return false;
  380. }
  381. return true;
  382. }
  383. // ISO
  384. } /* validator */ } // cppcms
  385. #endif