📄 gb2312.h
字号:
/* * Copyright (C) 1999-2001 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., 59 Temple Place - * Suite 330, Boston, MA 02111-1307, USA. *//* * GB2312.1980-0 */#include "conv.h"#ifndef _ICONV_GB2312#define _ICONV_GB2312//#pragma pcrelconstdata onstatic int gb2312_mbtowc (conv_t conv, gb2312_table &table, UInt32 *pwc, const unsigned char *s, int n){ unsigned char c1 = s[0]; if ((c1 >= 0x21 && c1 <= 0x29) || (c1 >= 0x30 && c1 <= 0x77)) { if (n >= 2) { unsigned char c2 = s[1]; if (c2 >= 0x21 && c2 < 0x7f) { unsigned int i = 94 * (c1 - 0x21) + (c2 - 0x21); unsigned short wc = 0xfffd; if (i < 1410) { if (i < 831) wc = table.gb2312_2uni_page21[i]; } else { if (i < 8178) wc = table.gb2312_2uni_page30[i-1410]; } if (wc != 0xfffd) { *pwc = (UInt32) wc; return 2; } } return RET_ILSEQ; } return RET_TOOFEW(0); } return RET_ILSEQ;}static int gb2312_wctomb (conv_t conv, gb2312_table &table, unsigned char *r, UInt32 wc, int n){ if (n >= 2) { const Summary16 *summary = NULL; if (wc >= 0x0000 && wc < 0x0460) summary = &table.gb2312_uni2indx_page00[(wc>>4)]; else if (wc >= 0x2000 && wc < 0x2650) summary = &table.gb2312_uni2indx_page20[(wc>>4)-0x200]; else if (wc >= 0x3000 && wc < 0x3230) summary = &table.gb2312_uni2indx_page30[(wc>>4)-0x300]; else if (wc >= 0x4e00 && wc < 0x9cf0) summary = &table.gb2312_uni2indx_page4e[(wc>>4)-0x4e0]; else if (wc >= 0x9e00 && wc < 0x9fb0) summary = &table.gb2312_uni2indx_page9e[(wc>>4)-0x9e0]; else if (wc >= 0xff00 && wc < 0xfff0) summary = &table.gb2312_uni2indx_pageff[(wc>>4)-0xff0]; if (summary) { unsigned short used = summary->used; unsigned int i = wc & 0x0f; if (used & ((unsigned short) 1 << i)) { unsigned short c; /* Keep in `used' only the bits 0..i-1. */ used &= ((unsigned short) 1 << i) - 1; /* Add `summary->indx' and the number of bits set in `used'. */ used = (used & 0x5555) + ((used & 0xaaaa) >> 1); used = (used & 0x3333) + ((used & 0xcccc) >> 2); used = (used & 0x0f0f) + ((used & 0xf0f0) >> 4); used = (used & 0x00ff) + (used >> 8); c = table.gb2312_2charset[summary->indx + used]; r[0] = (c >> 8); r[1] = (c & 0xff); return 2; } } return RET_ILUNI; } return RET_TOOSMALL;}//#pragma pcrelconstdata off#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -