-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathopencc.c
46 lines (34 loc) · 900 Bytes
/
opencc.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "opencc/opencc.h"
const char *Convert(const char *input, const char *config) {
if(strlen(config) > 16) {
return 0;
}
char configFile[256] = "/usr/share/opencc/";
strcat(configFile, config);
strcat(configFile, ".json");
opencc_t p = opencc_open(configFile);
char *out = opencc_convert_utf8(p, input, strlen(input));
out[strlen(input)] = '\0';
opencc_close(p);
return out;
}
void Convert_free_string(char *p) {
opencc_convert_utf8_free(p);
}
void* Opencc_New(const char *configFile) {
return opencc_open(configFile);
}
void Opencc_Delete(void *id) {
opencc_close(id);
}
const char *Opencc_Convert(void *id, const char *input) {
char *output = opencc_convert_utf8(id, input, strlen(input));
output[strlen(input)] = '\0';
return output;
}
void Opencc_Free_String(char *p) {
opencc_convert_utf8_free(p);
}