Back to index

im-sdk  12.3.91
neima_encode.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include "ime.h"
00003 
00004 int is_valid_code(int encode, unsigned char *int_code, int code_len)
00005 {
00006        unsigned char code0, code1, code2, code3;
00007        
00008        code0 = int_code[0];
00009        code1 = int_code[1];
00010 
00011        switch (encode) {
00012               case ENCODE_GB2312:
00013                      if (code0 < 0xA1 || code0 > 0xFE)
00014                             return (-1);
00015                      if (code1 < 0xA1 || code1 > 0xFE)
00016                             return (-1);
00017                      break;
00018                      
00019               case ENCODE_GBK:
00020                      if (code0 < 0x81 || code0 > 0xFE)
00021                             return (-1);
00022                      if (code1 < 0x40 || code1 > 0xFE || code1 == 0x7F)
00023                             return (-1);
00024                      break;
00025 
00026               case ENCODE_GB18030:
00027                      if (code_len == 2) {
00028                             if (code0 < 0x81 || code0 > 0xFE)
00029                                    return (-1);
00030                             if (code1 < 0x40 || code1 > 0xFE || code1 == 0x7F)
00031                                    return (-1);
00032                      } else if (code_len == 4) {
00033                             code2 = int_code[2];
00034                             code3 = int_code[3];
00035                             if (code0 < 0x81 || code0 > 0xFE)
00036                                    return (-1);
00037                             if (code1 < 0x30 || code1 > 0x39)
00038                                    return (-1);
00039                             if (code2 < 0x81 || code2 > 0xFE)
00040                                    return (-1);
00041                             if (code3 < 0x30 || code3 > 0x39)
00042                                    return (-1);
00043                      }
00044                      break;
00045 
00046               case ENCODE_BIG5:
00047                      if (code0 < 0xA1 || code0 > 0xFE)
00048                             return (-1);
00049                      if (code1 < 0x40 || code1 > 0xFE)
00050                             return (-1);
00051                      if (code1 > 0x7E && code1 < 0xA1)
00052                             return (-1);
00053                      break;
00054 
00055               case ENCODE_EUCTW:
00056                      if (code_len == 2) {
00057                             if (code0 < 0x80 || code1 <0x80)
00058                                    return (-1);
00059                      } if (code_len == 4) {
00060                             code2 = int_code[2];
00061                             code3 = int_code[3];
00062                             if (code0 != 0x8E)
00063                                    return(-1);
00064                             if (code1 < 0x80 || code2 < 0x80 || code3 < 0x80)
00065                                    return(-1);
00066                      }
00067                      break;
00068 
00069               case ENCODE_BIG5HKSCS:
00070                      if (code0 < 0x81 || code0 > 0xFE)
00071                             return (-1);
00072                      if (code1 < 0x40 || code1 > 0xFE)
00073                             return (-1);
00074                      break;
00075 
00076               case ENCODE_UTF8:
00077                      break;
00078        }
00079        return(0);
00080 }