File: Unicode.xs

package info (click to toggle)
libjcode-pm-perl 0.60-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 888 kB
  • ctags: 92
  • sloc: perl: 14,211; ansic: 13,219; makefile: 57
file content (86 lines) | stat: -rw-r--r-- 2,271 bytes parent folder | download
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

static int
not_here(s)
char *s;
{
    croak("%s not implemented on this architecture", s);
    return -1;
}

#define PERL_XS 1
#include "unicode.c"

MODULE = Jcode::Unicode	PACKAGE = Jcode::Unicode

PROTOTYPES: ENABLE

char *
euc_ucs2(src, ...)
        SV *            src
    PROTOTYPE: $;$
    CODE:
        STRLEN srclen;
        STRLEN dstlen;
        char *s = SvROK(src) ? SvPV(SvRV(src), srclen) :SvPV(src, srclen);
	int pedantic = 0;
        if (items > 1) { pedantic = SvIV(ST(1)); };
        dstlen = srclen * 3 + 10; /* large enough? */
	ST(0) = sv_2mortal(newSV(dstlen));
	dstlen = _euc_ucs2(SvPVX(ST(0)), s, pedantic);
        SvCUR_set(ST(0), dstlen);
        SvPOK_only(ST(0));
	if (SvROK(src)) { sv_setsv(SvRV(src), ST(0)); }

char *
ucs2_euc(src, ...)
        SV *            src
    PROTOTYPE: $;$
    CODE:
        STRLEN srclen;
        STRLEN dstlen;
        char *s = SvROK(src) ? SvPV(SvRV(src), srclen) :SvPV(src, srclen);
	int pedantic = 0;
        if (items > 1) { pedantic = SvIV(ST(1)); };
        dstlen = srclen * 3 + 10; /* large enough? */
        ST(0) = sv_2mortal(newSV(dstlen));
        dstlen = _ucs2_euc(SvPVX(ST(0)), s, srclen, pedantic);
        SvCUR_set(ST(0), dstlen);
        SvPOK_only(ST(0));
	if (SvROK(src)) { sv_setsv(SvRV(src), ST(0)); }

char *
utf8_ucs2(src, ...)
        SV *            src
    PROTOTYPE: $
    CODE:
        STRLEN srclen;
        STRLEN dstlen;
        char *s = SvROK(src) ? SvPV(SvRV(src), srclen) :SvPV(src, srclen);
        dstlen = srclen * 3 + 10; /* large enough? */
        ST(0) = sv_2mortal(newSV(dstlen));
        dstlen = _utf8_ucs2(SvPVX(ST(0)), s);
        SvCUR_set(ST(0), dstlen);
        SvPOK_only(ST(0));
	if (SvROK(src)) { sv_setsv(SvRV(src), ST(0)); }

char *
ucs2_utf8(src, ...)
        SV *            src
    PROTOTYPE: $
    CODE:
        STRLEN srclen;
        STRLEN dstlen;
        char *s = SvROK(src) ? SvPV(SvRV(src), srclen) :SvPV(src, srclen);
        dstlen = srclen * 3 + 10; /* large enough? */
        ST(0) = sv_2mortal(newSV(dstlen));
        dstlen = _ucs2_utf8(SvPVX(ST(0)), s, srclen);
        SvCUR_set(ST(0), dstlen);
        SvPOK_only(ST(0));
	if (SvROK(src)) { sv_setsv(SvRV(src), ST(0)); }