summaryrefslogtreecommitdiff
path: root/anthy/xstr.h
blob: 1d0dd95a0d7033481090a4dbdec6a0c01ae35c7b (plain)
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
/*
 * Anthy内部で使う文字列
 * 特に実装を隠蔽しようとしているわけでは無いので、
 * ここにある関数の使用は強制しない。
 */
#ifndef _xstr_h_included_
#define _xstr_h_included_

/** 文字型
 * UCS4が入っている */
typedef int xchar;

/** 文字列
 * xstrにtypedefされている
 */
typedef struct xstr_ {
  /** 文字列へのポインタ */
  xchar *str;
  /** xcharの数 */
  int len;
} xstr;

/* デバッグ用の出力関数 */
void anthy_putxchar(xchar );
void anthy_putxstr(xstr *);
void anthy_putxstrln(xstr *);

/* Cの文字列への書き出し */
int anthy_sputxchar(char *, xchar , int encoding);
int anthy_sputxstr(char *, xstr *, int encoding);
int anthy_snputxstr(char *, int , xstr *, int encoding);

/* xstrとstr共にmallocされる、freeで両方解放するかanthy_free_xstrで解放する */
xstr *anthy_cstr_to_xstr(const char *, int );
/* 結果はmallocで確保される */
char *anthy_xstr_to_cstr(xstr *, int);

/* xstrとstr共にmallocされる */
xstr *anthy_xstr_dup(xstr *);
void anthy_free_xstr(xstr *);

/* 結果はmallocで確保される */
xchar *anthy_xstr_dup_str(xstr *);
void anthy_free_xstr_str(xstr *);

/* 文字列をコピーする */
xstr* anthy_xstrcpy(xstr *, xstr *);
/* 文字列を比較する。strcmpと同等の動作(返り値の符号に意味がある) */
int anthy_xstrcmp(xstr *, xstr *);
/* n文字目まで文字列を比較する。strncmpと同等の動作(返り値の符号に意味がある) */
int anthy_xstrncmp(xstr *, xstr *, int);
/* s->strをreallocする */
xstr *anthy_xstrcat(xstr *s, xstr *d);
/* xs->strをreallocする */
xstr *anthy_xstrappend(xstr *xs, xchar c);

/* strtollのxstr版 */
long long anthy_xstrtoll(xstr *);
/* 全角数字から半角数字への変換 */
xstr *anthy_xstr_wide_num_to_num(xstr *);
/* ひらがなからカタカナへの変換 */
xstr *anthy_xstr_hira_to_kata(xstr *);
/**/
xstr *anthy_xstr_hira_to_half_kata(xstr *);
xstr *anthy_conv_half_wide(xstr *xs);

/*  xcharの型 */
#define XCT_ALL 0xffffffff
#define XCT_NONE 0
#define XCT_HIRA 1
#define XCT_KATA 2
#define XCT_ASCII 4
#define XCT_NUM 8
#define XCT_WIDENUM 16
#define XCT_OPEN 32
#define XCT_CLOSE 64
/* 直前の文字の一部 */
#define XCT_PART 128
/* 助詞 */
#define XCT_DEP 256
/* 記号 */
#define XCT_SYMBOL 1024
/* 漢字 */
#define XCT_KANJI 2048
/* 句読点 */
#define XCT_PUNCTUATION 4096

/** XCT_*が返ってくる */
int anthy_get_xchar_type(const xchar );
/** 全ての文字に対してXCT_*の論理積をとったもの */
int anthy_get_xstr_type(const xstr *);

/* hash */
int anthy_xstr_hash(xstr *);

/* xstr.c */
int anthy_init_xstr(void);
void anthy_quit_xstr(void);
void anthy_xstr_set_print_encoding(int );

int anthy_euc_to_ucs(int ec);
int anthy_ucs_to_euc(int uc);

const char *anthy_utf8_to_ucs4_xchar(const char *s, xchar *res);
/**/
char *anthy_conv_euc_to_utf8(const char *s);
char *anthy_conv_utf8_to_euc(const char *s);

#endif