• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            GBK和BIG5都是雙字節(jié)字符,也就是用兩個位符來表示一個漢字。要判斷是否漢字,就必須知道它的有效范圍,下面是第一個位和第二個位的有效范圍:

            GBK范圍:
            1st byte | 2nd byte
            0×81~0xfe | 0×40~0×7e and 0×80~0xfe
            BIG5范圍:
            1st byte | 2nd byte
            0×81~0xfe | 0×40~0×7e and 0xa1~0xfe
            下面是來自libiconv的關(guān)于GBK(cp936)和BIG5(cp950)的兩段代碼,相信還是相當(dāng)有用的。

            Download: cp936.h
            /* 
            * Copyright (C) 2005 Free Software Foundation, Inc. 
            * This file is part of the GNU LIBICONV Library. 

            * The GNU LIBICONV Library is free software; you can redistribute it 
            * and/or modify it under the terms of the GNU Library General Public 
            * License as published by the Free Software Foundation; either version 2 
            * of the License, or (at your option) any later version. 

            * The GNU LIBICONV Library is distributed in the hope that it will be 
            * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 
            * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
            * Library General Public License for more details. 

            * You should have received a copy of the GNU Library General Public 
            * License along with the GNU LIBICONV Library; see the file COPYING.LIB. 
            * If not, write to the Free Software Foundation, Inc., 51 Franklin Street, 
            * Fifth Floor, Boston, MA 02110-1301, USA. 
            */
             
              
            /* 
            * CP936 
            */
             
              
            /* 
            * The IANA has CP936 as an alias of GBK. But GBK is an official Chinese 
            * specification, whereas CP936 is de-facto maintained by Microsoft. And, 
            * of course, Microsoft modified CP936 since 1999. 

            * The differences from GBK are: 

            * 1. A single character: 

            *    code   CP936.TXT 
            *    0x80   0x20AC # EURO SIGN 

            * Some variants of CP936 (in JDK, Windows-2000, ICU) also add: 

            * 2. Private area mappings: 

            *              code                 Unicode 
            *    0x{A1..A2}{40..7E,80..A0}  U+E4C6..U+E585 
            *    0x{AA..AF,F8..FE}{A1..FE}  U+E000..U+E4C5 

            * We add them too because, although there are backward compatibility problems 
            * when a character from a private area is moved to an official Unicode code 
            * point, they are useful for some people in practice. 
            */
             
              
            static int cp936_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, int n) 

              
            /* Try GBK first. */ 
              

                
            int ret = ces_gbk_mbtowc(conv,pwc,s,n); 
                
            if (ret != RET_ILSEQ) 
                  
            return ret; 
              }
             
              
            /* Then handle the additional mappings. */ 
              

                unsigned 
            char c = *s; 
                
            if (c == 0x80
                  
            *pwc = 0x20ac
                  
            return 1
                }
             
                
            /* User-defined characters */ 
                
            if (c >= 0xa1 && c <= 0xa2
                  
            if (n < 2
                    
            return RET_TOOFEW(0); 
                  

                    unsigned 
            char c2 = s[1]; 
                    
            if ((c2 >= 0x40 && c2 < 0x7f|| (c2 >= 0x80 && c2 < 0xa1)) 
                      
            *pwc = 0xe4c6 + 96 * (c - 0xa1+ (c2 - (c2 >= 0x80 ? 0x41 : 0x40)); 
                      
            return 2
                    }
             
                  }
             
                }
             else if ((c >= 0xaa && c < 0xb0|| (c >= 0xf8 && c < 0xff)) 
                  
            if (n < 2
                    
            return RET_TOOFEW(0); 
                  

                    unsigned 
            char c2 = s[1]; 
                    
            if (c2 >= 0xa1 && c2 < 0xff
                      
            *pwc = 0xe000 + 94 * (c - (c >= 0xf8 ? 0xf2 : 0xaa)) + (c2 - 0xa1); 
                      
            return 2
                    }
             
                  }
             
                }
             
              }
             
              
            return RET_ILSEQ; 
            }
             
              
            static int cp936_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, int n) 

              
            /* Try GBK first. */ 
              

                
            int ret = ces_gbk_wctomb(conv,r,wc,n); 
                
            if (ret != RET_ILUNI) 
                  
            return ret; 
              }
             
              
            /* Then handle the additional mappings. */ 
              
            if (wc >= 0xe000 && wc < 0xe586
                
            /* User-defined characters */ 
                
            if (n < 2
                  
            return RET_TOOFEW(0); 
                
            if (wc < 0xe4c6
                  unsigned 
            int i = wc - 0xe000
                  unsigned 
            int c1 = i / 94
                  unsigned 
            int c2 = i % 94
                  r[
            0= c1 + (c1 < 6 ? 0xaa : 0xf2); 
                  r[
            1= c2 + 0xa1
                  
            return 2
                }
             else 
                  unsigned 
            int i = wc - 0xe4c6
                  unsigned 
            int c1 = i / 96
                  unsigned 
            int c2 = i % 96
                  r[
            0= c1 + 0xa1
                  r[
            1= c2 + (c2 < 0x3f ? 0x40 : 0x41); 
                  
            return 2
                }
             
              }
             else if (wc == 0x20ac
                r[
            0= 0x80
                
            return 1
              }
             
              
            return RET_ILUNI; 
            }


            接下來是BIG5的cp950:

            Download: cp950.h

            /* 
            * Copyright (C) 1999-2001, 2005 Free Software Foundation, Inc. 
            * This file is part of the GNU LIBICONV Library. 

            * The GNU LIBICONV Library is free software; you can redistribute it 
            * and/or modify it under the terms of the GNU Library General Public 
            * License as published by the Free Software Foundation; either version 2 
            * of the License, or (at your option) any later version. 

            * The GNU LIBICONV Library is distributed in the hope that it will be 
            * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 
            * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
            * Library General Public License for more details. 

            * You should have received a copy of the GNU Library General Public 
            * License along with the GNU LIBICONV Library; see the file COPYING.LIB. 
            * If not, write to the Free Software Foundation, Inc., 51 Franklin Street, 
            * Fifth Floor, Boston, MA 02110-1301, USA. 
            */
             
              
            /* 
            * CP950 
            */
             
              
            /* 
            * Microsoft CP950 is a slightly extended and slightly modified version of 
            * BIG5. The differences between the EASTASIA/OTHER/BIG5.TXT and 
            * VENDORS/MICSFT/WINDOWS/CP950.TXT tables found on ftp.unicode.org are 
            * as follows: 

            * 1. Some characters in the BIG5 range are defined differently: 

            *     code   BIG5.TXT                       CP950.TXT 
            *    0xA145  0x2022 # BULLET                0x2027 # HYPHENATION POINT 
            *    0xA14E  0xFF64 # HALFWIDTH IDEOGRAPHIC COMMA 
            *                                           0xFE51 # SMALL IDEOGRAPHIC COMMA 
            *    0xA15A    ---                          0x2574 # BOX DRAWINGS LIGHT LEFT 
            *    0xA1C2  0x203E # OVERLINE              0x00AF # MACRON 
            *    0xA1C3    ---                          0xFFE3 # FULLWIDTH MACRON 
            *    0xA1C5    ---                          0x02CD # MODIFIER LETTER LOW MACRON 
            *    0xA1E3  0x223C # TILDE OPERATOR        0xFF5E # FULLWIDTH TILDE 
            *    0xA1F2  0x2641 # EARTH                 0x2295 # CIRCLED PLUS 
            *    0xA1F3  0x2609 # SUN                   0x2299 # CIRCLED DOT OPERATOR 
            *    0xA1FE    ---                          0xFF0F # FULLWIDTH SOLIDUS 
            *    0xA240    ---                          0xFF3C # FULLWIDTH REVERSE SOLIDUS 
            *    0xA241  0xFF0F # FULLWIDTH SOLIDUS     0x2215 # DIVISION SLASH 
            *    0xA242  0xFF3C # FULLWIDTH REVERSE SOLIDUS 
            *                                           0xFE68 # SMALL REVERSE SOLIDUS 
            *    0xA244  0x00A5 # YEN SIGN              0xFFE5 # FULLWIDTH YEN SIGN 
            *    0xA246  0x00A2 # CENT SIGN             0xFFE0 # FULLWIDTH CENT SIGN 
            *    0xA247  0x00A3 # POUND SIGN            0xFFE1 # FULLWIDTH POUND SIGN 
            *    0xA2CC    ---                          0x5341 
            *    0xA2CE    ---                          0x5345 

            * 2. A small new row. See cp950ext.h. 

            * 3. CP950.TXT is lacking the range 0xC6A1..0xC7FC (Hiragana, Katakana, 
            *    Cyrillic, circled digits, parenthesized digits). 

            *    We implement this omission, because said range is marked "uncertain" 
            *    in the unicode.org BIG5 table. 

            * The table found on Microsoft's website furthermore adds: 

            * 4. A single character: 

            *     code   CP950.TXT 
            *    0xA3E1  0x20AC # EURO SIGN 

            * Many variants of BIG5 or CP950 (in JDK, Solaris, OSF/1, Windows-2000, ICU, 
            * as well as our BIG5-2003 converter) also add: 

            * 5. Private area mappings: 

            *              code                 Unicode 
            *    0x{81..8D}{40..7E,A1..FE}  U+EEB8..U+F6B0 
            *    0x{8E..A0}{40..7E,A1..FE}  U+E311..U+EEB7 
            *    0x{FA..FE}{40..7E,A1..FE}  U+E000..U+E310 

            * We add them too because, although there are backward compatibility problems 
            * when a character from a private area is moved to an official Unicode code 
            * point, they are useful for some people in practice. 
            */
             
              
            static const unsigned short cp950_2uni_pagea1[314= 
              
            /* 0xa1 */ 
              
            0x30000xff0c0x30010x30020xff0e0x20270xff1b0xff1a
              
            0xff1f0xff010xfe300x20260x20250xfe500xfe510xfe52
              
            0x00b70xfe540xfe550xfe560xfe570xff5c0x20130xfe31
              
            0x20140xfe330x25740xfe340xfe4f0xff080xff090xfe35
              
            0xfe360xff5b0xff5d0xfe370xfe380x30140x30150xfe39
              
            0xfe3a0x30100x30110xfe3b0xfe3c0x300a0x300b0xfe3d
              
            0xfe3e0x30080x30090xfe3f0xfe400x300c0x300d0xfe41
              
            0xfe420x300e0x300f0xfe430xfe440xfe590xfe5a0xfe5b
              
            0xfe5c0xfe5d0xfe5e0x20180x20190x201c0x201d0x301d
              
            0x301e0x20350x20320xff030xff060xff0a0x203b0x00a7
              
            0x30030x25cb0x25cf0x25b30x25b20x25ce0x26060x2605
              
            0x25c70x25c60x25a10x25a00x25bd0x25bc0x32a30x2105
              
            0x00af0xffe30xff3f0x02cd0xfe490xfe4a0xfe4d0xfe4e
              
            0xfe4b0xfe4c0xfe5f0xfe600xfe610xff0b0xff0d0x00d7
              
            0x00f70x00b10x221a0xff1c0xff1e0xff1d0x22660x2267
              
            0x22600x221e0x22520x22610xfe620xfe630xfe640xfe65
              
            0xfe660xff5e0x22290x222a0x22a50x22200x221f0x22bf
              
            0x33d20x33d10x222b0x222e0x22350x22340x26400x2642
              
            0x22950x22990x21910x21930x21900x21920x21960x2197
              
            0x21990x21980x22250x22230xff0f
              
            /* 0xa2 */ 
              
            0xff3c0x22150xfe680xff040xffe50x30120xffe00xffe1
              
            0xff050xff200x21030x21090xfe690xfe6a0xfe6b0x33d5
              
            0x339c0x339d0x339e0x33ce0x33a10x338e0x338f0x33c4
              
            0x00b00x51590x515b0x515e0x515d0x51610x51630x55e7
              
            0x74e90x7cce0x25810x25820x25830x25840x25850x2586
              
            0x25870x25880x258f0x258e0x258d0x258c0x258b0x258a
              
            0x25890x253c0x25340x252c0x25240x251c0x25940x2500
              
            0x25020x25950x250c0x25100x25140x25180x256d0x256e
              
            0x25700x256f0x25500x255e0x256a0x25610x25e20x25e3
              
            0x25e50x25e40x25710x25720x25730xff100xff110xff12
              
            0xff130xff140xff150xff160xff170xff180xff190x2160
              
            0x21610x21620x21630x21640x21650x21660x21670x2168
              
            0x21690x30210x30220x30230x30240x30250x30260x3027
              
            0x30280x30290x53410x53440x53450xff210xff220xff23
              
            0xff240xff250xff260xff270xff280xff290xff2a0xff2b
              
            0xff2c0xff2d0xff2e0xff2f0xff300xff310xff320xff33
              
            0xff340xff350xff360xff370xff380xff390xff3a0xff41
              
            0xff420xff430xff440xff450xff460xff470xff480xff49
              
            0xff4a0xff4b0xff4c0xff4d0xff4e0xff4f0xff500xff51
              
            0xff520xff530xff540xff550xff56
            }

              
            #include 
            "cp950ext.h" 
              
            static int cp950_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, int n) 

              unsigned 
            char c = *s; 
              
            /* Code set 0 (ASCII) */ 
              
            if (c < 0x80
                
            return ascii_mbtowc(conv,pwc,s,n); 
              
            /* Code set 1 (BIG5 extended) */ 
              
            if (c >= 0x81 && c < 0xff
                
            if (n < 2
                  
            return RET_TOOFEW(0); 
                

                  unsigned 
            char c2 = s[1]; 
                  
            if ((c2 >= 0x40 && c2 < 0x7f|| (c2 >= 0xa1 && c2 < 0xff)) 
                    
            if (c >= 0xa1
                      
            if (c < 0xa3
                        unsigned 
            int i = 157 * (c - 0xa1+ (c2 - (c2 >= 0xa1 ? 0x62 : 0x40)); 
                        unsigned 
            short wc = cp950_2uni_pagea1[i]; 
                        
            if (wc != 0xfffd
                          
            *pwc = (ucs4_t) wc; 
                          
            return 2
                        }
             
                      }
             
                      
            if (!((c == 0xc6 && c2 >= 0xa1|| c == 0xc7)) 
                        
            int ret = big5_mbtowc(conv,pwc,s,2); 
                        
            if (ret != RET_ILSEQ) 
                          
            return ret; 
                      }
             
                      
            if (c == 0xa3 && c2 == 0xe1
                        
            *pwc = 0x20ac
                        
            return 2
                      }
             
                      
            if (c >= 0xfa
                        
            /* User-defined characters */ 
                        
            *pwc = 0xe000 + 157 * (c - 0xfa+ (c2 - (c2 >= 0xa1 ? 0x62 : 0x40)); 
                        
            return 2
                      }
             
                    }
             else 
                      
            /* 0x81 <= c < 0xa1. */ 
                      
            /* User-defined characters */ 
                      
            *pwc = (c >= 0x8e ? 0xdb18 : 0xeeb8+ 157 * (c - 0x81
                             
            + (c2 - (c2 >= 0xa1 ? 0x62 : 0x40)); 
                      
            return 2
                    }
             
                  }
             
                }
             
                
            if (c == 0xf9
                  
            int ret = cp950ext_mbtowc(conv,pwc,s,2); 
                  
            if (ret != RET_ILSEQ) 
                    
            return ret; 
                }
             
              }
             
              
            return RET_ILSEQ; 
            }
             
              
            static int cp950_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, int n) 

              unsigned 
            char buf[2]; 
              
            int ret; 
              
              
            /* Code set 0 (ASCII) */ 
              ret 
            = ascii_wctomb(conv,r,wc,n); 
              
            if (ret != RET_ILUNI) 
                
            return ret; 
              
              
            /* Code set 1 (BIG5 extended) */ 
              
            switch (wc >> 8
                
            case 0x00
                  
            if (wc == 0x00af{ buf[0= 0xa1; buf[1= 0xc2; ret = 2break; } 
                  
            if (wc == 0x00a2 || wc == 0x00a3 || wc == 0x00a4
                    
            return RET_ILUNI; 
                  
            break
                
            case 0x02
                  
            if (wc == 0x02cd{ buf[0= 0xa1; buf[1= 0xc5; ret = 2break; } 
                  
            break
                
            case 0x20
                  
            if (wc == 0x2027{ buf[0= 0xa1; buf[1= 0x45; ret = 2break; } 
                  
            if (wc == 0x20ac{ buf[0= 0xa3; buf[1= 0xe1; ret = 2break; } 
                  
            if (wc == 0x2022 || wc == 0x203e
                    
            return RET_ILUNI; 
                  
            break
                
            case 0x22
                  
            if (wc == 0x2215{ buf[0= 0xa2; buf[1= 0x41; ret = 2break; } 
                  
            if (wc == 0x2295{ buf[0= 0xa1; buf[1= 0xf2; ret = 2break; } 
                  
            if (wc == 0x2299{ buf[0= 0xa1; buf[1= 0xf3; ret = 2break; } 
                  
            if (wc == 0x223c
                    
            return RET_ILUNI; 
                  
            break
                
            case 0x25
                  
            if (wc == 0x2574{ buf[0= 0xa1; buf[1= 0x5a; ret = 2break; } 
                  
            break
                
            case 0x26
                  
            if (wc == 0x2609 || wc == 0x2641
                    
            return RET_ILUNI; 
                  
            break
                
            case 0xe0case 0xe1case 0xe2case 0xe3case 0xe4case 0xe5
                
            case 0xe6case 0xe7case 0xe8case 0xe9case 0xeacase 0xeb
                
            case 0xeccase 0xedcase 0xeecase 0xefcase 0xf0case 0xf1
                
            case 0xf2case 0xf3case 0xf4case 0xf5case 0xf6
                  

                    
            /* User-defined characters */ 
                    unsigned 
            int i = wc - 0xe000
                    
            if (i < 5809
                      unsigned 
            int c1 = i / 157
                      unsigned 
            int c2 = i % 157
                      buf[
            0= c1 + (c1 < 5 ? 0xfa : c1 < 24 ? 0x89 : 0x69); 
                      buf[
            1= c2 + (c2 < 0x3f ? 0x40 : 0x62); 
                      ret 
            = 2
                      
            break
                    }
             
                  }
             
                  
            break
                
            case 0xfe
                  
            if (wc == 0xfe51{ buf[0= 0xa1; buf[1= 0x4e; ret = 2break; } 
                  
            if (wc == 0xfe68{ buf[0= 0xa2; buf[1= 0x42; ret = 2break; } 
                  
            break
                
            case 0xff
                  
            if (wc == 0xff0f{ buf[0= 0xa1; buf[1= 0xfe; ret = 2break; } 
                  
            if (wc == 0xff3c{ buf[0= 0xa2; buf[1= 0x40; ret = 2break; } 
                  
            if (wc == 0xff5e{ buf[0= 0xa1; buf[1= 0xe3; ret = 2break; } 
                  
            if (wc == 0xffe0{ buf[0= 0xa2; buf[1= 0x46; ret = 2break; } 
                  
            if (wc == 0xffe1{ buf[0= 0xa2; buf[1= 0x47; ret = 2break; } 
                  
            if (wc == 0xffe3{ buf[0= 0xa1; buf[1= 0xc3; ret = 2break; } 
                  
            if (wc == 0xffe5{ buf[0= 0xa2; buf[1= 0x44; ret = 2break; } 
                  
            if (wc == 0xff64
                    
            return RET_ILUNI; 
                  
            break
              }
             
              
            if (ret == RET_ILUNI) 
                ret 
            = big5_wctomb(conv,buf,wc,2); 
              
            if (ret != RET_ILUNI) 
                
            if (ret != 2) abort(); 
                
            if (!((buf[0== 0xc6 && buf[1>= 0xa1|| buf[0== 0xc7)) 
                  
            if (n < 2
                    
            return RET_TOOSMALL; 
                  r[
            0= buf[0]; 
                  r[
            1= buf[1]; 
                  
            return 2
                }
             
              }
             
              ret 
            = cp950ext_wctomb(conv,buf,wc,2); 
              
            if (ret != RET_ILUNI) 
                
            if (ret != 2) abort(); 
                
            if (n < 2
                  
            return RET_TOOSMALL; 
                r[
            0= buf[0]; 
                r[
            1= buf[1]; 
                
            return 2
              }
             
              
              
            return RET_ILUNI; 
            }
            国产亚洲精久久久久久无码| 狠狠色婷婷综合天天久久丁香| 国产精品美女久久福利网站| 久久婷婷五月综合97色直播| 久久影院亚洲一区| 亚洲婷婷国产精品电影人久久| 久久免费看黄a级毛片| 久久久老熟女一区二区三区| 国产精品久久久亚洲| 色综合合久久天天综合绕视看 | 嫩草伊人久久精品少妇AV| 日产精品99久久久久久| 粉嫩小泬无遮挡久久久久久| 久久精品国产99国产精偷| 国产三级精品久久| 2021国内久久精品| 久久精品99久久香蕉国产色戒 | 亚洲成色999久久网站| 久久综合狠狠综合久久激情 | 久久人妻少妇嫩草AV蜜桃| 精品久久亚洲中文无码| 996久久国产精品线观看| 久久国产成人午夜AV影院| 伊人久久大香线蕉综合5g| 欧洲精品久久久av无码电影| 日本道色综合久久影院| 久久人人爽人人爽人人爽| 国产精品久久亚洲不卡动漫| 欧美激情精品久久久久久久| 久久久亚洲欧洲日产国码aⅴ| 国产L精品国产亚洲区久久| 国产精品美女久久福利网站| 久久精品国产精品亚洲精品| 亚洲AⅤ优女AV综合久久久| 久久99精品久久久久久久久久| 久久亚洲欧洲国产综合| 久久国产精品99精品国产| 日韩精品无码久久一区二区三| 99精品久久精品一区二区| 欧美精品九九99久久在观看| 久久最近最新中文字幕大全|