Skip to content

Commit 46e3cfd

Browse files
committed
hangul_ic_* 에 대한 obj-c wrapper
1 parent 5a8c3db commit 46e3cfd

10 files changed

+688
-29
lines changed

.gitignore

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Backup files from text editors
2+
*~
3+
*.DS_Store
4+
.*.swp
5+
.hg
6+
.hgignore
7+
.svn
8+
.svnignore
9+
10+
# Xcode crap
11+
*mode1v3
12+
*pbxuser
13+
*perspectivev3
14+
*xcuserdata*
15+
*xcworkspace*
16+
# Junk files on Mac OS X
17+
*.DS_Store
18+
19+
build
20+

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "libhangul"]
2+
path = libhangul
3+
url = git://github.com/gureum/libhangul.git

Hangul.xcodeproj/project.pbxproj

+176-27
Large diffs are not rendered by default.

Hangul/HGCharacter.h

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//
2+
// HGCharacter.h
3+
// CharmIM
4+
//
5+
// Created by youknowone on 11. 9. 2..
6+
// Copyright 2011 youknowone.org. All rights reserved.
7+
//
8+
9+
/*!
10+
@header
11+
@brief See hangul.h and hangulctype.c to see related libhangul functions
12+
13+
libhangul의 ctype 함수를 Apple Coding Guideline에 따라 재명명. 연관된 함수를 확인하려면 hangul/hangul.h 와 hangul/hangulctype.c 를 확인한다.
14+
*/
15+
16+
#include <Hangul/hangul.h>
17+
18+
//! @brief libhangul 의 글자 단위인 ucschar의 alias
19+
typedef ucschar HGUCSChar;
20+
21+
//! @ref hangul_is_choseong
22+
BOOL HGCharacterIsChoseong(HGUCSChar character);
23+
//! @ref hangul_is_jungseong
24+
BOOL HGCharacterIsJungseong(HGUCSChar character);
25+
//! @ref hangul_is_jongseong
26+
BOOL HGCharacterIsJongseong(HGUCSChar character);
27+
//! @ref hangul_is_choseong_conjoinable
28+
BOOL HGCharacterIsChoseongConjoinable(HGUCSChar character);
29+
//! @ref hangul_is_jungseong_conjoinable
30+
BOOL HGCharacterIsJungseongConjoinable(HGUCSChar character);
31+
//! @ref hangul_is_jongseong_conjoinable
32+
BOOL HGCharacterIsJongseongConjoinable(HGUCSChar character);
33+
//! @ref hangul_is_syllable
34+
BOOL HGCharacterIsSyllable(HGUCSChar character);
35+
//! @ref hangul_is_jamo
36+
BOOL HGCharacterIsJamo(HGUCSChar character);
37+
//! @ref hangul_is_cjamo
38+
BOOL HGCharacterIsCompatibleJamo(HGUCSChar character);
39+
40+
//! @ref hangul_jamo_to_cjamo
41+
HGUCSChar HGCompatibleJamoFromJamo(HGUCSChar character);
42+
43+
//! @ref hangul_choseong_to_jongseong
44+
HGUCSChar HGJongseongFromChoseong(HGUCSChar character);
45+
//! @ref hangul_jongseong_to_choseong
46+
HGUCSChar HGChoseongFromJongseong(HGUCSChar character);
47+
//! @ref hangul_jongseong_dicompose
48+
void HGGetDecomposedCharactersFromJongseong(HGUCSChar character,
49+
HGUCSChar* jongseong,
50+
HGUCSChar* choseong);
51+
52+
//! @ref hangul_syllable_iterator_prev
53+
const HGUCSChar* HGPreviousSyllableInJamoString(const HGUCSChar* jamoString,
54+
const HGUCSChar* begin);
55+
//! @ref hangul_syllable_iterator_next
56+
const HGUCSChar* HGNextSyllableInJamoString(const HGUCSChar* jamoString,
57+
const HGUCSChar* end);
58+
59+
//! @ref hangul_syllable_len
60+
NSInteger HGSyllableLength(const HGUCSChar *string, NSInteger maxLength); // jamoString?
61+
//! @ref hangul_jamo_to_syllable
62+
HGUCSChar HGSyllableFromJamo(HGUCSChar choseong, HGUCSChar jungseong,
63+
HGUCSChar jongseong);
64+
//! @ref hangul_syllable_to_jamo
65+
void HGGetJamoFromSyllable(HGUCSChar syllable, HGUCSChar *choseong,
66+
HGUCSChar *jungseong, HGUCSChar *jongseong);
67+
//! @ref hangul_jamos_to_syllables
68+
NSInteger HGGetSyllablesFromJamos(const HGUCSChar* jamos, NSInteger jamosLength,
69+
HGUCSChar* syllables, NSInteger syllablesLength);

Hangul/HGCharacter.m

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//
2+
// HGCharacter.m
3+
// CharmIM
4+
//
5+
// Created by youknowone on 11. 9. 2..
6+
// Copyright 2011 youknowone.org. All rights reserved.
7+
//
8+
9+
#import "HGCharacter.h"
10+
11+
inline BOOL HGCharacterIsChoseong(HGUCSChar character) {
12+
return (BOOL)hangul_is_choseong(character);
13+
}
14+
15+
inline BOOL HGCharacterIsJungseong(HGUCSChar character) {
16+
return (BOOL)hangul_is_jungseong(character);
17+
}
18+
19+
inline BOOL HGCharacterIsJongseong(HGUCSChar character) {
20+
return (BOOL)hangul_is_jongseong(character);
21+
}
22+
23+
inline BOOL HGCharacterIsChoseongConjoinable(HGUCSChar character) {
24+
return (BOOL)hangul_is_choseong_conjoinable(character);
25+
}
26+
27+
inline BOOL HGCharacterIsJungseongConjoinable(HGUCSChar character) {
28+
return (BOOL)hangul_is_jungseong_conjoinable(character);
29+
}
30+
31+
inline BOOL HGCharacterIsJongseongConjoinable(HGUCSChar character) {
32+
return (BOOL)hangul_is_jongseong_conjoinable(character);
33+
}
34+
35+
inline BOOL HGCharacterIsSyllable(HGUCSChar character) {
36+
return (BOOL)hangul_is_syllable(character);
37+
}
38+
39+
inline BOOL HGCharacterIsJamo(HGUCSChar character) {
40+
return (BOOL)hangul_is_jamo(character);
41+
}
42+
43+
inline BOOL HGCharacterIsCompatibleJamo(HGUCSChar character) {
44+
return (BOOL)hangul_is_cjamo(character);
45+
}
46+
47+
inline HGUCSChar HGCompatibleJamoFromJamo(HGUCSChar character) {
48+
return hangul_jamo_to_cjamo(character);
49+
}
50+
51+
inline HGUCSChar HGJongseongFromChoseong(HGUCSChar character) {
52+
return hangul_choseong_to_jongseong(character);
53+
}
54+
55+
inline HGUCSChar HGChoseongFromJongseong(HGUCSChar character) {
56+
return hangul_jongseong_to_choseong(character);
57+
}
58+
59+
inline void HGGetDecomposedCharactersFromJongseong(HGUCSChar character,
60+
HGUCSChar* jongseong,
61+
HGUCSChar* choseong) {
62+
return hangul_jongseong_dicompose(character, jongseong, choseong);
63+
}
64+
65+
inline const HGUCSChar* HGPreviousSyllableInJamoString(const HGUCSChar* jamoString,
66+
const HGUCSChar* begin) {
67+
return hangul_syllable_iterator_prev(jamoString, begin);
68+
}
69+
70+
inline const HGUCSChar* HGNextSyllableInJamoString(const HGUCSChar* jamoString,
71+
const HGUCSChar* end) {
72+
return hangul_syllable_iterator_next(jamoString, end);
73+
}
74+
75+
inline NSInteger HGSyllableLength(const HGUCSChar *string, NSInteger maxLength) {
76+
return (NSInteger)hangul_syllable_len(string, (int)maxLength);
77+
}
78+
79+
inline HGUCSChar HGSyllableFromJamo(HGUCSChar choseong, HGUCSChar jungseong,
80+
HGUCSChar jongseong) {
81+
return hangul_jamo_to_syllable(choseong, jungseong, jongseong);
82+
}
83+
84+
inline void HGGetJamoFromSyllable(HGUCSChar syllable, HGUCSChar *choseong,
85+
HGUCSChar *jungseong, HGUCSChar *jongseong) {
86+
return hangul_syllable_to_jamo(syllable, choseong, jungseong, jongseong);
87+
}
88+
89+
inline NSInteger HGGetSyllablesFromJamos(const HGUCSChar* jamos, NSInteger jamosLength,
90+
HGUCSChar* syllables, NSInteger syllablesLength) {
91+
return (NSInteger)hangul_jamos_to_syllables(syllables, (int)syllablesLength, jamos, (int)jamosLength);
92+
}

Hangul/HGInputContext.h

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
//
2+
// HGInputContext.h
3+
// CharmIM
4+
//
5+
// Created by youknowone on 11. 9. 1..
6+
// Copyright 2011 youknowone.org. All rights reserved.
7+
//
8+
9+
/*!
10+
@header
11+
@brief See hangul.h and hangulinputcontext.c to see related libhangul functions
12+
13+
libhangul의 hangul input context 코드를 Objective-C 객체 모델로 감싼다. 관련 libhangul 함수를 보기 위해서 hangul/hangul.h와 hangul/hangulinputcontext.c 를 본다.
14+
*/
15+
16+
#import <Foundation/Foundation.h>
17+
#import <Hangul/HGCharacter.h>
18+
19+
@class HGHangulCombination;
20+
21+
/*!
22+
@brief @ref HangulKeyboard 를 감싼다.
23+
24+
@ref HGInputContext 를 위해 새 데이터를 만들때는 -init 을, 원래의 HangulKeyboard 데이터를 변환하기 위해서는 -initWithKeyboardData:freeWhenDone: 과 -keyboardWithKeyboardData:freeWhenDone: 을 사용한다.
25+
*/
26+
@interface HGKeyboard : NSObject {
27+
@private
28+
HangulKeyboard *data;
29+
30+
struct {
31+
unsigned freeWhenDone:1;
32+
} flags;
33+
}
34+
/*! @property
35+
@brief 미구현 기능을 위해 HangulKeyboard 객체에 접근할 때 사용한다.
36+
*/
37+
@property(nonatomic, readonly) HangulKeyboard *data;
38+
39+
//! @brief HangulKeyboard 데이터를 기반으로 객체 생성
40+
- (id)initWithKeyboardData:(HangulKeyboard *)data freeWhenDone:(BOOL)YesOrNo;
41+
//! @brief HangulKeyboard 데이터를 기반으로 객체 생성
42+
+ (id)keyboardWithKeyboardData:(HangulKeyboard *)data freeWhenDone:(BOOL)YesOrNo;
43+
44+
//! @brief @ref hangul_keyboard_set_value
45+
- (void)setValue:(HGUCSChar)value forKey:(int)key;
46+
//! @brief @ref hangul_keyboard_set_type
47+
- (void)setType:(int)type;
48+
49+
@end
50+
51+
/*!
52+
@brief 출력 형태에 관한 상수
53+
*/
54+
typedef enum {
55+
HGOutputModeSyllable = HANGUL_OUTPUT_SYLLABLE,
56+
HGOutputModeJamo = HANGUL_OUTPUT_JAMO,
57+
} HGOutputMode;
58+
59+
/*!
60+
@brief @ref HangulInputContext 를 감싼다.
61+
62+
@ref HangulInputContext 의 기능에 대한 Objective-C의 객체 모델을 제공한다. 객체 모델이 지원하지 않는 기능에 대해서는 -context 로 libhangul의 컨텍스트에 직접 접근하여 사용할 수 있다.
63+
*/
64+
@interface HGInputContext : NSObject {
65+
@private
66+
HangulInputContext *context;
67+
}
68+
69+
//! @brief 미구현 기능을 이용하기 위해 HangulInputContext 에 직접 접근
70+
@property(nonatomic, readonly) HangulInputContext *context;
71+
72+
//! @brief @ref hangul_ic_new @ref hangul_ic_delete
73+
- (id)initWithKeyboardIdentifier:(NSString *)code;
74+
//! @brief @ref hangul_ic_process
75+
- (BOOL)process:(int)ascii;
76+
//! @brief @ref hangul_ic_reset
77+
- (void)reset;
78+
//! @brief @ref hangul_ic_backspace
79+
- (BOOL)backspace;
80+
81+
//! @brief @ref hangul_ic_is_empty
82+
@property(nonatomic, readonly, getter=isEmpty) BOOL empty;
83+
//! @brief @ref hangul_ic_has_choseong
84+
@property(nonatomic, readonly) BOOL hasChoseong;
85+
//! @brief @ref hangul_ic_has_jungseong
86+
@property(nonatomic, readonly) BOOL hasJungseong;
87+
//! @brief @ref hangul_ic_has_jongseong
88+
@property(nonatomic, readonly) BOOL hasJongseong;
89+
//! @brief @ref hangul_ic_is_transliteration
90+
@property(nonatomic, readonly, getter=isTransliteration) BOOL transliteration;
91+
/*!
92+
@brief @ref hangul_ic_preedit_string
93+
94+
@ref IMKInputController 의 -composedString 과 대응한다.
95+
*/
96+
@property(nonatomic, readonly) NSString *preeditString;
97+
//! @brief @ref hangul_ic_commit_string
98+
@property(nonatomic, readonly) NSString *commitString;
99+
/*!
100+
@brief @ref hangul_ic_flush
101+
102+
@discussion 현재 조합 중인 글자의 조합을 완료하고 @ref preeditString 을 결과로 돌려준다.
103+
*/
104+
- (NSString *)flushString; // unclear naming...
105+
106+
//! @brief @ref hangul_ic_set_output_mode
107+
- (void)setOutputMode:(HGOutputMode)mode;
108+
//! @brief @ref hangul_ic_set_keyboard
109+
- (void)setKeyboard:(HGKeyboard *)aKeyboard;
110+
//! @brief @ref hangul_ic_set_keyboard
111+
- (void)setKeyboardWithData:(HangulKeyboard *)keyboardData;
112+
//! @brief @ref hangul_ic_select_keyboard
113+
- (void)setKeyboardWithIdentifier:(NSString *)identifier;
114+
//! @brief @ref hangul_ic_set_combination
115+
- (void)setCombination:(HangulCombination *)aCombination;
116+
117+
/* out of use, out of mind
118+
void hangul_ic_connect_callback(HangulInputContext* hic, const char* event,
119+
void* callback, void* user_data);
120+
121+
*/
122+
@end
123+
124+
/* out of use, out of mind
125+
unsigned hangul_ic_get_n_keyboards();
126+
*/
127+
//! @brief @ref hangul_ic_get_keyboard_id
128+
NSString *HGKeyboardIdentifierAtIndex(NSUInteger index);
129+
//! @brief @ref hangul_ic_get_keyboard_name
130+
NSString *HGKeyboardNameAtIndex(NSUInteger index);
131+
132+
133+
/*!
134+
@brief HGUSCChar - NSString 변환
135+
136+
libhangul의 ucschar 문자열을 NSString 으로 변환하는 생성자 카테고리이다.
137+
*/
138+
@interface NSString (HGUCS)
139+
140+
//! @brief HGUCSChar 문자열로 NSString을 생성 (UTF-32LE)
141+
- (id)initWithHGUCSString:(const HGUCSChar *)ucsString;
142+
//! @brief HGUCSChar 문자열로 NSString을 생성 (UTF-32LE)
143+
+ (id)stringWithHGUCSString:(const HGUCSChar *)ucsString;
144+
145+
@end

0 commit comments

Comments
 (0)