… | |
… | |
99 | *stash_cf_arch_wrap, |
99 | *stash_cf_arch_wrap, |
100 | *stash_cf_party_wrap, |
100 | *stash_cf_party_wrap, |
101 | *stash_cf_region_wrap, |
101 | *stash_cf_region_wrap, |
102 | *stash_cf_living_wrap; |
102 | *stash_cf_living_wrap; |
103 | |
103 | |
|
|
104 | static inline SV * |
|
|
105 | newSVpv_utf8 (const char *s) |
|
|
106 | { |
|
|
107 | SV *sv = newSVpv (s, 0); |
|
|
108 | SvUTF8_on (sv); |
|
|
109 | return sv; |
|
|
110 | } |
|
|
111 | |
|
|
112 | static inline SV * |
|
|
113 | newSVpvn_utf8 (const char *s, STRLEN l) |
|
|
114 | { |
|
|
115 | SV *sv = newSVpvn (s, l); |
|
|
116 | SvUTF8_on (sv); |
|
|
117 | return sv; |
|
|
118 | } |
|
|
119 | |
104 | // helper cast function, returns super class * or 0 |
120 | // helper cast function, returns super class * or 0 |
105 | template<class super> |
121 | template<class super> |
106 | static super * |
122 | static super * |
107 | is_a (attachable *at) |
123 | is_a (attachable *at) |
108 | { |
124 | { |
… | |
… | |
247 | } |
263 | } |
248 | } |
264 | } |
249 | } |
265 | } |
250 | |
266 | |
251 | void |
267 | void |
252 | attachable::set_key (const char *key, const char *value) |
268 | attachable::set_key (const char *key, const char *value, bool is_utf8) |
253 | { |
269 | { |
254 | if (!self) |
270 | if (!self) |
255 | self = newHV (); |
271 | self = newHV (); |
256 | |
272 | |
257 | if (value) |
273 | if (value) |
258 | hv_store (self, key, strlen (key), newSVpv (value, 0), 0); |
274 | hv_store (self, key, strlen (key), is_utf8 ? newSVpv_utf8 (value) : newSVpv (value, 0), 0); |
259 | else |
275 | else |
260 | hv_delete (self, key, strlen (key), G_DISCARD); |
276 | hv_delete (self, key, strlen (key), G_DISCARD); |
261 | } |
277 | } |
262 | |
278 | |
263 | attachable & |
279 | attachable & |
… | |
… | |
394 | { |
410 | { |
395 | if (SvOK (sv)) |
411 | if (SvOK (sv)) |
396 | return SvPTR (sv, klass); |
412 | return SvPTR (sv, klass); |
397 | else |
413 | else |
398 | return 0; |
414 | return 0; |
399 | } |
|
|
400 | |
|
|
401 | static inline SV * |
|
|
402 | newSVpv_utf8 (const char *s) |
|
|
403 | { |
|
|
404 | SV *sv = newSVpv (s, 0); |
|
|
405 | SvUTF8_on (sv); |
|
|
406 | return sv; |
|
|
407 | } |
|
|
408 | |
|
|
409 | static inline SV * |
|
|
410 | newSVpvn_utf8 (const char *s, STRLEN l) |
|
|
411 | { |
|
|
412 | SV *sv = newSVpvn (s, l); |
|
|
413 | SvUTF8_on (sv); |
|
|
414 | return sv; |
|
|
415 | } |
415 | } |
416 | |
416 | |
417 | inline SV *to_sv (const shstr & v) { return v ? newSVpvn_utf8 ((const char *)v, v.length ()) : &PL_sv_undef; } |
417 | inline SV *to_sv (const shstr & v) { return v ? newSVpvn_utf8 ((const char *)v, v.length ()) : &PL_sv_undef; } |
418 | inline SV *to_sv (const char * v) { return newSVpv (v, 0); } |
418 | inline SV *to_sv (const char * v) { return newSVpv (v, 0); } |
419 | inline SV *to_sv (bool v) { return newSViv (v); } |
419 | inline SV *to_sv (bool v) { return newSViv (v); } |