1 /* 2 * Copyright (C) 2006 George Staikos <staikos (at) kde.org> 3 * Copyright (C) 2006 Alexey Proskuryakov <ap (at) nypop.com> 4 * Copyright (C) 2007 Apple Computer, Inc. All rights reserved. 5 * Copyright (C) 2008 Jrg Billeter <j (at) bitron.ch> 6 * Copyright (C) 2008 Dominik Rttsches <dominik.roettsches (at) access-company.com> 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Library General Public 10 * License as published by the Free Software Foundation; either 11 * version 2 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Library General Public License for more details. 17 * 18 * You should have received a copy of the GNU Library General Public License 19 * along with this library; see the file COPYING.LIB. If not, write to 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 * Boston, MA 02110-1301, USA. 22 * 23 */ 24 25 #ifndef UnicodeMacrosFromICU_h 26 #define UnicodeMacrosFromICU_h 27 28 // some defines from ICU 29 30 #define U16_IS_LEAD(c) (((c)&0xfffffc00)==0xd800) 31 #define U16_IS_TRAIL(c) (((c)&0xfffffc00)==0xdc00) 32 #define U16_SURROGATE_OFFSET ((0xd800<<10UL)+0xdc00-0x10000) 33 #define U16_GET_SUPPLEMENTARY(lead, trail) \ 34 (((UChar32)(lead)<<10UL)+(UChar32)(trail)-U16_SURROGATE_OFFSET) 35 36 #define U16_LEAD(supplementary) (UChar)(((supplementary)>>10)+0xd7c0) 37 #define U16_TRAIL(supplementary) (UChar)(((supplementary)&0x3ff)|0xdc00) 38 39 #define U_IS_SURROGATE(c) (((c)&0xfffff800)==0xd800) 40 #define U16_IS_SINGLE(c) !U_IS_SURROGATE(c) 41 #define U16_IS_SURROGATE(c) U_IS_SURROGATE(c) 42 #define U16_IS_SURROGATE_LEAD(c) (((c)&0x400)==0) 43 44 #define U16_PREV(s, start, i, c) { \ 45 (c)=(s)[--(i)]; \ 46 if(U16_IS_TRAIL(c)) { \ 47 uint16_t __c2; \ 48 if((i)>(start) && U16_IS_LEAD(__c2=(s)[(i)-1])) { \ 49 --(i); \ 50 (c)=U16_GET_SUPPLEMENTARY(__c2, (c)); \ 51 } \ 52 } \ 53 } 54 55 #define U16_NEXT(s, i, length, c) { \ 56 (c)=(s)[(i)++]; \ 57 if(U16_IS_LEAD(c)) { \ 58 uint16_t __c2; \ 59 if((i)<(length) && U16_IS_TRAIL(__c2=(s)[(i)])) { \ 60 ++(i); \ 61 (c)=U16_GET_SUPPLEMENTARY((c), __c2); \ 62 } \ 63 } \ 64 } 65 66 #define U_MASK(x) ((uint32_t)1<<(x)) 67 68 #endif 69 70