/* character.h -- header file for the character module.
- Copyright (C) 2003, 2004
+ Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
National Institute of Advanced Industrial Science and Technology (AIST)
Registration Number H15PRO112
You should have received a copy of the GNU Lesser General Public
License along with the m17n library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
02111-1307, USA. */
#ifndef _M17N_CHARACTER_H_
#define STRING_CHAR STRING_CHAR_UTF8
-#define STRING_CHAR_ADVANCE_UTF8(p) \
- (!(*(p) & 0x80) ? *(p)++ \
- : !(*(p) & 0x20) ? (((*(p)++ & 0x1F) << 6) \
- | (*(p)++ & 0x3F)) \
- : !(*(p) & 0x10) ? (((*(p)++ & 0x0F) << 12) \
- | ((*(p)++ & 0x3F) << 6) \
- | (*(p)++ & 0x3F)) \
- : !(*(p) & 0x08) ? (((*(p)++ & 0x07) << 18) \
- | ((*(p)++ & 0x3F) << 12) \
- | ((*(p)++ & 0x3F) << 6) \
- | (*(p)++ & 0x3F)) \
- : !(*(p) & 0x04) ? (((*(p)++ & 0x03) << 24) \
- | ((*(p)++ & 0x3F) << 18) \
- | ((*(p)++ & 0x3F) << 12) \
- | ((*(p)++ & 0x3F) << 6) \
- | (*(p)++ & 0x3F)) \
- : (((*(p)++ & 0x01) << 30) \
- | ((*(p)++ & 0x3F) << 24) \
- | ((*(p)++ & 0x3F) << 18) \
- | ((*(p)++ & 0x3F) << 12) \
- | ((*(p)++ & 0x3F) << 6) \
- | (*(p)++ & 0x3F)))
-
-#define STRING_CHAR_ADVANCE_UTF16(p) \
- (((unsigned short) (p)[0] < 0xD800 || (unsigned short) (p)[0] >= 0xDC00) \
- ? *(p)++ \
- : (((*(p)++ - 0xD800) << 10) + (*(p)++ - 0xDC00) + 0x10000))
+#define STRING_CHAR_ADVANCE_UTF8(p) \
+ (!(*(p) & 0x80) ? ((p)++, (p)[-1]) \
+ : !(*(p) & 0x20) ? ((p) += 2, ((((p)[-2] & 0x1F) << 6) \
+ | ((p)[-1] & 0x3F))) \
+ : !(*(p) & 0x10) ? ((p) += 3, ((((p)[-3] & 0x0F) << 12) \
+ | (((p)[-2] & 0x3F) << 6) \
+ | ((p)[-1] & 0x3F))) \
+ : !(*(p) & 0x08) ? ((p) += 4, ((((p)[-4] & 0x07) << 18) \
+ | (((p)[-3] & 0x3F) << 12) \
+ | (((p)[-2] & 0x3F) << 6) \
+ | ((p)[-1] & 0x3F))) \
+ : !(*(p) & 0x04) ? ((p) += 5, ((((p)[-5] & 0x03) << 24) \
+ | (((p)[-4] & 0x3F) << 18) \
+ | (((p)[-3] & 0x3F) << 12) \
+ | (((p)[-2] & 0x3F) << 6) \
+ | ((p)[-1] & 0x3F))) \
+ : ((p) += 6, ((((p)[-6] & 0x01) << 30) \
+ | (((p)[-5] & 0x3F) << 24) \
+ | (((p)[-4] & 0x3F) << 18) \
+ | (((p)[-3] & 0x3F) << 12) \
+ | (((p)[-2] & 0x3F) << 6) \
+ | ((p)[-1] & 0x3F))))
+
+#define STRING_CHAR_ADVANCE_UTF16(p) \
+ (((p)[0] < 0xD800 || (p)[0] >= 0xDC00) \
+ ? ((p)++, (p)[-1]) \
+ : ((p) += 2, ((((p)[-2] - 0xD800) << 10) + ((p)[-1] - 0xDC00) + 0x10000)))
#define STRING_CHAR_ADVANCE STRING_CHAR_ADVANCE_UTF8