html-template-pro 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. data/.autotest +9 -0
  2. data/ARTISTIC +131 -0
  3. data/History.txt +4 -0
  4. data/LGPL +504 -0
  5. data/Manifest.txt +221 -0
  6. data/README.rdoc +52 -0
  7. data/Rakefile +18 -0
  8. data/benchmark.rb +136 -0
  9. data/config/website.yml +2 -0
  10. data/ext/html/template/internal/Pro.xs +679 -0
  11. data/ext/html/template/internal/builtin_findfile.inc +361 -0
  12. data/ext/html/template/internal/calc.h +26 -0
  13. data/ext/html/template/internal/calc.inc +120 -0
  14. data/ext/html/template/internal/callback_stubs.inc +63 -0
  15. data/ext/html/template/internal/expr.c +2267 -0
  16. data/ext/html/template/internal/expr.y +476 -0
  17. data/ext/html/template/internal/expr_iface.c +94 -0
  18. data/ext/html/template/internal/exprpstr.h +36 -0
  19. data/ext/html/template/internal/exprpstr.inc +144 -0
  20. data/ext/html/template/internal/exprtool.h +99 -0
  21. data/ext/html/template/internal/exprtool.inc +289 -0
  22. data/ext/html/template/internal/exprtype.h +62 -0
  23. data/ext/html/template/internal/exprval.h +30 -0
  24. data/ext/html/template/internal/extconf.rb +6 -0
  25. data/ext/html/template/internal/internal.c +449 -0
  26. data/ext/html/template/internal/loadfile.h +11 -0
  27. data/ext/html/template/internal/loadfile.inc +171 -0
  28. data/ext/html/template/internal/pabidecl.h +54 -0
  29. data/ext/html/template/internal/pabstract.h +426 -0
  30. data/ext/html/template/internal/parse_expr.h +15 -0
  31. data/ext/html/template/internal/pbuffer.c +76 -0
  32. data/ext/html/template/internal/pbuffer.h +31 -0
  33. data/ext/html/template/internal/pmiscdef.h +54 -0
  34. data/ext/html/template/internal/pparam.h +101 -0
  35. data/ext/html/template/internal/ppport.h +1098 -0
  36. data/ext/html/template/internal/procore.c +1189 -0
  37. data/ext/html/template/internal/procore.h +18 -0
  38. data/ext/html/template/internal/proparam.c +443 -0
  39. data/ext/html/template/internal/proparam.h +571 -0
  40. data/ext/html/template/internal/proscope.h +32 -0
  41. data/ext/html/template/internal/proscope.inc +107 -0
  42. data/ext/html/template/internal/prostate.h +49 -0
  43. data/ext/html/template/internal/prostate.inc +24 -0
  44. data/ext/html/template/internal/provalue.h +14 -0
  45. data/ext/html/template/internal/pstring.h +60 -0
  46. data/ext/html/template/internal/pstrutils.h +25 -0
  47. data/ext/html/template/internal/pstrutils.inc +150 -0
  48. data/ext/html/template/internal/tagstack.h +30 -0
  49. data/ext/html/template/internal/tagstack.inc +65 -0
  50. data/ext/html/template/internal/tmpllog.c +62 -0
  51. data/ext/html/template/internal/tmpllog.h +27 -0
  52. data/ext/html/template/internal/tmplpro.h +218 -0
  53. data/ext/html/template/internal/tmplpro_version.c +35 -0
  54. data/lib/html/template/pro.rb +225 -0
  55. data/script/console +10 -0
  56. data/script/destroy +14 -0
  57. data/script/generate +14 -0
  58. data/script/txt2html +71 -0
  59. data/tasks/extconf.rake +13 -0
  60. data/tasks/extconf/tmplpro.rake +43 -0
  61. data/templates-Pro/a.incl +1 -0
  62. data/templates-Pro/empty.incl +0 -0
  63. data/templates-Pro/include/1/a.incl +1 -0
  64. data/templates-Pro/include/2.out +3 -0
  65. data/templates-Pro/include/2.tmpl +1 -0
  66. data/templates-Pro/include/2/a.incl +1 -0
  67. data/templates-Pro/include/3.tmpl +1 -0
  68. data/templates-Pro/include/4.tmpl +1 -0
  69. data/templates-Pro/include/a.incl +1 -0
  70. data/templates-Pro/test_broken.tmpl +25 -0
  71. data/templates-Pro/test_broken1.out +1 -0
  72. data/templates-Pro/test_broken1.tmpl +1 -0
  73. data/templates-Pro/test_esc1.out +4 -0
  74. data/templates-Pro/test_esc1.tmpl +4 -0
  75. data/templates-Pro/test_esc2.out +5 -0
  76. data/templates-Pro/test_esc2.tmpl +6 -0
  77. data/templates-Pro/test_esc3.out +4 -0
  78. data/templates-Pro/test_esc3.tmpl +4 -0
  79. data/templates-Pro/test_esc4.out +3 -0
  80. data/templates-Pro/test_esc4.tmpl +4 -0
  81. data/templates-Pro/test_expr1.out +26 -0
  82. data/templates-Pro/test_expr1.tmpl +26 -0
  83. data/templates-Pro/test_expr2.out +34 -0
  84. data/templates-Pro/test_expr2.tmpl +34 -0
  85. data/templates-Pro/test_expr3.out +6 -0
  86. data/templates-Pro/test_expr3.tmpl +6 -0
  87. data/templates-Pro/test_expr4.out +4 -0
  88. data/templates-Pro/test_expr4.tmpl +4 -0
  89. data/templates-Pro/test_expr5.out +18 -0
  90. data/templates-Pro/test_expr5.tmpl +18 -0
  91. data/templates-Pro/test_expr6.out +18 -0
  92. data/templates-Pro/test_expr6.tmpl +18 -0
  93. data/templates-Pro/test_expr7.out +44 -0
  94. data/templates-Pro/test_expr7.tmpl +20 -0
  95. data/templates-Pro/test_expr8.out +15 -0
  96. data/templates-Pro/test_expr8.tmpl +15 -0
  97. data/templates-Pro/test_if1.out +25 -0
  98. data/templates-Pro/test_if1.tmpl +28 -0
  99. data/templates-Pro/test_if2.out +17 -0
  100. data/templates-Pro/test_if2.tmpl +25 -0
  101. data/templates-Pro/test_if3.out +12 -0
  102. data/templates-Pro/test_if3.tmpl +14 -0
  103. data/templates-Pro/test_if4.out +15 -0
  104. data/templates-Pro/test_if4.tmpl +31 -0
  105. data/templates-Pro/test_if5.out +16 -0
  106. data/templates-Pro/test_if5.tmpl +16 -0
  107. data/templates-Pro/test_if6.out +15 -0
  108. data/templates-Pro/test_if6.tmpl +31 -0
  109. data/templates-Pro/test_if7.out +14 -0
  110. data/templates-Pro/test_if7.tmpl +18 -0
  111. data/templates-Pro/test_include1.out +23 -0
  112. data/templates-Pro/test_include1.tmpl +7 -0
  113. data/templates-Pro/test_include2.out +120 -0
  114. data/templates-Pro/test_include2.tmpl +10 -0
  115. data/templates-Pro/test_include3.out +8 -0
  116. data/templates-Pro/test_include3.tmpl +8 -0
  117. data/templates-Pro/test_include4.out +7 -0
  118. data/templates-Pro/test_include4.tmpl +6 -0
  119. data/templates-Pro/test_include5.out +7 -0
  120. data/templates-Pro/test_include5.tmpl +6 -0
  121. data/templates-Pro/test_loop1.erb +17 -0
  122. data/templates-Pro/test_loop1.out +12 -0
  123. data/templates-Pro/test_loop1.tmpl +16 -0
  124. data/templates-Pro/test_loop2.erb +19 -0
  125. data/templates-Pro/test_loop2.out +40 -0
  126. data/templates-Pro/test_loop2.tmpl +19 -0
  127. data/templates-Pro/test_loop3.out +38 -0
  128. data/templates-Pro/test_loop3.tmpl +40 -0
  129. data/templates-Pro/test_loop4.out +44 -0
  130. data/templates-Pro/test_loop4.tmpl +20 -0
  131. data/templates-Pro/test_loop5.out +9 -0
  132. data/templates-Pro/test_loop5.tmpl +11 -0
  133. data/templates-Pro/test_loop6.out +33 -0
  134. data/templates-Pro/test_loop6.tmpl +15 -0
  135. data/templates-Pro/test_malloc.tmpl +1 -0
  136. data/templates-Pro/test_userfunc1.out +14 -0
  137. data/templates-Pro/test_userfunc1.tmpl +14 -0
  138. data/templates-Pro/test_userfunc2.out +35 -0
  139. data/templates-Pro/test_userfunc2.tmpl +5 -0
  140. data/templates-Pro/test_userfunc3.out +5 -0
  141. data/templates-Pro/test_userfunc3.tmpl +5 -0
  142. data/templates-Pro/test_userfunc4.out +10 -0
  143. data/templates-Pro/test_userfunc4.tmpl +10 -0
  144. data/templates-Pro/test_userfunc5.out +4 -0
  145. data/templates-Pro/test_userfunc5.tmpl +4 -0
  146. data/templates-Pro/test_userfunc6.out +4 -0
  147. data/templates-Pro/test_userfunc6.tmpl +4 -0
  148. data/templates-Pro/test_var1.erb +23 -0
  149. data/templates-Pro/test_var1.out +20 -0
  150. data/templates-Pro/test_var1.tmpl +23 -0
  151. data/templates-Pro/test_var2.erb +7 -0
  152. data/templates-Pro/test_var2.out +6 -0
  153. data/templates-Pro/test_var2.tmpl +7 -0
  154. data/templates-Pro/test_var3.out +14 -0
  155. data/templates-Pro/test_var3.tmpl +16 -0
  156. data/templates/case_loop.tmpl +3 -0
  157. data/templates/context.tmpl +3 -0
  158. data/templates/counter.tmpl +2 -0
  159. data/templates/default.tmpl +1 -0
  160. data/templates/default_escape.tmpl +4 -0
  161. data/templates/double_loop.tmpl +7 -0
  162. data/templates/escape.tmpl +5 -0
  163. data/templates/global-loops.tmpl +9 -0
  164. data/templates/globals.tmpl +11 -0
  165. data/templates/if.tmpl +7 -0
  166. data/templates/ifelse.tmpl +6 -0
  167. data/templates/include.tmpl +14 -0
  168. data/templates/include_path/a.tmpl +2 -0
  169. data/templates/include_path/b.tmpl +1 -0
  170. data/templates/include_path/inner.tmpl +1 -0
  171. data/templates/include_path/one.tmpl +2 -0
  172. data/templates/include_path2/inner.tmpl +1 -0
  173. data/templates/included.tmpl +4 -0
  174. data/templates/included2.tmpl +3 -0
  175. data/templates/js.tmpl +1 -0
  176. data/templates/long_loops.tmpl +307 -0
  177. data/templates/loop-context.tmpl +2 -0
  178. data/templates/loop-if.tmpl +9 -0
  179. data/templates/medium.tmpl +217 -0
  180. data/templates/multiline_tags.tmpl +7 -0
  181. data/templates/newline_test1.tmpl +1 -0
  182. data/templates/newline_test2.tmpl +1 -0
  183. data/templates/other-loop.tmpl +7 -0
  184. data/templates/outer.tmpl +3 -0
  185. data/templates/query-test.tmpl +21 -0
  186. data/templates/query-test2.tmpl +12 -0
  187. data/templates/recursive.tmpl +2 -0
  188. data/templates/searchpath/included.tmpl +4 -0
  189. data/templates/searchpath/three.tmpl +1 -0
  190. data/templates/searchpath/two.tmpl +2 -0
  191. data/templates/simple-loop-nonames.tmpl +13 -0
  192. data/templates/simple-loop.tmpl +12 -0
  193. data/templates/simple.tmpl +9 -0
  194. data/templates/unless.tmpl +5 -0
  195. data/templates/urlescape.tmpl +3 -0
  196. data/templates/vanguard1.tmpl +2 -0
  197. data/templates/vanguard2.tmpl +3 -0
  198. data/test/templates/complex.tmpl +24 -0
  199. data/test/templates/foo.tmpl +6 -0
  200. data/test/templates/func.tmpl +2 -0
  201. data/test/templates/loop.tmpl +14 -0
  202. data/test/templates/negative.tmpl +1 -0
  203. data/test/templates/numerics.tmpl +6 -0
  204. data/test/templates/register.tmpl +2 -0
  205. data/test/test_basic.rb +23 -0
  206. data/test/test_coderefs.rb +16 -0
  207. data/test/test_complex.rb +106 -0
  208. data/test/test_helper.rb +3 -0
  209. data/test/test_html_template.rb +583 -0
  210. data/test/test_html_template_internal_extn.rb +10 -0
  211. data/test/test_html_template_pro.rb +177 -0
  212. data/test/test_path_like_variable_scope.rb +59 -0
  213. data/test/test_random.rb +21 -0
  214. data/test/test_realloc.rb +16 -0
  215. data/test/test_register.rb +25 -0
  216. data/test/test_tmplpro.rb +9 -0
  217. data/test/tests.rb +9 -0
  218. data/website/index.txt +57 -0
  219. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  220. data/website/stylesheets/screen.css +159 -0
  221. data/website/template.html.erb +50 -0
  222. metadata +303 -0
@@ -0,0 +1,32 @@
1
+ /* -*- c -*-
2
+ * File: proscope.h
3
+ * Author: Igor Vlasenko <vlasenko@imath.kiev.ua>
4
+ * Created: Thu May 26 15:13:10 2005
5
+ *
6
+ * $Id$
7
+ */
8
+
9
+ #ifndef _PROSCOPE_H
10
+ #define _PROSCOPE_H 1
11
+
12
+ #include "pabstract.h"
13
+
14
+ struct scope_stack {
15
+ int level;
16
+ int max;
17
+ struct ProScopeEntry* root;
18
+ };
19
+
20
+ struct ProScopeEntry {
21
+ int flags; /* type of scope */
22
+ int loop; /* current loop */
23
+ int loop_count; /* total number of loops or negative value if unknown */
24
+ /* objects are wrapper-specific so pointer is void */
25
+ ABSTRACT_ARRAY* loops_AV; /* pointer to array of loop's dictionaries */
26
+ ABSTRACT_MAP* param_HV; /* pointer to dictionary of current loop */
27
+ };
28
+
29
+ #define isScopeLoop(X) ((X)->loops_AV!=NULL)
30
+ #define isScopeMap(X) ((X)->loops_AV==NULL)
31
+
32
+ #endif /* _PROSCOPE_H */
@@ -0,0 +1,107 @@
1
+ /* -*- c -*-
2
+ * File: proscope.c
3
+ * Author: Igor Vlasenko <vlasenko@imath.kiev.ua>
4
+ * Created: Thu May 26 15:25:57 2005
5
+ *
6
+ * $Id$
7
+ */
8
+
9
+ #include <stdlib.h>
10
+ #include "proscope.h"
11
+ #include "tmpllog.h"
12
+
13
+ #define START_NUMBER_OF_NESTED_LOOPS 64
14
+
15
+ static
16
+ void
17
+ Scope_init(struct scope_stack* scopestack) {
18
+ scopestack->max=START_NUMBER_OF_NESTED_LOOPS;
19
+ scopestack->root=(struct ProScopeEntry*) malloc ((scopestack->max) * sizeof(struct ProScopeEntry));
20
+ if (NULL==scopestack->root) tmpl_log(TMPL_LOG_ERROR, "DIE:_Scope_init:internal error:not enough memory\n");
21
+ scopestack->level=-1;
22
+ }
23
+
24
+ static
25
+ void
26
+ Scope_free(struct scope_stack* scopestack) {
27
+ free(scopestack->root);
28
+ scopestack->max=-1;
29
+ scopestack->level=-1;
30
+ }
31
+
32
+ static
33
+ int curScopeLevel(struct scope_stack* scopestack) {
34
+ return scopestack->level;
35
+ }
36
+
37
+ static
38
+ struct ProScopeEntry* getCurrentScope(struct scope_stack* scopestack) {
39
+ return scopestack->root+scopestack->level;
40
+ }
41
+
42
+ static
43
+ struct ProScopeEntry*
44
+ getScope(struct scope_stack* scopestack, int depth) {
45
+ return &(scopestack->root)[depth];
46
+ }
47
+
48
+ static
49
+ void
50
+ popScope(struct scope_stack* scopestack) {
51
+ if (scopestack->level>0) scopestack->level--;
52
+ else tmpl_log(TMPL_LOG_ERROR, "WARN:PopScope:internal error:scope is exhausted\n");
53
+ }
54
+
55
+ static
56
+ void
57
+ _pushScope(struct scope_stack* scopestack) {
58
+ if (scopestack->max<0) {
59
+ tmpl_log(TMPL_LOG_ERROR, "WARN:PushScope:internal warning:why scope is empty?\n");
60
+ Scope_init(scopestack);
61
+ }
62
+ ++scopestack->level;
63
+ if (scopestack->level>scopestack->max)
64
+ {
65
+ if (scopestack->max<START_NUMBER_OF_NESTED_LOOPS) scopestack->max=START_NUMBER_OF_NESTED_LOOPS;
66
+ scopestack->max*=2;
67
+ scopestack->root=(struct ProScopeEntry*) realloc (scopestack->root, (scopestack->max) * sizeof(struct ProScopeEntry));
68
+ }
69
+ }
70
+
71
+ static
72
+ void
73
+ pushScopeLoop(struct scope_stack* scopestack, int loop_count, void *loops_AV) {
74
+ struct ProScopeEntry* CurrentScope;
75
+ _pushScope(scopestack);
76
+ CurrentScope=scopestack->root+scopestack->level;
77
+ CurrentScope->loop=-1;
78
+ CurrentScope->loop_count = loop_count;
79
+ CurrentScope->flags=0;
80
+ CurrentScope->loops_AV=loops_AV;
81
+ CurrentScope->param_HV=NULL;
82
+ }
83
+
84
+ static
85
+ void
86
+ pushScopeMap(struct scope_stack* scopestack, void *param_HV, int flags) {
87
+ struct ProScopeEntry* CurrentScope;
88
+ _pushScope(scopestack);
89
+ CurrentScope=scopestack->root+scopestack->level;
90
+ CurrentScope->flags=flags;
91
+ CurrentScope->loops_AV=NULL;
92
+ CurrentScope->param_HV=param_HV;
93
+ }
94
+
95
+ static
96
+ void
97
+ Scope_reset(struct scope_stack* scopestack, int keep_count) {
98
+ int init_level=-1;
99
+ // TODO; find out scope level
100
+ if (scopestack->max<0) {
101
+ tmpl_log(TMPL_LOG_ERROR, "ERROR:Scope_reset:internal error:scope is empty.\n");
102
+ Scope_init(scopestack);
103
+ scopestack->level=init_level;
104
+ } else {
105
+ scopestack->level=keep_count+init_level;
106
+ }
107
+ }
@@ -0,0 +1,49 @@
1
+ #ifndef _PROSTATE_H
2
+ #define _PROSTATE_H 1
3
+
4
+ #include "pbuffer.h"
5
+
6
+ struct tagstack {
7
+ struct tagstack_entry* entry;
8
+ int pos;
9
+ int depth;
10
+ };
11
+
12
+ struct tmplpro_param;
13
+
14
+ typedef int boolval;
15
+
16
+ struct tmplpro_state {
17
+ boolval is_visible;
18
+ const char* top;
19
+ const char* next_to_end;
20
+ const char* last_processed_pos;
21
+ const char* cur_pos;
22
+ struct tmplpro_param* param;
23
+ /* current tag */
24
+ int tag;
25
+ boolval is_tag_closed;
26
+ boolval is_tag_commented;
27
+ boolval is_expr;
28
+ const char* tag_start;
29
+
30
+ /* internal buffers */
31
+ /* main string buffer */
32
+ pbuffer str_buffer;
33
+ /* tag stack */
34
+ struct tagstack tag_stack;
35
+
36
+ /* expr string buffers; used to unescape pstring args and for num -> string */
37
+ pbuffer expr_left_pbuffer;
38
+ pbuffer expr_right_pbuffer;
39
+ };
40
+
41
+ extern TMPLPRO_LOCAL void log_state(struct tmplpro_state*, int level, const char *fmt, ...) FORMAT_PRINTF(3,4);
42
+
43
+ #endif /* prostate.h */
44
+
45
+ /*
46
+ * Local Variables:
47
+ * mode: c
48
+ * End:
49
+ */
@@ -0,0 +1,24 @@
1
+ #include "prostate.h"
2
+ #include "tmpllog.h"
3
+
4
+ TMPLPRO_LOCAL void log_state(struct tmplpro_state* state, int level, const char *fmt, ...)
5
+ {
6
+ va_list vl;
7
+ va_start(vl, fmt);
8
+ if (state->tag ==HTML_TEMPLATE_NO_TAG) {
9
+ tmpl_log(level, "HTML::Template::Pro:");
10
+ } else {
11
+ tmpl_log(level, "HTML::Template::Pro:in %sTMPL_%s at pos " MOD_TD ": ",
12
+ (state->is_tag_closed ? "/" : ""),
13
+ (state->tag>HTML_TEMPLATE_BAD_TAG && state->tag <=HTML_TEMPLATE_LAST_TAG_USED) ? TAGNAME[state->tag] : "",
14
+ TO_PTRDIFF_T(state->tag_start - state->top));
15
+ }
16
+ tmpl_vlog(level, fmt, vl);
17
+ va_end(vl);
18
+ }
19
+
20
+ /*
21
+ * Local Variables:
22
+ * mode: c
23
+ * End:
24
+ */
@@ -0,0 +1,14 @@
1
+ #ifndef _PROVALUE_H
2
+ #define _PROVALUE_H 1
3
+
4
+ #include<pabidecl.h>
5
+
6
+ TMPLPRO_LOCAL PSTRING _get_variable_value (struct tmplpro_param *param, PSTRING name);
7
+
8
+ #endif /* provalue.h */
9
+
10
+ /*
11
+ * Local Variables:
12
+ * mode: c
13
+ * End:
14
+ */
@@ -0,0 +1,60 @@
1
+ /*! \file pstring.h
2
+ * \brief string type.
3
+ *
4
+ * \author Igor Vlasenko <vlasenko@imath.kiev.ua>
5
+ * \warning This header file should never be included directly.
6
+ * Include <tmplpro.h> instead.
7
+ */
8
+
9
+ #ifndef _PSTRING_H
10
+ #define _PSTRING_H 1
11
+
12
+ /** \struct PSTRING
13
+
14
+ \brief string type used in htmltmplpro.
15
+
16
+ \code
17
+ typedef struct PSTRING {
18
+ const char* begin;
19
+ const char* endnext;
20
+ } PSTRING;
21
+ \endcode
22
+
23
+
24
+ The string is delimited by two pointers, begin and endnext.
25
+ The length of the string is calculated as endnext - begin.
26
+ The empty string has begin == endnext.
27
+
28
+ \warning It is possible for empty string to have begin == endnext == NULL.
29
+ \warning Contents of the memory area, passed as PSTRING, should always be treated as const.
30
+ \warning Contents of the memory area, passed as PSTRING, can be destroyed after the callback function
31
+ completed. To be used afterwards the string content should be copied.
32
+ */
33
+
34
+ typedef struct PSTRING {
35
+ const char* begin; /*!< pointer to begin of the string. */
36
+ const char* endnext; /*!< pointer to the byte next to the last char of the string. */
37
+ } PSTRING;
38
+
39
+ /** \struct MPSTRING
40
+
41
+ \brief Modifiable PSTRING.
42
+
43
+ \code
44
+ typedef struct MPSTRING {
45
+ char* begin;
46
+ char* endnext;
47
+ } PSTRING;
48
+ \endcode
49
+
50
+ The same as PSTING, but in non-constant memory.
51
+
52
+ */
53
+
54
+
55
+ typedef struct MPSTRING {
56
+ char* begin; /*!< pointer to begin of the string. */
57
+ char* endnext; /*!< pointer to the byte next to the last char of the string. */
58
+ } MPSTRING;
59
+
60
+ #endif /* pstring.h */
@@ -0,0 +1,25 @@
1
+ /* -*- c -*-
2
+ * File: pstring.h
3
+ * Author: Igor Vlasenko <vlasenko@imath.kiev.ua>
4
+ * Created: Fri Jul 1 20:11:51 2005
5
+ *
6
+ * $Id$
7
+ */
8
+
9
+ #ifndef _PSTRUTILS_H
10
+ #define _PSTRUTILS_H 1
11
+
12
+ #include "pbuffer.h"
13
+
14
+ static
15
+ PSTRING lowercase_pstring (pbuffer*, PSTRING);
16
+ static
17
+ int is_pstring_true (PSTRING s);
18
+ static
19
+ PSTRING escape_pstring (pbuffer* StrBuffer, PSTRING pstring, int escapeopt);
20
+
21
+ /*
22
+ static
23
+ void lowercase_pstring_inplace (PSTRING pstring);
24
+ */
25
+ #endif /* pstrutils.h */
@@ -0,0 +1,150 @@
1
+ /* -*- c -*-
2
+ * File: pstring.h
3
+ * Author: Igor Vlasenko <vlasenko@imath.kiev.ua>
4
+ * Created: Fri Jul 1 20:11:51 2005
5
+ *
6
+ * $Id$
7
+ */
8
+
9
+ #include <stdio.h>
10
+ #include <string.h>
11
+ #include <ctype.h>
12
+ #include "pbuffer.h"
13
+ #include "pstring.h"
14
+
15
+ static
16
+ PSTRING
17
+ lowercase_pstring (pbuffer* pBuffer ,PSTRING pstring) {
18
+ size_t size=pstring.endnext-pstring.begin;
19
+ char* buf=pbuffer_resize(pBuffer, size+1);
20
+ char* inbuf=buf;
21
+ const char* i=pstring.begin;
22
+ PSTRING retval;
23
+ while (i<pstring.endnext) {
24
+ *inbuf++=tolower((unsigned char) *i++);
25
+ }
26
+ *inbuf=0;
27
+ retval.begin=buf;
28
+ retval.endnext=buf+size;
29
+ return retval;
30
+ }
31
+
32
+ /*
33
+ static
34
+ void
35
+ lowercase_pstring_inplace (PSTRING pstring) {
36
+ char* i=pstring.begin;
37
+ while (i<pstring.endnext) {
38
+ *i=tolower(*i);
39
+ i++;
40
+ }
41
+ }
42
+ */
43
+
44
+ static
45
+ PSTRING
46
+ uppercase_pstring (pbuffer* pBuffer ,PSTRING pstring) {
47
+ size_t size=pstring.endnext-pstring.begin;
48
+ char* buf=pbuffer_resize(pBuffer, size+1);
49
+ char* inbuf=buf;
50
+ const char* i=pstring.begin;
51
+ PSTRING retval;
52
+ while (i<pstring.endnext) {
53
+ *inbuf++=toupper((unsigned char) *i++);
54
+ }
55
+ *inbuf=0;
56
+ retval.begin=buf;
57
+ retval.endnext=buf+size;
58
+ return retval;
59
+ }
60
+
61
+
62
+ static
63
+ int
64
+ is_pstring_true (PSTRING s) {
65
+ if (s.begin == NULL || s.begin == s.endnext) return 0;
66
+ if (1==s.endnext-s.begin) {
67
+ if (*(s.begin)=='0') return 0; else return 1;
68
+ } else if (3==s.endnext-s.begin) {
69
+ if ('0'==*(s.begin) && '.'==*(s.begin+1) && '0'==*(s.begin+2)) return 0; else return 1;
70
+ } else return 1;
71
+ }
72
+
73
+ static
74
+ PSTRING
75
+ escape_pstring (pbuffer* StrBuffer, PSTRING pstring, int escapeopt) {
76
+ char* buf=pbuffer_resize(StrBuffer, 2*(pstring.endnext-pstring.begin+1));
77
+ const char* curpos=pstring.begin;
78
+ size_t offset=0;
79
+ size_t buflen=pbuffer_size(StrBuffer);
80
+ PSTRING retval;
81
+ switch (escapeopt) {
82
+ case HTML_TEMPLATE_OPT_ESCAPE_HTML:
83
+ while (curpos<pstring.endnext) {
84
+ unsigned char curchar=*curpos++;
85
+ int bufdelta=1;
86
+ if (offset>=buflen) {
87
+ buf=pbuffer_resize(StrBuffer, 2*offset);
88
+ buflen=pbuffer_size(StrBuffer);
89
+ }
90
+ switch (curchar) {
91
+ /* straight from the CGI.pm bible. (HTML::Template) */
92
+ case '&' : bufdelta=5; strncpy(buf+offset, "&amp;", bufdelta);break;
93
+ case '"' : bufdelta=6; strncpy(buf+offset, "&quot;",bufdelta);break;
94
+ case '>' : bufdelta=4; strncpy(buf+offset, "&gt;", bufdelta);break;
95
+ case '<' : bufdelta=4; strncpy(buf+offset, "&lt;", bufdelta);break;
96
+ case '\'': bufdelta=5; strncpy(buf+offset, "&#39;", bufdelta);break;
97
+ default: *(buf+offset)=curchar;
98
+ }
99
+ offset+=bufdelta;
100
+ }
101
+ break;
102
+ case HTML_TEMPLATE_OPT_ESCAPE_JS:
103
+ while (curpos<pstring.endnext) {
104
+ unsigned char curchar=*curpos++;
105
+ int bufdelta=1;
106
+ if (offset>=buflen) {
107
+ buf=pbuffer_resize(StrBuffer, 2*offset);
108
+ buflen=pbuffer_size(StrBuffer);
109
+ }
110
+ switch (curchar) {
111
+ case '\\' : bufdelta=2; strncpy(buf+offset, "\\\\", bufdelta);break;
112
+ case '"' : bufdelta=2; strncpy(buf+offset, "\\\"",bufdelta);break;
113
+ case '\'' : bufdelta=2; strncpy(buf+offset, "\\'",bufdelta);break;
114
+ case '\n' : bufdelta=2; strncpy(buf+offset, "\\n",bufdelta);break;
115
+ case '\r' : bufdelta=2; strncpy(buf+offset, "\\r",bufdelta);break;
116
+ default: *(buf+offset)=curchar;
117
+ }
118
+ offset+=bufdelta;
119
+ }
120
+ break;
121
+ case HTML_TEMPLATE_OPT_ESCAPE_URL:
122
+ while (curpos<pstring.endnext) {
123
+ unsigned char curchar=*curpos++;
124
+ int bufdelta=1;
125
+ if (offset>=buflen) {
126
+ buf=pbuffer_resize(StrBuffer, 2*offset);
127
+ buflen=pbuffer_size(StrBuffer);
128
+ }
129
+ /*
130
+ * # do the translation (RFC 2396 ^uric)
131
+ * s!([^a-zA-Z0-9_.\-])!sprintf('%%%02X', $_)
132
+ */
133
+ if ((curchar>='a' && curchar<='z') ||
134
+ (curchar>='A' && curchar<='Z') ||
135
+ (curchar>='0' && curchar<='9') ||
136
+ curchar=='_' || curchar=='.' || curchar=='\\' || curchar=='-'
137
+ )
138
+ *(buf+offset)=curchar;
139
+ else {
140
+ bufdelta=3; sprintf(buf+offset,"%%%.2X",(int) curchar);
141
+ }
142
+ offset+=bufdelta;
143
+ }
144
+ break;
145
+ default : return pstring;
146
+ }
147
+ retval.begin=buf;
148
+ retval.endnext=buf+offset;
149
+ return retval;
150
+ }