utf8internal.h

Go to the documentation of this file.
00001 /*
00002  * This file is part of the Sofia-SIP package
00003  *
00004  * Copyright (C) 2005 Nokia Corporation.
00005  *
00006  * Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation; either version 2.1 of
00011  * the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00021  * 02110-1301 USA
00022  *
00023  */
00024 
00025 #ifndef UTF8INTERNAL_H
00026 #define UTF8INTERNAL_H 
00027 
00036 #define UTF8_ANALYZE(s, ascii, latin1, ucs2, ucs4, errors) \
00037 do {  \
00038   if (s) while (*s) { \
00039     utf8 c = *s++; \
00040     if (IS_UTF8_1(c)) \
00041       ascii++; \
00042     else if (IS_UTF8_I(c)) { \
00043       if (IS_UTF8_X(s[0])) \
00044         latin1++, s++; \
00045       else \
00046         errors++; \
00047     } \
00048     else if (IS_UTF8_2(c)) { \
00049       if (IS_UTF8_X(s[0])) \
00050         ucs2++, s++; \
00051       else \
00052         errors++; \
00053     } \
00054     else if (IS_UTF8_3(c)) { \
00055       if (IS_UTF8_X(s[0]) && IS_UTF8_X(s[1])) \
00056         ucs2++, s++, s++; \
00057       else \
00058         errors++; \
00059     } \
00060     else if (IS_UTF8_4(c)) { \
00061       if (IS_UTF8_X(s[0]) && IS_UTF8_X(s[1]) && IS_UTF8_X(s[2])) \
00062         ucs4++, s++, s++, s++; \
00063       else \
00064         errors++; \
00065     } \
00066     else if (IS_UTF8_5(c)) { \
00067       if (IS_UTF8_X(s[0]) && IS_UTF8_X(s[1]) &&  \
00068           IS_UTF8_X(s[2]) && IS_UTF8_X(s[3])) \
00069         ucs4++, s++, s++, s++, s++; \
00070       else \
00071         errors++; \
00072     } \
00073     else if (IS_UTF8_6(c)) { \
00074       if (IS_UTF8_X(s[0]) && IS_UTF8_X(s[1]) &&  \
00075           IS_UTF8_X(s[2]) && IS_UTF8_X(s[3]) && IS_UTF8_X(s[4])) \
00076         ucs4++, s++, s++, s++, s++, s++; \
00077       else \
00078         errors++; \
00079     } \
00080     else \
00081         errors++; \
00082   } \
00083 } while(0)
00084 
00085 #endif /* UTF8INTERNAL_H */

Sofia-SIP 1.12.4 - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.