aboutsummaryrefslogtreecommitdiffstats
path: root/libwc/priv.c
blob: 62a4240221a3e4d6eb3163082c0742451c428074 (plain) (blame)
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
#include "wc.h"
#include "wtf.h"

Str
wc_conv_from_priv1(Str is, wc_ces ces)
{
    Str os;
    wc_uchar *sp = (wc_uchar *)is->ptr;
    wc_uchar *ep = sp + is->length;
    wc_uchar *p;
    wc_ccs ccs = WcCesInfo[WC_CCS_INDEX(ces)].gset[1].ccs;

    for (p = sp; p < ep && *p < 0x80; p++)
	;
    if (p == ep)
	return is;
    os = Strnew_size(is->length);
    if (p > sp)
	Strcat_charp_n(os, is->ptr, (int)(p - sp));

    for (; p < ep; p++) {
	if (*p & 0x80)
	    wtf_push(os, ccs, (wc_uint32)*p);
	else
	    Strcat_char(os, (char)*p);
    }
    return os;
}

Str
wc_char_conv_from_priv1(wc_uchar c, wc_status *st)
{
    Str os = Strnew_size(1);

    if (c & 0x80)
	wtf_push(os, st->ces_info->gset[1].ccs, (wc_uint32)c);
    else
	Strcat_char(os, (char)c);
    return os;
}

Str
wc_conv_from_ascii(Str is, wc_ces ces)
{
    Str os;
    wc_uchar *sp = (wc_uchar *)is->ptr;
    wc_uchar *ep = sp + is->length;
    wc_uchar *p;

    for (p = sp; p < ep && *p < 0x80; p++)
	;
    if (p == ep)
	return is;
    os = Strnew_size(is->length);
    if (p > sp)
	Strcat_charp_n(os, is->ptr, (int)(p - sp));

    for (; p < ep; p++) {
	if (*p & 0x80)
	    wtf_push_unknown(os, p, 1);
	else
	    Strcat_char(os, (char)*p);
    }
    return os;
}

void
wc_push_to_raw(Str os, wc_wchar_t cc, wc_status *st)
{

    switch (cc.ccs) {
    case WC_CCS_US_ASCII:
    case WC_CCS_RAW:
	Strcat_char(os, (char)cc.code);
    }
    return;
}