1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright (c) 1996 by Sun Microsystems, Inc. 23 */ 24 25 26 #include "common_def.h" 27 #include "common_han.h" 28 #include "common_utf.h" 29 30 /**** _ U T F 8 _ T O _ J O H A P 8 2 ****/ 31 32 hcode_type _utf8_to_johap82(hcode_type utfcode) 33 { 34 /* Only for Hangul character */ 35 hcode_type johap, unicode; 36 37 unicode = _utf8_to_uni(utfcode); 38 39 if ((UNICODE_HANGUL_START <= unicode.code) && 40 (unicode.code <= UNICODE_HANGUL_END)) { 41 /* Hangul Area */ 42 unsigned int uni, x, y, z; 43 44 uni = unicode.code - 0xAC00; 45 x = uni / 588; 46 /* 588 = 21(Joongsung Number) * 28(Jongsung Number) */ 47 y = (uni % 588) / 28; 48 z = (uni % 588) % 28; 49 50 johap.code = 0; 51 johap.johap.msb = 1; 52 johap.johap.chosung = x + 0x0A; 53 johap.johap.joongsung = 54 y == 0x14 ? y + 9 : 55 y > 0x10 ? y + 8 : 56 y > 0x0D ? y + 7 : 57 y > 0x0A ? y + 6 : 58 y > 0x07 ? y + 5 : 59 y > 0x04 ? y + 4 : 60 y > 0x01 ? y + 3 : y + 2; 61 johap.johap.jongsung = z + 1; 62 63 return(johap); 64 65 } else { 66 johap.code = NON_ID_CHAR; /* initial & default set to fail value */ 67 68 return(johap); 69 } 70 71 72 } /* end of hcode_type _utf8_to_johap82(hcode_type utfcode) */ 73