• R/O
  • SSH
  • HTTPS

bchan: 提交


Commit MetaInfo

修訂594 (tree)
時間2013-12-06 02:02:27
作者ornse01

Log Message

replace implementation for language code handling.

Change Summary

差異

--- bchanf/trunk/src/control/texteditor_characterstate.c (revision 593)
+++ bchanf/trunk/src/control/texteditor_characterstate.c (revision 594)
@@ -28,6 +28,9 @@
2828
2929 #include <bstdio.h>
3030
31+#include <tad/tadfragment.h>
32+#include <tad/tadlangcode.h>
33+
3134 #ifdef BCHAN_CONFIG_DEBUG
3235 # define DP(arg) printf arg
3336 # define DP_ER(msg, err) printf("%s (%d/%x)\n", msg, err>>16, err)
@@ -38,8 +41,8 @@
3841
3942 EXPORT W texteditor_charactorstate_input(texteditor_characterstate_t *state, tadfragment_cursor_segment *segment)
4043 {
41- TC ch;
42- W iter;
44+ TC *str;
45+ W len, err;
4346 UB segid, subid;
4447
4548 if (segment->type == TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE) {
@@ -56,13 +59,12 @@
5659 }
5760 state->w_ratio = *(RATIO*)(segment->p + 8);
5861 } else if (segment->type == TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE) {
59- ch = *(TC*)(segment->p + segment->len - 2);
60- iter = segment->len - 2;
61- if ((ch & 0xFE00) == 0xFE00) {
62- iter++;
62+ str = (TC*)segment->p;
63+ len = segment->len / sizeof(TC);
64+ err = TCtotadlangcode(str, len, &state->lang);
65+ if (err < 0) {
66+ return err;
6367 }
64- state->lang.iter = iter - 1;
65- state->lang.code = 0x00FF & ch;
6668 }
6769 return 0;
6870 }
@@ -82,44 +84,12 @@
8284
8385 EXPORT W texteditor_characterstate_getlang(texteditor_characterstate_t *state, TC *str, W len)
8486 {
85- W i, req_len;
86-
87- req_len = 2 + (state->lang.iter+1)/2*2;
88-
89- if (str == NULL || len < 0) {
90- return req_len / sizeof(TC);
91- }
92-
93- for (i = 0; i < (state->lang.iter + 1) / 2; i++) {
94- str[i] = 0xFEFE;
95- }
96- if (state->lang.iter % 2 == 1) {
97- str[i] = state->lang.code;
98- } else {
99- str[i] = 0xFE00 | state->lang.code;
100- }
101-
102- return req_len / sizeof(TC);
87+ return tadlangcodetoTC(&state->lang, str, len);
10388 }
10489
10590 EXPORT Bool texteditor_characterstate_islang(texteditor_characterstate_t *state, TC *str, W len)
10691 {
107- TC ch;
108- W iter;
109- UH code;
110-
111- ch = str[len - 1];
112- iter = (len - 1) * 2;
113- if ((ch & 0xFE00) == 0xFE00) {
114- iter++;
115- }
116- iter--;
117- code = 0x00FF & ch;
118-
119- if ((state->lang.iter == iter)&&(state->lang.code == code)) {
120- return True;
121- }
122- return False;
92+ return tadlangcodecmpTC(str, len, &state->lang);
12393 }
12494
12595 EXPORT VOID texteditor_characterstate_initialize(texteditor_characterstate_t *state)
--- bchanf/trunk/src/control/texteditor_characterstate.h (revision 593)
+++ bchanf/trunk/src/control/texteditor_characterstate.h (revision 594)
@@ -27,6 +27,7 @@
2727 #include <basic.h>
2828
2929 #include <tad/tadfragment.h>
30+#include <tad/tadlangcode.h>
3031
3132 #ifndef __TEXTEDITOR_CHARACTERSTATE_H__
3233 #define __TEXTEDITOR_CHARACTERSTATE_H__
@@ -35,10 +36,7 @@
3536 /* Detail name: characterstate */
3637 struct texteditor_characterstate_t_ {
3738 RATIO w_ratio;
38- struct {
39- UW iter;
40- UB code;
41- } lang;
39+ tadlangcode lang;
4240 };
4341 typedef struct texteditor_characterstate_t_ texteditor_characterstate_t;
4442
Show on old repository browser