15f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian/*
25f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian *  Copyright (C) 2006 George Staikos <staikos@kde.org>
35f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian *  Copyright (C) 2006 Alexey Proskuryakov <ap@nypop.com>
45f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian *  Copyright (C) 2007 Apple Computer, Inc. All rights reserved.
55f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian *  Copyright (C) 2008 Jürg Billeter <j@bitron.ch>
65f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian *  Copyright (C) 2008 Dominik Röttsches <dominik.roettsches@access-company.com>
75f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian *
85f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian *  This library is free software; you can redistribute it and/or
95f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian *  modify it under the terms of the GNU Library General Public
105f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian *  License as published by the Free Software Foundation; either
115f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian *  version 2 of the License, or (at your option) any later version.
125f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian *
135f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian *  This library is distributed in the hope that it will be useful,
145f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian *  but WITHOUT ANY WARRANTY; without even the implied warranty of
155f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
165f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian *  Library General Public License for more details.
175f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian *
185f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian *  You should have received a copy of the GNU Library General Public License
195f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian *  along with this library; see the file COPYING.LIB.  If not, write to
205f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
215f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian *  Boston, MA 02110-1301, USA.
225f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian *
235f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian */
245f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
255f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian#ifndef UnicodeMacrosFromICU_h
265f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian#define UnicodeMacrosFromICU_h
275f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
285f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian// some defines from ICU
295f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
305f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian#define U16_IS_LEAD(c) (((c)&0xfffffc00)==0xd800)
315f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian#define U16_IS_TRAIL(c) (((c)&0xfffffc00)==0xdc00)
325f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian#define U16_SURROGATE_OFFSET ((0xd800<<10UL)+0xdc00-0x10000)
335f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian#define U16_GET_SUPPLEMENTARY(lead, trail) \
345f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    (((UChar32)(lead)<<10UL)+(UChar32)(trail)-U16_SURROGATE_OFFSET)
355f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
365f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian#define U16_LEAD(supplementary) (UChar)(((supplementary)>>10)+0xd7c0)
375f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian#define U16_TRAIL(supplementary) (UChar)(((supplementary)&0x3ff)|0xdc00)
385f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
395f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian#define U_IS_SURROGATE(c) (((c)&0xfffff800)==0xd800)
405f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian#define U16_IS_SINGLE(c) !U_IS_SURROGATE(c)
415f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian#define U16_IS_SURROGATE(c) U_IS_SURROGATE(c)
425f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian#define U16_IS_SURROGATE_LEAD(c) (((c)&0x400)==0)
435f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
445f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian#define U16_PREV(s, start, i, c) { \
455f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    (c)=(s)[--(i)]; \
465f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    if(U16_IS_TRAIL(c)) { \
475f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        uint16_t __c2; \
485f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        if((i)>(start) && U16_IS_LEAD(__c2=(s)[(i)-1])) { \
495f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian            --(i); \
505f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian            (c)=U16_GET_SUPPLEMENTARY(__c2, (c)); \
515f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        } \
525f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    } \
535f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian}
545f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
555f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian#define U16_NEXT(s, i, length, c) { \
565f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    (c)=(s)[(i)++]; \
575f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    if(U16_IS_LEAD(c)) { \
585f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        uint16_t __c2; \
595f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        if((i)<(length) && U16_IS_TRAIL(__c2=(s)[(i)])) { \
605f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian            ++(i); \
615f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian            (c)=U16_GET_SUPPLEMENTARY((c), __c2); \
625f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        } \
635f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    } \
645f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian}
655f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
665f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian#define U_MASK(x) ((uint32_t)1<<(x))
675f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
685f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian#endif
695f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
70