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.
 
 
 
 
 
 

416 lines
8.0 KiB

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