summaryrefslogtreecommitdiff
path: root/zap/source/any/str/win1252enc.c
blob: d7ae548d78025ed01e1ac22fd41d214d0d91a001 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
	Copyright 2022-2023 Gabriel Jensen.
	This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
	If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/

#include <zap/str.h>

void zap_win1252enc(zap_i8 * dest,zap_i02 const * src) {
	for (;;++src,++dest) {
		zap_i02 const chr = *src;
		if (chr == 0x0u) break;
		zap_i8 const bad = 0x3Fu;
		switch (chr) {
		default:
			if (chr > 0xFFu) {
				*dest = bad;
				break;
			}
			if (chr >= 0x80u && chr <= 0x9Fu) {
				*dest = bad;
				break;
			}
			*dest = *src;
			break;
		case 0x20ACu:
			*dest = 0x80u;
			break;
		case 0x201Au:
			*dest = 0x82u;
			break;
		case 0x192u:
			*dest = 0x83u;
			break;
		case 0x201Eu:
			*dest = 0x84u;
			break;
		case 0x2026u:
			*dest = 0x85u;
			break;
		case 0x2020u:
			*dest = 0x86u;
			break;
		case 0x2021u:
			*dest = 0x87u;
			break;
		case 0x2C6u:
			*dest = 0x88u;
			break;
		case 0x2030u:
			*dest = 0x89u;
			break;
		case 0x160u:
			*dest = 0x8Au;
			break;
		case 0x2039u:
			*dest = 0x8Bu;
			break;
		case 0x152u:
			*dest = 0x8Cu;
			break;
		case 0x17Du:
			*dest = 0x8Eu;
			break;
		case 0x2018u:
			*dest = 0x91u;
			break;
		case 0x2019u:
			*dest = 0x92u;
			break;
		case 0x201Cu:
			*dest = 0x93u;
			break;
		case 0x201Du:
			*dest = 0x94u;
			break;
		case 0x2022u:
			*dest = 0x95u;
			break;
		case 0x2013u:
			*dest = 0x96u;
			break;
		case 0x2014u:
			*dest = 0x97u;
			break;
		case 0x2DCu:
			*dest = 0x98u;
			break;
		case 0x2122u:
			*dest = 0x99u;
			break;
		case 0x161u:
			*dest = 0x9Au;
			break;
		case 0x203Au:
			*dest = 0x9Bu;
			break;
		case 0x153u:
			*dest = 0x9Cu;
			break;
		case 0x17Eu:
			*dest = 0x9Eu;
			break;
		case 0x178u:
			*dest = 0x9Fu;
			break;
		}
	}
}