1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | |
28 | |
29 |
30 |
31 |
32 | FORM decode_html |
33 | CHANGING |
34 | c_txt TYPE any. |
35 | |
36 | DATA: |
37 | l_xstr TYPE xstring, |
38 | l_hex TYPE string, |
39 | l_xpos TYPE i, |
40 | l_str TYPE string, |
41 | l_fdpos TYPE i, |
42 | l_strlen TYPE i, |
43 | l_out TYPE string, |
44 | l_outlen TYPE i, |
45 | l_char TYPE string. |
46 | |
47 | CHECK NOT c_txt IS INITIAL. |
48 | CHECK c_txt CS '&#x'. |
49 | |
50 | l_str = c_txt. |
51 | |
52 | DO. |
53 | IF l_str CS '&#x'. |
54 | l_fdpos = sy-fdpos. |
55 | IF l_fdpos > 0. |
56 | CONCATENATE l_out+0(l_outlen) l_str+0(l_fdpos) INTO l_out. |
57 | l_outlen = l_outlen + l_fdpos. |
58 | ENDIF. |
59 | l_xpos = l_fdpos + 3. |
60 | l_strlen = strlen( l_str ). |
61 | l_strlen = l_strlen - l_xpos. |
62 | l_str = l_str+l_xpos(l_strlen). |
63 | SPLIT l_str AT ';' INTO l_hex l_str. |
64 | l_xstr = l_hex. |
65 | |
66 | CALL FUNCTION 'NLS_STRING_CONVERT_TO_SYS' |
67 | EXPORTING |
68 | lang_used = sy-langu |
69 | SOURCE = l_xstr |
70 | IMPORTING |
71 | RESULT = l_char |
72 | EXCEPTIONS |
73 | OTHERS = 1. |
74 | IF sy-subrc = 0. |
75 | CONCATENATE l_out+0(l_outlen) l_char+0(1) INTO l_out. |
76 | ELSE. |
77 | CONCATENATE l_out+0(l_outlen) '#' INTO l_out. |
78 | ENDIF. |
79 | l_outlen = l_outlen + 1. |
80 | ELSE. |
81 | EXIT. |
82 | ENDIF. |
83 | ENDDO. |
84 | |
85 | l_strlen = strlen( l_str ). |
86 | CONCATENATE l_out+0(l_outlen) l_str+0(l_strlen) INTO l_out. |
87 | c_txt = l_out. |
88 | ENDFORM. "decode_html |
89 | |
90 | |
91 |
92 |
93 |
94 | FORM decode_html_io |
95 | USING |
96 | i_html TYPE string |
97 | CHANGING |
98 | c_txt TYPE any. |
99 | |
100 | c_txt = i_html. |
101 | |
102 | PERFORM decode_html |
103 | CHANGING |
104 | c_txt. |
105 | |
106 | ENDFORM. "decode_html_io |
107 | |
108 | |
109 |
110 |
111 |
112 | FORM encode_html |
113 | CHANGING |
114 | c_txt TYPE string. |
115 | |
116 | CHECK NOT c_txt IS INITIAL. |
117 | CHECK c_txt NS '&#'. |
118 | |
119 | PERFORM encode_html_force |
120 | CHANGING c_txt. |
121 | |
122 | ENDFORM. "encode_html |
123 | |
124 | |
125 |
126 |
127 |
128 | FORM encode_html_force |
129 | CHANGING |
130 | c_txt TYPE string. |
131 | |
132 | DATA: |
133 | l_xstr TYPE xstring, |
134 | l_hex TYPE string, |
135 | l_hexlen TYPE i, |
136 | l_xlen TYPE i, |
137 | l_xpos TYPE i, |
138 | l_str TYPE string, |
139 | l_strlen TYPE i, |
140 | l_out TYPE string, |
141 | l_outlen TYPE i, |
142 | l_pos TYPE i, |
143 | l_chars(255) TYPE c, |
144 | l_xchar(4) TYPE c. |
145 | |
146 | |
147 | CHECK NOT c_txt IS INITIAL. |
148 | |
149 | CONCATENATE "characters not to encode |
150 | ' :;,./()-_+*#=' |
151 | '0123456789' |
152 | 'abcdefghijklmnopqrstuvwxyz' |
153 | 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
154 | INTO l_chars. |
155 | |
156 | l_str = c_txt. |
157 | |
158 | |
159 | CALL FUNCTION 'NLS_STRING_CONVERT_FROM_SYS' |
160 | EXPORTING |
161 | lang_used = sy-langu |
162 | SOURCE = l_str |
163 | IMPORTING |
164 | RESULT = l_xstr. |
165 | |
166 | l_hex = l_xstr. |
167 | l_hexlen = strlen( l_hex ). |
168 | l_strlen = strlen( l_str ). |
169 | l_xlen = l_hexlen / l_strlen. |
170 | |
171 | DO. |
172 | l_xpos = l_pos * l_xlen. |
173 | l_xchar = l_hex+l_xpos(l_xlen). |
174 | IF l_chars NA l_str+l_pos(1) |
175 | AND NOT l_xchar = '23'. |
176 | IF l_outlen = 0. |
177 | CONCATENATE '&#x' l_xchar ';' INTO l_out. |
178 | ELSE. |
179 | CONCATENATE l_out+0(l_outlen) '&#x' l_xchar ';' |
180 | INTO l_out. |
181 | ENDIF. |
182 | l_outlen = l_outlen + 4 + l_xlen. |
183 | ELSE. |
184 | IF l_outlen = 0. |
185 | l_out = l_str+l_pos(1). |
186 | ELSE. |
187 | CONCATENATE l_out+0(l_outlen) l_str+l_pos(1) INTO l_out. |
188 | ENDIF. |
189 | l_outlen = l_outlen + 1. |
190 | ENDIF. |
191 | |
192 | l_pos = l_pos + 1. |
193 | l_strlen = strlen( l_str ). |
194 | IF l_pos = l_strlen. |
195 | EXIT. |
196 | ENDIF. |
197 | ENDDO. |
198 | |
199 | c_txt = l_out. |
200 | ENDFORM. "encode_html_force |
201 | |
202 | |
203 |
204 |
205 |
206 | FORM encode_uri |
207 | CHANGING |
208 | c_url TYPE string. |
209 | |
210 | DATA: |
211 | l_prot TYPE string, |
212 | l_url TYPE string, |
213 | l_params TYPE string, |
214 | lt_param TYPE it_string, |
215 | l_key TYPE string, |
216 | l_value TYPE string, |
217 | l_len TYPE i. |
218 | |
219 | FIELD-SYMBOLS: |
220 | <l_param> TYPE string. |
221 | |
222 | CHECK NOT c_url IS INITIAL. |
223 | |
224 | IF c_url CA '?' OR c_url NA '='. |
225 | SPLIT c_url AT '?' INTO l_url l_params. |
226 | IF l_url CA ':'. |
227 | SPLIT l_url AT ':' INTO l_prot l_url. |
228 | ENDIF. |
229 | PERFORM encode_uri_link CHANGING l_url. |
230 | IF NOT l_prot IS INITIAL. |
231 | CONCATENATE l_prot ':' l_url INTO l_url. |
232 | ENDIF. |
233 | CONCATENATE l_url '?' INTO l_url. |
234 | ELSEIF c_url CA '='. |
235 | l_params = c_url. |
236 | ENDIF. |
237 | |
238 | SPLIT l_params AT '&' INTO TABLE lt_param. |
239 | LOOP AT lt_param ASSIGNING <l_param>. |
240 | CLEAR: l_key, l_value. |
241 | SPLIT <l_param> AT '=' INTO l_key l_value. |
242 | PERFORM encode_uri_value CHANGING l_value. |
243 | CONCATENATE l_url l_key '=' l_value '&' INTO l_url. |
244 | ENDLOOP. |
245 | |
246 | l_len = strlen( l_url ). |
247 | l_len = l_len - 1. "remove last '&' |
248 | c_url = l_url+0(l_len). |
249 | ENDFORM. "encode_uri |
250 | |
251 | |
252 |
253 |
254 |
255 | FORM encode_uri_link |
256 | CHANGING |
257 | c_value TYPE string. |
258 | |
259 | DATA: |
260 | l_chars(66) TYPE c. |
261 | |
262 | CHECK NOT c_value IS INITIAL. |
263 | |
264 | CONCATENATE "characters not to encode |
265 | '/_-.' |
266 | '0123456789' |
267 | 'abcdefghijklmnopqrstuvwxyz' |
268 | 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
269 | INTO l_chars. |
270 | |
271 | PERFORM encode_uri_string |
272 | USING l_chars |
273 | CHANGING c_value. |
274 | |
275 | ENDFORM. "encode_uri_link |
276 | |
277 | |
278 |
279 |
280 |
281 | FORM encode_uri_string |
282 | USING |
283 | value(i_chars) |
284 | CHANGING |
285 | c_value TYPE string. |
286 | |
287 | DATA: |
288 | l_xstr TYPE xstring, |
289 | l_hex TYPE string, |
290 | l_hexlen TYPE i, |
291 | l_chex TYPE string, |
292 | l_chex_pos TYPE i, |
293 | l_xlen TYPE i, |
294 | l_xpos TYPE i, |
295 | l_str TYPE string, |
296 | l_strlen TYPE i, |
297 | l_out TYPE string, |
298 | l_outlen TYPE i, |
299 | l_pos TYPE i. |
300 | |
301 | CHECK NOT c_value IS INITIAL. |
302 | |
303 | l_str = c_value. |
304 | |
305 | |
306 | CALL FUNCTION 'NLS_STRING_CONVERT_FROM_SYS' |
307 | EXPORTING |
308 | lang_used = sy-langu |
309 | SOURCE = l_str |
310 | IMPORTING |
311 | RESULT = l_xstr. |
312 | |
313 | l_hex = l_xstr. |
314 | l_hexlen = strlen( l_hex ). |
315 | l_strlen = strlen( l_str ). |
316 | l_xlen = l_hexlen / l_strlen. |
317 | |
318 | DO. |
319 | IF i_chars NA l_str+l_pos(1). |
320 | l_xpos = l_pos * l_xlen. |
321 | l_chex = l_hex+l_xpos(l_xlen). |
322 | l_chex_pos = strlen( l_chex ). |
323 | l_chex_pos = l_chex_pos - 2. |
324 | l_chex = l_chex+l_chex_pos(2). |
325 | IF l_outlen = 0. |
326 | CONCATENATE '%' l_chex INTO l_out. |
327 | ELSE. |
328 | CONCATENATE l_out+0(l_outlen) '%' l_chex |
329 | INTO l_out. |
330 | ENDIF. |
331 | l_outlen = l_outlen + 3. |
332 | ELSE. |
333 | IF l_outlen = 0. |
334 | l_out = l_str+l_pos(1). |
335 | ELSE. |
336 | CONCATENATE l_out+0(l_outlen) l_str+l_pos(1) INTO l_out. |
337 | ENDIF. |
338 | l_outlen = l_outlen + 1. |
339 | ENDIF. |
340 | |
341 | l_pos = l_pos + 1. |
342 | l_strlen = strlen( l_str ). |
343 | IF l_pos = l_strlen. |
344 | EXIT. |
345 | ENDIF. |
346 | ENDDO. |
347 | |
348 | c_value = l_out. |
349 | ENDFORM. "encode_uri_string |
350 | |
351 | |
352 |
353 |
354 |
355 | FORM encode_uri_value |
356 | CHANGING |
357 | c_value TYPE string. |
358 | |
359 | DATA: |
360 | l_chars(62) TYPE c. |
361 | |
362 | CHECK NOT c_value IS INITIAL. |
363 | |
364 | CONCATENATE "characters not to encode |
365 | '0123456789' |
366 | 'abcdefghijklmnopqrstuvwxyz' |
367 | 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
368 | INTO l_chars. |
369 | |
370 | PERFORM encode_uri_string |
371 | USING l_chars |
372 | CHANGING c_value. |
373 | |
374 | ENDFORM. "encode_uri_value |