- int beg, end;
- int c;
-
- /* Extra 1-byte is for 0 terminating. */
- tis = alloca ((*to - *from) + 1);
-
- for (beg = pos; beg > *from; beg--)
- {
- if ((c = mtext_ref_char (mt, beg - 1)) < THAI_BEG || c > THAI_END)
- break;
- tis[beg - 1 - *from] = 0xA1 + (c - THAI_BEG);
- }
- for (end = pos; end < *to; end++)
- {
- if ((c = mtext_ref_char (mt, end)) < THAI_BEG || c > THAI_END)
- break;
- tis[end - *from] = 0xA1 + (c - THAI_BEG);
- }
-
- if (pos == end)
- {
- *from = *to = pos;
- return 0;
- }
-
- /* Make it terminate by 0. */
- tis[end - *from] = 0;
- prop = wordseg_propertize (mt, pos, beg, end, tis + (beg - *from));
+ int i;
+
+ for (beg = pos; beg > 0; beg--)
+ if ((c = mtext_ref_char (mt, beg - 1)) < THAI_BEG || c > THAI_END)
+ break;
+ for (end = pos + 1; end < len; end++)
+ if ((c = mtext_ref_char (mt, end)) < THAI_BEG || c > THAI_END)
+ break;
+
+ /* Extra 1-byte for 0 terminating. */
+ tis = alloca ((end - beg) + 1);
+
+ for (i = beg; i < end; i++)
+ tis[i - beg] = 0xA1 + (mtext_ref_char (mt, i) - THAI_BEG);
+ tis[i - beg] = 0;
+ prop = wordseg_propertize (mt, pos, beg, end, tis);
+ i = MTEXTPROP_START (prop);
+ beg = (i > beg || i == 0) ? i : -1;
+ i = MTEXTPROP_END (prop);
+ end = (i < end || i == len) ? i : -1;