Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenfold.c
Go to the documentation of this file.
00001 /* 00002 * String folding 00003 * 00004 * Copyright 2003 Jon Griffiths 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00019 */ 00020 00021 #include "wine/unicode.h" 00022 00023 static inline WCHAR to_unicode_digit( WCHAR ch ) 00024 { 00025 extern const WCHAR wine_digitmap[]; 00026 return ch + wine_digitmap[wine_digitmap[ch >> 8] + (ch & 0xff)]; 00027 } 00028 00029 static inline WCHAR to_unicode_native( WCHAR ch ) 00030 { 00031 extern const WCHAR wine_compatmap[]; 00032 return ch + wine_compatmap[wine_compatmap[ch >> 8] + (ch & 0xff)]; 00033 } 00034 00035 static const WCHAR wine_ligatures[] = 00036 { 00037 0x00c6, 0x00de, 0x00df, 0x00e6, 0x00fe, 0x0132, 0x0133, 0x0152, 00038 0x0153, 0x01c4, 0x01c5, 0x01c6, 0x01c7, 0x01c8, 0x01c9, 0x01ca, 00039 0x01cb, 0x01cc, 0x01e2, 0x01e3, 0x01f1, 0x01f2, 0x01f3, 0x01fc, 00040 0x01fd, 0x05f0, 0x05f1, 0x05f2, 0xfb00, 0xfb01, 0xfb02, 0xfb03, 00041 0xfb04, 0xfb05, 0xfb06 00042 }; 00043 00044 /* Unicode expanded ligatures */ 00045 static const WCHAR wine_expanded_ligatures[][4] = 00046 { 00047 { 'A','E','\0',1 }, 00048 { 'T','H','\0',1 }, 00049 { 's','s','\0',1 }, 00050 { 'a','e','\0',1 }, 00051 { 't','h','\0',1 }, 00052 { 'I','J','\0',1 }, 00053 { 'i','j','\0',1 }, 00054 { 'O','E','\0',1 }, 00055 { 'o','e','\0',1 }, 00056 { 'D',0x017d,'\0',1 }, 00057 { 'D',0x017e,'\0',1 }, 00058 { 'd',0x017e,'\0',1 }, 00059 { 'L','J','\0',1 }, 00060 { 'L','j','\0',1 }, 00061 { 'l','j','\0',1 }, 00062 { 'N','J','\0',1 }, 00063 { 'N','j','\0',1 }, 00064 { 'n','j','\0',1 }, 00065 { 0x0100,0x0112,'\0',1 }, 00066 { 0x0101,0x0113,'\0',1 }, 00067 { 'D','Z','\0',1 }, 00068 { 'D','z','\0',1 }, 00069 { 'd','z','\0',1 }, 00070 { 0x00c1,0x00c9,'\0',1 }, 00071 { 0x00e1,0x00e9,'\0',1 }, 00072 { 0x05d5,0x05d5,'\0',1 }, 00073 { 0x05d5,0x05d9,'\0',1 }, 00074 { 0x05d9,0x05d9,'\0',1 }, 00075 { 'f','f','\0',1 }, 00076 { 'f','i','\0',1 }, 00077 { 'f','l','\0',1 }, 00078 { 'f','f','i',2 }, 00079 { 'f','f','l',2 }, 00080 { 0x017f,'t','\0',1 }, 00081 { 's','t','\0',1 } 00082 }; 00083 00084 static inline int get_ligature_len( WCHAR wc ) 00085 { 00086 int low = 0, high = sizeof(wine_ligatures)/sizeof(WCHAR) -1; 00087 while (low <= high) 00088 { 00089 int pos = (low + high) / 2; 00090 if (wine_ligatures[pos] < wc) 00091 low = pos + 1; 00092 else if (wine_ligatures[pos] > wc) 00093 high = pos - 1; 00094 else 00095 return wine_expanded_ligatures[pos][3]; 00096 } 00097 return 0; 00098 } 00099 00100 static inline const WCHAR* get_ligature( WCHAR wc ) 00101 { 00102 static const WCHAR empty_ligature[] = { '\0','\0','\0', 0 }; 00103 int low = 0, high = sizeof(wine_ligatures)/sizeof(WCHAR) -1; 00104 while (low <= high) 00105 { 00106 int pos = (low + high) / 2; 00107 if (wine_ligatures[pos] < wc) 00108 low = pos + 1; 00109 else if (wine_ligatures[pos] > wc) 00110 high = pos - 1; 00111 else 00112 return wine_expanded_ligatures[pos]; 00113 } 00114 return empty_ligature; 00115 } 00116 00117 /* fold a unicode string */ 00118 int wine_fold_string( int flags, const WCHAR *src, int srclen, WCHAR *dst, int dstlen ) 00119 { 00120 WCHAR *dstbase = dst; 00121 const WCHAR *expand; 00122 int i; 00123 00124 if (srclen == -1) 00125 srclen = strlenW(src) + 1; /* Include terminating NUL in count */ 00126 00127 if (!dstlen) 00128 { 00129 /* Calculate the required size for dst */ 00130 dstlen = srclen; 00131 00132 if (flags & MAP_EXPAND_LIGATURES) 00133 { 00134 while (srclen--) 00135 { 00136 dstlen += get_ligature_len(*src); 00137 src++; 00138 } 00139 } 00140 else if (flags & MAP_COMPOSITE) 00141 { 00142 /* FIXME */ 00143 } 00144 else if (flags & MAP_PRECOMPOSED) 00145 { 00146 /* FIXME */ 00147 } 00148 return dstlen; 00149 } 00150 00151 if (srclen > dstlen) 00152 return 0; 00153 00154 dstlen -= srclen; 00155 00156 /* Actually perform the mapping(s) specified */ 00157 for (i = 0; i < srclen; i++) 00158 { 00159 WCHAR ch = *src; 00160 00161 if (flags & MAP_EXPAND_LIGATURES) 00162 { 00163 expand = get_ligature(ch); 00164 if (expand[0]) 00165 { 00166 if (!dstlen--) 00167 return 0; 00168 dst[0] = expand[0]; 00169 if (expand[2]) 00170 { 00171 if (!dstlen--) 00172 return 0; 00173 *++dst = expand[1]; 00174 ch = expand[2]; 00175 } 00176 else 00177 ch = expand[1]; 00178 dst++; 00179 } 00180 } 00181 else if (flags & MAP_COMPOSITE) 00182 { 00183 /* FIXME */ 00184 } 00185 else if (flags & MAP_PRECOMPOSED) 00186 { 00187 /* FIXME */ 00188 } 00189 if (flags & MAP_FOLDDIGITS) 00190 ch = to_unicode_digit(ch); 00191 if (flags & MAP_FOLDCZONE) 00192 ch = to_unicode_native(ch); 00193 00194 *dst++ = ch; 00195 src++; 00196 } 00197 return dst - dstbase; 00198 } Generated on Fri May 25 2012 04:22:33 for ReactOS by
1.7.6.1
|