From: handa Date: Tue, 15 Jun 2004 23:19:05 +0000 (+0000) Subject: (INC_POSITION): Handle format other than utf8 and utf16. X-Git-Tag: withdl~77 X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=7d56122bba2738b5d47d582c04f501d8e82bd7b6;p=m17n%2Fm17n-lib.git (INC_POSITION): Handle format other than utf8 and utf16. (DEC_POSITION): Likewise. --- diff --git a/src/mtext.c b/src/mtext.c index ab3b350..0bb8f59 100644 --- a/src/mtext.c +++ b/src/mtext.c @@ -104,53 +104,57 @@ static enum MTextFormat default_utf_16 = MTEXT_FORMAT_UTF_16LE; static enum MTextFormat default_utf_32 = MTEXT_FORMAT_UTF_32LE; #endif -/** Increment character position CHAR_POS and byte position BYTE_POS +/** Increment character position CHAR_POS and byte position UNIT_POS so that they point to the next character in M-text MT. No range - check for CHAR_POS and BYTE_POS. */ + check for CHAR_POS and UNIT_POS. */ -#define INC_POSITION(mt, char_pos, byte_pos) \ +#define INC_POSITION(mt, char_pos, unit_pos) \ do { \ int c; \ \ - if ((mt)->format == MTEXT_FORMAT_UTF_8) \ + if ((mt)->format <= MTEXT_FORMAT_UTF_8) \ { \ - c = (mt)->data[(byte_pos)]; \ - (byte_pos) += CHAR_UNITS_BY_HEAD_UTF8 (c); \ + c = (mt)->data[(unit_pos)]; \ + (unit_pos) += CHAR_UNITS_BY_HEAD_UTF8 (c); \ } \ - else \ + else if ((mt)->format <= MTEXT_FORMAT_UTF_16BE) \ { \ - c = ((unsigned short *) ((mt)->data))[(byte_pos)]; \ + c = ((unsigned short *) ((mt)->data))[(unit_pos)]; \ \ if ((mt)->format != default_utf_16) \ c = SWAP_16 (c); \ - (byte_pos) += (c < 0xD800 || c >= 0xE000) ? 1 : 2; \ + (unit_pos) += (c < 0xD800 || c >= 0xE000) ? 1 : 2; \ } \ + else \ + (unit_pos)++; \ (char_pos)++; \ } while (0) -/** Decrement character position CHAR_POS and byte position BYTE_POS +/** Decrement character position CHAR_POS and byte position UNIT_POS so that they point to the previous character in M-text MT. No - range check for CHAR_POS and BYTE_POS. */ + range check for CHAR_POS and UNIT_POS. */ -#define DEC_POSITION(mt, char_pos, byte_pos) \ +#define DEC_POSITION(mt, char_pos, unit_pos) \ do { \ - if ((mt)->format == MTEXT_FORMAT_UTF_8) \ + if ((mt)->format <= MTEXT_FORMAT_UTF_8) \ { \ - unsigned char *p1 = (mt)->data + (byte_pos); \ + unsigned char *p1 = (mt)->data + (unit_pos); \ unsigned char *p0 = p1 - 1; \ \ while (! CHAR_HEAD_P (p0)) p0--; \ - (byte_pos) -= (p1 - p0); \ + (unit_pos) -= (p1 - p0); \ } \ - else \ + else if ((mt)->format <= MTEXT_FORMAT_UTF_16BE) \ { \ - int c = ((unsigned short *) ((mt)->data))[(byte_pos) - 1]; \ + int c = ((unsigned short *) ((mt)->data))[(unit_pos) - 1]; \ \ if ((mt)->format != default_utf_16) \ c = SWAP_16 (c); \ - (byte_pos) -= (c < 0xD800 || c >= 0xE000) ? 1 : 2; \ + (unit_pos) -= (c < 0xD800 || c >= 0xE000) ? 1 : 2; \ } \ + else \ + (unit_pos)--; \ (char_pos)--; \ } while (0)