3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
5 * This file is part of msg-service.
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 * Sangkoo Kim <sangkoo.kim@samsung.com>
9 * Seunghwan Lee <sh.cat.lee@samsung.com>
10 * SoonMin Jung <sm0415.jung@samsung.com>
11 * Jae-Young Lee <jy4710.lee@samsung.com>
12 * KeeBum Kim <keebum.kim@samsung.com>
14 * PROPRIETARY/CONFIDENTIAL
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
32 #include "MmsPluginWmLngPack.h"
36 int __WmLngUTF2Unicode (unsigned short *des,unsigned char *src, int nChar);
39 int __WmLngStrlenByByte(UCHAR *szInText, int byteCount)
42 while (byteCount > 0 && (*szInText != '\0')) {
43 if (*szInText < 0x80) {
46 } else if (((0xC0 <= *szInText) && (*szInText < 0xE0)) && (*(szInText+1) >= 0x80)) {
49 } else if ((*szInText >= 0xE0) && (*(szInText+1) >= 0x80) && (*(szInText+2) >= 0x80)) {
55 MSG_DEBUG("__WmLngStrlenByByte: utf8 incorrect range!\n");
59 return (nCount+1)*sizeof(MCHAR);
63 * This function convert character n'th byte UTF8 character to ProcessCode(unicode)
65 * @param pmszOutText : Output Buffer Pointer to ProcessCode(UniCode)
66 * @param szInText : Input Buffer Pointer to UTF8
67 * @param byteCount : byte number for converting the character
68 * @return : This function returns true on success, or false
71 * @see WmConvertPCode2UTF
73 bool WmConvertUTF2PCode (MCHAR *pmszOutText, int outBufSize, UCHAR *szInText, int byteCount)
77 pmszOutText[0] = NULL;
81 if (__WmConvertCodeBufferSizeCheck((char*)pmszOutText, outBufSize, __WmLngStrlenByByte((UCHAR*)szInText, byteCount)) == false) {
82 MSG_DEBUG("WmConvertUTF2PCode: Out buffer size seems to be small!\n");
86 length = __WmLngUTF2Unicode (pmszOutText, szInText, byteCount);
88 MSG_DEBUG("WmConvertUTF2PCode: __WmLngUTF2Unicode returns false!\n");
97 * change 1byte-encoded-UTF8 character to Unicode
98 * @param byte1 : 1byte character code
99 * @return : result of bit operation
104 unsigned short __WmLngConvert1ByteChar (unsigned char byte1)
106 unsigned short result;
109 result = (byte1 & 0x7F);
115 * change 2byte-encoded-UTF8 character to Unicode
116 * @param byte1 : 1'st byte character code
117 * @param byte2 : 2'st byte character code
118 * @return : result of bit operation
122 unsigned short __WmLngConvert2ByteChar (unsigned char byte1, unsigned char byte2)
124 unsigned short result;
133 result = (hi << 6) | lo;
139 * change 3byte-encoded-UTF8 character to Unicode
140 * @param byte1 : 1'st character code
141 * @param byte2 : 2'st character code
142 * @param byte3 : 3'st character code
143 * @return : result of bit operation
147 unsigned short __WmLngConvert3ByteChar (unsigned char byte1, unsigned char byte2, unsigned char byte3)
149 unsigned short result;
160 result = (hi << 12) | (mid << 6) | lo;
166 * This function convert character UTF8 to ProcessCode(unicode)
168 * @param des : Output Buffer Pointer to ProcessCode(UniCode)
169 * @param src : Input Buffer Pointer to UTF8
170 * @param nChar : number for convert n'th chararcter
171 * @return : This function returns number for convert n'th chararcter on success, or -1
177 int __WmLngUTF2Unicode (unsigned short *des,unsigned char *src, int nChar)
183 while (nChar > 0 && (*src != '\0')) {
185 *des = __WmLngConvert1ByteChar (*src);
190 } else if (((0xC0 <= *src) && (*src < 0xE0)) && (*(src+1) >= 0x80)) {
191 *des = __WmLngConvert2ByteChar (*src, *(src+1));
196 } else if ((*src >= 0xE0) && (*(src+1) >= 0x80) && (*(src+2) >= 0x80)) {
197 *des = __WmLngConvert3ByteChar (*src, *(src+1), *(src+2));
204 *des = __WmLngConvert1ByteChar (*src);
208 MSG_DEBUG("__WmLngUTF2Unicode: utf8 incorrect range!\n");