Skip to content

Commit f2987f8

Browse files
committed
tutf8e: Tiny UTF-8 Encoder for C
Signed-off-by: Nigel Stewart <[email protected]>
1 parent 121c2a3 commit f2987f8

30 files changed

+2011
-0
lines changed

lib/tutf8e/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 2.8)
2+
project(tutf8e)
3+
4+
set(CMAKE_C_FLAGS "-Os -Wall")
5+
6+
include_directories(include)
7+
file(GLOB src src/*.c)
8+
add_library(tutf8e STATIC ${src})
9+
10+
add_executable(tutf8e-test test/test.c)
11+
target_link_libraries(tutf8e-test tutf8e)

lib/tutf8e/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Nigel Stewart
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

lib/tutf8e/README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# tutf8e
2+
3+
*Tute Feighty*
4+
5+
A tiny UTF-8 encoder for C.
6+
7+
## Goals
8+
9+
* As small and fast as possible
10+
* Narrowly scoped to one-step UTF-8 encoding in C
11+
* Link only what you need and use
12+
* MIT licence
13+
14+
## Supported Encodings
15+
16+
* [iso-8859-1](https://en.wikipedia.org/wiki/ISO/IEC_8859-1) Latin-1 Western European
17+
* [iso-8859-2](https://en.wikipedia.org/wiki/ISO/IEC_8859-2) Latin-2 East European
18+
* [iso-8859-3](https://en.wikipedia.org/wiki/ISO/IEC_8859-3) Latin-3 South European
19+
* [iso-8859-4](https://en.wikipedia.org/wiki/ISO/IEC_8859-4) Latin-4 North European
20+
* [iso-8859-5](https://en.wikipedia.org/wiki/ISO/IEC_8859-5) Part 5: Latin/Cyrillic
21+
* [iso-8859-6](https://en.wikipedia.org/wiki/ISO/IEC_8859-6) Part 6: Latin/Arabic
22+
* [iso-8859-7](https://en.wikipedia.org/wiki/ISO/IEC_8859-7) Part 7: Latin/Greek
23+
* [iso-8859-8](https://en.wikipedia.org/wiki/ISO/IEC_8859-8) Part 8: Latin/Hebrew
24+
* [iso-8859-9](https://en.wikipedia.org/wiki/ISO/IEC_8859-9) Latin-5 Turkish
25+
* [iso-8859-10](https://en.wikipedia.org/wiki/ISO/IEC_8859-10) Latin-6 Nordic
26+
* [iso-8859-11](https://en.wikipedia.org/wiki/ISO/IEC_8859-11) Part 11: Latin/Thai
27+
* [iso-8859-13](https://en.wikipedia.org/wiki/ISO/IEC_8859-13) Latin-7 Baltic Rim
28+
* [iso-8859-14](https://en.wikipedia.org/wiki/ISO/IEC_8859-14) Latin-8 Celtic
29+
* [iso-8859-15](https://en.wikipedia.org/wiki/ISO/IEC_8859-15) Latin-9 Western European
30+
* [iso-8859-16](https://en.wikipedia.org/wiki/ISO/IEC_8859-16) Latin-10 South-Eastern European
31+
* [windows-1250](https://en.wikipedia.org/wiki/Windows-1250) Central European and Eastern European
32+
* [windows-1251](https://en.wikipedia.org/wiki/Windows-1251) Cyrillic
33+
* [windows-1252](https://en.wikipedia.org/wiki/Windows-1252) English
34+
* [windows-1253](https://en.wikipedia.org/wiki/Windows-1253) Greek
35+
* [windows-1254](https://en.wikipedia.org/wiki/Windows-1254) Turkish
36+
* [windows-1255](https://en.wikipedia.org/wiki/Windows-1255) Hebrew
37+
* [windows-1256](https://en.wikipedia.org/wiki/Windows-1256) Arabic
38+
* [windows-1257](https://en.wikipedia.org/wiki/Windows-1257) Baltic
39+
* [windows-1258](https://en.wikipedia.org/wiki/Windows-1258) Vietnamese
40+
41+
## Test Procedure
42+
43+
```
44+
$ ./codegen.py
45+
46+
$ gcc src/* test/test.c -Iinclude
47+
48+
$ ./a.out
49+
A quick brown fox jumps over the lazy dog
50+
Nechť již hříšné saxofony ďáblů rozezvučí síň úděsnými tóny waltzu, tanga a quickstepu.
51+
Pijamalı hasta yağız şoföre çabucak güvendi.
52+
Põdur Zagrebi tšellomängija-följetonist Ciqo külmetas kehvas garaažis
53+
В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!
54+
διαφυλάξτε γενικά τη ζωή σας από βαθειά ψυχικά τραύματα
55+
עטלף אבק נס דרך מזגן שהתפוצץ כי חם
56+
Pijamalı hasta yağız şoföre çabucak güvendi.
57+
Flygande bäckasiner söka hwila på mjuka tuvor.
58+
เป็นมนุษย์สุดประเสริฐเลิศคุณค่า กว่าบรรดาฝูงสัตว์เดรัจฉาน จงฝ่าฟันพัฒนาวิชาการ อย่าล้างผลาญฤๅเข่นฆ่าบีฑาใคร ไม่ถือโทษโกรธแช่งซัดฮึดฮัดด่า หัดอภัยเหมือนกีฬาอัชฌาสัย ปฏิบัติประพฤติกฎกำหนดใจ พูดจาให้จ๊ะๆ จ๋าๆ น่าฟังเอยฯ
59+
Jeżu klątw, spłódź Finom część gry hańb!
60+
11 passed, 0 failed tests
61+
```
62+
63+
## How small is it?
64+
65+
512 bytes + overhead per encoding.
66+
67+
```
68+
$ for i in src/*; do gcc -c $i -O1; done
69+
$ du -bhc *.o | grep total
70+
32K total
71+
72+
$ for i in src/*; do gcc -c $i -O3; done
73+
$ du -bhc *.o | grep total
74+
32K total
75+
76+
$ for i in src/*; do gcc -c $i -Os; done
77+
$ du -bhc *.o | grep total
78+
28K total
79+
```
80+
81+
## Related
82+
83+
* [iconv](https://www.gnu.org/software/libiconv/)
84+
* [icu](http://site.icu-project.org/)

lib/tutf8e/include/tutf8e.h

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
2+
#ifndef TUTF8E_H
3+
#define TUTF8E_H
4+
5+
#include <stddef.h> /* size_t */
6+
#include <stdint.h> /* uint16_t */
7+
8+
/* Internal API */
9+
extern int tutf8e_string_length(const uint16_t *table, const char *i, size_t *ilen, size_t *olen);
10+
extern int tutf8e_buffer_length(const uint16_t *table, const char *i, size_t ilen, size_t *length);
11+
extern int tutf8e_buffer_encode(const uint16_t *table, const char *i, size_t ilen, char *output, size_t *olen);
12+
13+
/* External API */
14+
15+
/* Encode NUL-terminated string to UTF8 */
16+
extern int tutf8e_string_encode_iso_8859_1 (char *output, size_t olen, const char *input);
17+
extern int tutf8e_string_encode_iso_8859_10 (char *output, size_t olen, const char *input);
18+
extern int tutf8e_string_encode_iso_8859_11 (char *output, size_t olen, const char *input);
19+
extern int tutf8e_string_encode_iso_8859_13 (char *output, size_t olen, const char *input);
20+
extern int tutf8e_string_encode_iso_8859_14 (char *output, size_t olen, const char *input);
21+
extern int tutf8e_string_encode_iso_8859_15 (char *output, size_t olen, const char *input);
22+
extern int tutf8e_string_encode_iso_8859_16 (char *output, size_t olen, const char *input);
23+
extern int tutf8e_string_encode_iso_8859_2 (char *output, size_t olen, const char *input);
24+
extern int tutf8e_string_encode_iso_8859_3 (char *output, size_t olen, const char *input);
25+
extern int tutf8e_string_encode_iso_8859_4 (char *output, size_t olen, const char *input);
26+
extern int tutf8e_string_encode_iso_8859_5 (char *output, size_t olen, const char *input);
27+
extern int tutf8e_string_encode_iso_8859_6 (char *output, size_t olen, const char *input);
28+
extern int tutf8e_string_encode_iso_8859_7 (char *output, size_t olen, const char *input);
29+
extern int tutf8e_string_encode_iso_8859_8 (char *output, size_t olen, const char *input);
30+
extern int tutf8e_string_encode_iso_8859_9 (char *output, size_t olen, const char *input);
31+
extern int tutf8e_string_encode_windows_1250(char *output, size_t olen, const char *input);
32+
extern int tutf8e_string_encode_windows_1251(char *output, size_t olen, const char *input);
33+
extern int tutf8e_string_encode_windows_1252(char *output, size_t olen, const char *input);
34+
extern int tutf8e_string_encode_windows_1253(char *output, size_t olen, const char *input);
35+
extern int tutf8e_string_encode_windows_1254(char *output, size_t olen, const char *input);
36+
extern int tutf8e_string_encode_windows_1255(char *output, size_t olen, const char *input);
37+
extern int tutf8e_string_encode_windows_1256(char *output, size_t olen, const char *input);
38+
extern int tutf8e_string_encode_windows_1257(char *output, size_t olen, const char *input);
39+
extern int tutf8e_string_encode_windows_1258(char *output, size_t olen, const char *input);
40+
41+
/* Encode NUL-terminated string to UTF8, realloc as necessary */
42+
extern char * tutf8e_string_encode_iso_8859_1_realloc(char *input);
43+
extern char * tutf8e_string_encode_iso_8859_10_realloc(char *input);
44+
extern char * tutf8e_string_encode_iso_8859_11_realloc(char *input);
45+
extern char * tutf8e_string_encode_iso_8859_13_realloc(char *input);
46+
extern char * tutf8e_string_encode_iso_8859_14_realloc(char *input);
47+
extern char * tutf8e_string_encode_iso_8859_15_realloc(char *input);
48+
extern char * tutf8e_string_encode_iso_8859_16_realloc(char *input);
49+
extern char * tutf8e_string_encode_iso_8859_2_realloc(char *input);
50+
extern char * tutf8e_string_encode_iso_8859_3_realloc(char *input);
51+
extern char * tutf8e_string_encode_iso_8859_4_realloc(char *input);
52+
extern char * tutf8e_string_encode_iso_8859_5_realloc(char *input);
53+
extern char * tutf8e_string_encode_iso_8859_6_realloc(char *input);
54+
extern char * tutf8e_string_encode_iso_8859_7_realloc(char *input);
55+
extern char * tutf8e_string_encode_iso_8859_8_realloc(char *input);
56+
extern char * tutf8e_string_encode_iso_8859_9_realloc(char *input);
57+
extern char * tutf8e_string_encode_windows_1250_realloc(char *input);
58+
extern char * tutf8e_string_encode_windows_1251_realloc(char *input);
59+
extern char * tutf8e_string_encode_windows_1252_realloc(char *input);
60+
extern char * tutf8e_string_encode_windows_1253_realloc(char *input);
61+
extern char * tutf8e_string_encode_windows_1254_realloc(char *input);
62+
extern char * tutf8e_string_encode_windows_1255_realloc(char *input);
63+
extern char * tutf8e_string_encode_windows_1256_realloc(char *input);
64+
extern char * tutf8e_string_encode_windows_1257_realloc(char *input);
65+
extern char * tutf8e_string_encode_windows_1258_realloc(char *input);
66+
67+
/* Encode buffer to UTF8 */
68+
extern int tutf8e_buffer_encode_iso_8859_1 (char *output, size_t *olen, const char *input, size_t ilen);
69+
extern int tutf8e_buffer_encode_iso_8859_10 (char *output, size_t *olen, const char *input, size_t ilen);
70+
extern int tutf8e_buffer_encode_iso_8859_11 (char *output, size_t *olen, const char *input, size_t ilen);
71+
extern int tutf8e_buffer_encode_iso_8859_13 (char *output, size_t *olen, const char *input, size_t ilen);
72+
extern int tutf8e_buffer_encode_iso_8859_14 (char *output, size_t *olen, const char *input, size_t ilen);
73+
extern int tutf8e_buffer_encode_iso_8859_15 (char *output, size_t *olen, const char *input, size_t ilen);
74+
extern int tutf8e_buffer_encode_iso_8859_16 (char *output, size_t *olen, const char *input, size_t ilen);
75+
extern int tutf8e_buffer_encode_iso_8859_2 (char *output, size_t *olen, const char *input, size_t ilen);
76+
extern int tutf8e_buffer_encode_iso_8859_3 (char *output, size_t *olen, const char *input, size_t ilen);
77+
extern int tutf8e_buffer_encode_iso_8859_4 (char *output, size_t *olen, const char *input, size_t ilen);
78+
extern int tutf8e_buffer_encode_iso_8859_5 (char *output, size_t *olen, const char *input, size_t ilen);
79+
extern int tutf8e_buffer_encode_iso_8859_6 (char *output, size_t *olen, const char *input, size_t ilen);
80+
extern int tutf8e_buffer_encode_iso_8859_7 (char *output, size_t *olen, const char *input, size_t ilen);
81+
extern int tutf8e_buffer_encode_iso_8859_8 (char *output, size_t *olen, const char *input, size_t ilen);
82+
extern int tutf8e_buffer_encode_iso_8859_9 (char *output, size_t *olen, const char *input, size_t ilen);
83+
extern int tutf8e_buffer_encode_windows_1250(char *output, size_t *olen, const char *input, size_t ilen);
84+
extern int tutf8e_buffer_encode_windows_1251(char *output, size_t *olen, const char *input, size_t ilen);
85+
extern int tutf8e_buffer_encode_windows_1252(char *output, size_t *olen, const char *input, size_t ilen);
86+
extern int tutf8e_buffer_encode_windows_1253(char *output, size_t *olen, const char *input, size_t ilen);
87+
extern int tutf8e_buffer_encode_windows_1254(char *output, size_t *olen, const char *input, size_t ilen);
88+
extern int tutf8e_buffer_encode_windows_1255(char *output, size_t *olen, const char *input, size_t ilen);
89+
extern int tutf8e_buffer_encode_windows_1256(char *output, size_t *olen, const char *input, size_t ilen);
90+
extern int tutf8e_buffer_encode_windows_1257(char *output, size_t *olen, const char *input, size_t ilen);
91+
extern int tutf8e_buffer_encode_windows_1258(char *output, size_t *olen, const char *input, size_t ilen);
92+
93+
#endif

lib/tutf8e/src/iso_8859_1.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <tutf8e.h>
2+
3+
#include <string.h> /* strlen */
4+
#include <stdlib.h> /* malloc/free */
5+
6+
static const uint16_t iso_8859_1_utf8[256] =
7+
{
8+
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f,
9+
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f,
10+
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f,
11+
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f,
12+
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f,
13+
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f,
14+
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f,
15+
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f,
16+
0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,
17+
0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f,
18+
0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af,
19+
0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf,
20+
0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf,
21+
0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df,
22+
0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
23+
0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff,
24+
};
25+
26+
int tutf8e_string_encode_iso_8859_1(char *output, size_t olen, const char *input)
27+
{
28+
size_t len = strlen(input) + 1;
29+
return tutf8e_buffer_encode(iso_8859_1_utf8, input, len, output, &olen);
30+
}
31+
32+
int tutf8e_buffer_encode_iso_8859_1(char *output, size_t *olen, const char *input, size_t ilen)
33+
{
34+
return tutf8e_buffer_encode(iso_8859_1_utf8, input, ilen, output, olen);
35+
}
36+
37+
char * tutf8e_string_encode_iso_8859_1_realloc(char *input)
38+
{
39+
size_t ilen = 0;
40+
size_t olen = 0;
41+
if (input && !tutf8e_string_length(iso_8859_1_utf8, input, &ilen, &olen) && ilen && olen && ilen!=olen) {
42+
char * output = malloc(olen + 1);
43+
if (output && !tutf8e_buffer_encode(iso_8859_1_utf8, input, ilen, output, &olen)) {
44+
free(input);
45+
output[olen] = 0;
46+
return output;
47+
}
48+
free(output);
49+
}
50+
return input;
51+
}

lib/tutf8e/src/iso_8859_10.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <tutf8e.h>
2+
3+
#include <string.h> /* strlen */
4+
#include <stdlib.h> /* malloc/free */
5+
6+
static const uint16_t iso_8859_10_utf8[256] =
7+
{
8+
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f,
9+
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f,
10+
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f,
11+
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f,
12+
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f,
13+
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f,
14+
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f,
15+
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f,
16+
0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,
17+
0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f,
18+
0x00a0, 0x0104, 0x0112, 0x0122, 0x012a, 0x0128, 0x0136, 0x00a7, 0x013b, 0x0110, 0x0160, 0x0166, 0x017d, 0x00ad, 0x016a, 0x014a,
19+
0x00b0, 0x0105, 0x0113, 0x0123, 0x012b, 0x0129, 0x0137, 0x00b7, 0x013c, 0x0111, 0x0161, 0x0167, 0x017e, 0x2015, 0x016b, 0x014b,
20+
0x0100, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x012e, 0x010c, 0x00c9, 0x0118, 0x00cb, 0x0116, 0x00cd, 0x00ce, 0x00cf,
21+
0x00d0, 0x0145, 0x014c, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x0168, 0x00d8, 0x0172, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df,
22+
0x0101, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x012f, 0x010d, 0x00e9, 0x0119, 0x00eb, 0x0117, 0x00ed, 0x00ee, 0x00ef,
23+
0x00f0, 0x0146, 0x014d, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x0169, 0x00f8, 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x0138,
24+
};
25+
26+
int tutf8e_string_encode_iso_8859_10(char *output, size_t olen, const char *input)
27+
{
28+
size_t len = strlen(input) + 1;
29+
return tutf8e_buffer_encode(iso_8859_10_utf8, input, len, output, &olen);
30+
}
31+
32+
int tutf8e_buffer_encode_iso_8859_10(char *output, size_t *olen, const char *input, size_t ilen)
33+
{
34+
return tutf8e_buffer_encode(iso_8859_10_utf8, input, ilen, output, olen);
35+
}
36+
37+
char * tutf8e_string_encode_iso_8859_10_realloc(char *input)
38+
{
39+
size_t ilen = 0;
40+
size_t olen = 0;
41+
if (input && !tutf8e_string_length(iso_8859_10_utf8, input, &ilen, &olen) && ilen && olen && ilen!=olen) {
42+
char * output = malloc(olen + 1);
43+
if (output && !tutf8e_buffer_encode(iso_8859_10_utf8, input, ilen, output, &olen)) {
44+
free(input);
45+
output[olen] = 0;
46+
return output;
47+
}
48+
free(output);
49+
}
50+
return input;
51+
}

0 commit comments

Comments
 (0)