line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
/*-*- Mode: C -*- */ |
2
|
|
|
|
|
|
|
#include "EXTERN.h" |
3
|
|
|
|
|
|
|
#include "perl.h" |
4
|
|
|
|
|
|
|
#include "XSUB.h" |
5
|
|
|
|
|
|
|
/*#include "ppport.h"*/ |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#include |
8
|
|
|
|
|
|
|
#include |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
/*============================================================================== |
11
|
|
|
|
|
|
|
* Utils |
12
|
|
|
|
|
|
|
*/ |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
|
void ux_sv2buf_bytes(SV *sv, uxBuffer *buf) |
15
|
|
|
|
|
|
|
{ |
16
|
|
|
|
|
|
|
STRLEN len; |
17
|
0
|
0
|
|
|
|
|
buf->str = SvPV(sv, len); |
18
|
0
|
|
|
|
|
|
buf->len = len; |
19
|
0
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
/*============================================================================== |
22
|
|
|
|
|
|
|
* XS Guts |
23
|
|
|
|
|
|
|
*/ |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
MODULE = Unicruft PACKAGE = Unicruft |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
PROTOTYPES: ENABLE |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
##===================================================================== |
30
|
|
|
|
|
|
|
## Information |
31
|
|
|
|
|
|
|
##===================================================================== |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
const char * |
34
|
|
|
|
|
|
|
library_version() |
35
|
|
|
|
|
|
|
CODE: |
36
|
0
|
|
|
|
|
|
RETVAL = PACKAGE_VERSION; |
37
|
|
|
|
|
|
|
OUTPUT: |
38
|
|
|
|
|
|
|
RETVAL |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
##===================================================================== |
41
|
|
|
|
|
|
|
## Conversions |
42
|
|
|
|
|
|
|
##===================================================================== |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
##-------------------------------------------------------------- |
45
|
|
|
|
|
|
|
SV * |
46
|
|
|
|
|
|
|
ux_latin1_to_utf8(SV *l1bytes) |
47
|
|
|
|
|
|
|
PREINIT: |
48
|
0
|
|
|
|
|
|
uxBuffer ibuf = {NULL,0,0}; |
49
|
0
|
|
|
|
|
|
uxBuffer obuf = {NULL,0,0}; |
50
|
|
|
|
|
|
|
CODE: |
51
|
0
|
|
|
|
|
|
ux_sv2buf_bytes(l1bytes, &ibuf); |
52
|
0
|
|
|
|
|
|
ux_buffer_latin1_to_utf8(&ibuf, &obuf); |
53
|
0
|
|
|
|
|
|
RETVAL = newSVpvn(obuf.str, obuf.len); |
54
|
0
|
|
|
|
|
|
SvUTF8_on(RETVAL); |
55
|
|
|
|
|
|
|
OUTPUT: |
56
|
|
|
|
|
|
|
RETVAL |
57
|
|
|
|
|
|
|
CLEANUP: |
58
|
0
|
0
|
|
|
|
|
if (obuf.str) free(obuf.str); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
##-------------------------------------------------------------- |
61
|
|
|
|
|
|
|
SV * |
62
|
|
|
|
|
|
|
ux_utf8_to_ascii(SV *u8bytes) |
63
|
|
|
|
|
|
|
PREINIT: |
64
|
0
|
|
|
|
|
|
uxBuffer ibuf = {NULL,0,0}; |
65
|
0
|
|
|
|
|
|
uxBuffer obuf = {NULL,0,0}; |
66
|
|
|
|
|
|
|
CODE: |
67
|
0
|
|
|
|
|
|
ux_sv2buf_bytes(u8bytes, &ibuf); |
68
|
0
|
|
|
|
|
|
ux_unidecode_us(NULL, &ibuf, &obuf); |
69
|
0
|
|
|
|
|
|
RETVAL = newSVpvn(obuf.str, obuf.len); |
70
|
0
|
|
|
|
|
|
SvUTF8_off(RETVAL); |
71
|
|
|
|
|
|
|
OUTPUT: |
72
|
|
|
|
|
|
|
RETVAL |
73
|
|
|
|
|
|
|
CLEANUP: |
74
|
0
|
0
|
|
|
|
|
if (obuf.str) free(obuf.str); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
##-------------------------------------------------------------- |
77
|
|
|
|
|
|
|
SV * |
78
|
|
|
|
|
|
|
ux_utf8_to_latin1(SV *u8bytes) |
79
|
|
|
|
|
|
|
PREINIT: |
80
|
0
|
|
|
|
|
|
uxBuffer ibuf = {NULL,0,0}; |
81
|
0
|
|
|
|
|
|
uxBuffer obuf = {NULL,0,0}; |
82
|
|
|
|
|
|
|
CODE: |
83
|
0
|
|
|
|
|
|
ux_sv2buf_bytes(u8bytes, &ibuf); |
84
|
0
|
|
|
|
|
|
ux_unidecode_us(&UNIDECODE_LATIN1, &ibuf, &obuf); |
85
|
0
|
|
|
|
|
|
RETVAL = newSVpvn(obuf.str, obuf.len); |
86
|
0
|
|
|
|
|
|
SvUTF8_off(RETVAL); |
87
|
|
|
|
|
|
|
OUTPUT: |
88
|
|
|
|
|
|
|
RETVAL |
89
|
|
|
|
|
|
|
CLEANUP: |
90
|
0
|
0
|
|
|
|
|
if (obuf.str) free(obuf.str); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
##-------------------------------------------------------------- |
93
|
|
|
|
|
|
|
SV * |
94
|
|
|
|
|
|
|
ux_utf8_to_latin1_de(SV *u8bytes) |
95
|
|
|
|
|
|
|
PREINIT: |
96
|
0
|
|
|
|
|
|
uxBuffer ibuf = {NULL,0,0}; |
97
|
0
|
|
|
|
|
|
uxBuffer pbuf = {NULL,0,0}; |
98
|
0
|
|
|
|
|
|
uxBuffer obuf = {NULL,0,0}; |
99
|
|
|
|
|
|
|
uxDEpp depp; |
100
|
|
|
|
|
|
|
CODE: |
101
|
0
|
|
|
|
|
|
ux_sv2buf_bytes(u8bytes, &ibuf); |
102
|
0
|
|
|
|
|
|
ux_depp_init(&depp); |
103
|
0
|
|
|
|
|
|
ibuf.len++; //-- make uxDEyy scanner treat terminating NUL as a "normal" character |
104
|
0
|
|
|
|
|
|
ux_depp_scan_const_buffer(&depp, &ibuf, &pbuf); |
105
|
0
|
0
|
|
|
|
|
if (pbuf.len>0) pbuf.len--; //-- terminating NUL is not really a "normal" character |
106
|
0
|
|
|
|
|
|
ux_unidecode_us(&UNIDECODE_LATIN1, &pbuf, &obuf); |
107
|
0
|
|
|
|
|
|
RETVAL = newSVpvn(obuf.str, obuf.len); |
108
|
0
|
|
|
|
|
|
SvUTF8_off(RETVAL); |
109
|
|
|
|
|
|
|
OUTPUT: |
110
|
|
|
|
|
|
|
RETVAL |
111
|
|
|
|
|
|
|
CLEANUP: |
112
|
0
|
0
|
|
|
|
|
if (pbuf.str) free(pbuf.str); |
113
|
0
|
0
|
|
|
|
|
if (obuf.str) free(obuf.str); |
114
|
0
|
|
|
|
|
|
ux_depp_free_data(&depp); |