1/* 2 * Copyright (C) 2008,2009 OMRON SOFTWARE Co., Ltd. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#include "nj_lib.h" 18#include "nj_ext.h" 19 20 21#define HIRA_KATA_OFFSET (0x0060) 22 23#define ZEN_CHAR_LEN 1 24 25#define CHAR_TO_WCHAR(s) \ 26 ((NJ_UINT16)( (((NJ_UINT8*)(s))[0] << 8) | ((NJ_UINT8*)(s))[1] )) 27 28#define SET_WCHAR_TO_CHAR(s, c) \ 29 { \ 30 ((NJ_UINT8*)(s))[0] = (NJ_UINT8)(((c) >> 8) & 0x00ff); \ 31 ((NJ_UINT8*)(s))[1] = (NJ_UINT8)(((c)) & 0x00ff); \ 32 } 33 34#define IS_HIRAGANA_WCHAR(c) ( ((c) >= 0x3041) && ((c) <= 0x3093) ) 35 36 37 38 39NJ_INT16 nje_convert_hira_to_kata(NJ_CHAR *hira, NJ_CHAR *kata, NJ_UINT16 len) 40{ 41 NJ_UINT16 pnt; 42 NJ_UINT16 wchar; 43 44 45 pnt = 0; 46 while (pnt < len) { 47 if (*hira == NJ_CHAR_NUL) { 48 49 return pnt; 50 } 51 52 53 wchar = CHAR_TO_WCHAR(hira); 54 hira++; 55 pnt++; 56 57 if (IS_HIRAGANA_WCHAR(wchar)) { 58 59 SET_WCHAR_TO_CHAR(kata, wchar + HIRA_KATA_OFFSET); 60 kata += ZEN_CHAR_LEN; 61 } else { 62 SET_WCHAR_TO_CHAR(kata, wchar); 63 kata += ZEN_CHAR_LEN; 64 } 65 } 66 67 68 *kata = NJ_CHAR_NUL; 69 return pnt; 70} 71