2001-05-23 15:26:42 +02:00
|
|
|
/*
|
|
|
|
* PROGRAM: InterBase International support
|
2003-12-11 11:33:30 +01:00
|
|
|
* MODULE: lc_jis.cpp
|
2001-05-23 15:26:42 +02:00
|
|
|
* DESCRIPTION: Language Drivers in the JIS family.
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Interbase Public
|
|
|
|
* License Version 1.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy
|
|
|
|
* of the License at http://www.Inprise.com/IPL.html
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an
|
|
|
|
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
|
|
|
|
* or implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Inprise Corporation
|
|
|
|
* and its predecessors. Portions created by Inprise Corporation are
|
|
|
|
* Copyright (C) Inprise Corporation.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
|
|
|
*/
|
|
|
|
|
2003-02-17 11:37:42 +01:00
|
|
|
#include "firebird.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
#include "../intl/ldcommon.h"
|
2002-04-10 01:25:13 +02:00
|
|
|
#include "../intl/kanji.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-02-20 16:47:23 +01:00
|
|
|
#include "lc_ascii.h"
|
|
|
|
#include "cv_jis.h"
|
2003-09-21 01:33:36 +02:00
|
|
|
#include "ld_proto.h"
|
2003-02-20 16:47:23 +01:00
|
|
|
|
2003-08-21 18:22:11 +02:00
|
|
|
static USHORT sjis_to_upper(TEXTTYPE obj, UCS2_CHAR ch);
|
|
|
|
static USHORT sjis_to_lower(TEXTTYPE obj, UCS2_CHAR ch);
|
2003-12-31 06:36:12 +01:00
|
|
|
static SSHORT sjis_str_to_upper(TEXTTYPE obj, USHORT iLen, const BYTE* pStr, USHORT iOutLen, BYTE *pOutStr);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-09-19 00:06:59 +02:00
|
|
|
static inline void FAMILY_MULTIBYTE(TEXTTYPE cache,
|
|
|
|
TTYPE_ID id_number,
|
|
|
|
pfn_INTL_init name,
|
|
|
|
CHARSET_ID charset,
|
|
|
|
SSHORT country,
|
2004-03-11 06:04:26 +01:00
|
|
|
const ASCII* POSIX)
|
2003-09-19 00:06:59 +02:00
|
|
|
//#define FAMILY_MULTIBYTE(id_number, name, charset, country)
|
|
|
|
{
|
|
|
|
cache->texttype_version = IB_LANGDRV_VERSION;
|
|
|
|
cache->texttype_type = id_number;
|
|
|
|
cache->texttype_character_set = charset;
|
|
|
|
cache->texttype_country = country;
|
|
|
|
cache->texttype_bytes_per_char = 2;
|
2004-03-07 08:58:55 +01:00
|
|
|
cache->texttype_fn_init = name;
|
|
|
|
cache->texttype_fn_key_length = famasc_key_length;
|
|
|
|
cache->texttype_fn_string_to_key= famasc_string_to_key;
|
|
|
|
cache->texttype_fn_compare = famasc_compare;
|
2003-09-19 00:06:59 +02:00
|
|
|
cache->texttype_collation_table = NULL;
|
|
|
|
cache->texttype_toupper_table = NULL;
|
|
|
|
cache->texttype_tolower_table = NULL;
|
|
|
|
cache->texttype_compress_table = NULL;
|
|
|
|
cache->texttype_expand_table = NULL;
|
|
|
|
cache->texttype_name = POSIX;
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
TEXTTYPE_ENTRY(JIS220_init)
|
|
|
|
{
|
2003-02-13 10:58:19 +01:00
|
|
|
static const ASCII POSIX[] = "C.SJIS";
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-09-19 00:06:59 +02:00
|
|
|
FAMILY_MULTIBYTE(cache, 220, JIS220_init, CS_SJIS, CC_C, POSIX);
|
2004-03-07 08:58:55 +01:00
|
|
|
cache->texttype_fn_to_wc = CVJIS_sjis_byte2short;
|
|
|
|
cache->texttype_fn_mbtowc = CVJIS_sjis_mbtowc;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-03-07 08:58:55 +01:00
|
|
|
cache->texttype_fn_to_upper = reinterpret_cast<pfn_INTL_ch_case>(sjis_to_upper);
|
|
|
|
cache->texttype_fn_to_lower = reinterpret_cast<pfn_INTL_ch_case>(sjis_to_lower);
|
|
|
|
cache->texttype_fn_str_to_upper = sjis_str_to_upper;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
TEXTTYPE_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEXTTYPE_ENTRY(JIS230_init)
|
|
|
|
{
|
2003-02-13 10:58:19 +01:00
|
|
|
static const ASCII POSIX[] = "C.EUC_J";
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-09-19 00:06:59 +02:00
|
|
|
FAMILY_MULTIBYTE(cache, 230, JIS230_init, CS_EUCJ, CC_C, POSIX);
|
2004-03-07 08:58:55 +01:00
|
|
|
cache->texttype_fn_to_wc = CVJIS_euc_byte2short;
|
|
|
|
cache->texttype_fn_mbtowc = CVJIS_euc_mbtowc;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-03-07 08:58:55 +01:00
|
|
|
cache->texttype_fn_to_upper = famasc_to_upper;
|
|
|
|
cache->texttype_fn_to_lower = famasc_to_lower;
|
|
|
|
cache->texttype_fn_str_to_upper = famasc_str_to_upper;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
TEXTTYPE_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: This function expects Wide-Char input, not
|
|
|
|
* Multibyte input
|
|
|
|
*/
|
2003-08-21 18:22:11 +02:00
|
|
|
static USHORT sjis_to_upper(TEXTTYPE obj, UCS2_CHAR ch)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2003-02-18 06:24:35 +01:00
|
|
|
if (ch >= (UCS2_CHAR) ASCII_LOWER_A && ch <= (UCS2_CHAR) ASCII_LOWER_Z)
|
|
|
|
return (ch - (UCS2_CHAR) ASCII_LOWER_A + (UCS2_CHAR) ASCII_UPPER_A);
|
2001-05-23 15:26:42 +02:00
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns -1 if output buffer was too small
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Note: This function expects Multibyte input
|
|
|
|
*/
|
2003-12-31 06:36:12 +01:00
|
|
|
static SSHORT sjis_str_to_upper(TEXTTYPE obj, USHORT iLen, const BYTE* pStr, USHORT iOutLen, BYTE *pOutStr)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2003-12-31 06:36:12 +01:00
|
|
|
bool waiting_for_sjis2 = false;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-04 00:59:24 +01:00
|
|
|
fb_assert(pStr != NULL);
|
|
|
|
fb_assert(pOutStr != NULL);
|
|
|
|
fb_assert(iLen <= 32000); /* almost certainly an error */
|
|
|
|
fb_assert(iOutLen <= 32000); /* almost certainly an error */
|
|
|
|
fb_assert(iOutLen >= iLen);
|
2003-12-31 06:36:12 +01:00
|
|
|
const BYTE* const p = pOutStr;
|
2001-05-23 15:26:42 +02:00
|
|
|
while (iLen && iOutLen) {
|
2003-12-31 06:36:12 +01:00
|
|
|
BYTE c = *pStr++;
|
2001-05-23 15:26:42 +02:00
|
|
|
if (waiting_for_sjis2 || SJIS1(c)) {
|
|
|
|
waiting_for_sjis2 = !waiting_for_sjis2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (c >= ASCII_LOWER_A && c <= ASCII_LOWER_Z)
|
|
|
|
c = (c - ASCII_LOWER_A + ASCII_UPPER_A);
|
|
|
|
}
|
|
|
|
*pOutStr++ = c;
|
|
|
|
iLen--;
|
|
|
|
iOutLen--;
|
|
|
|
}
|
|
|
|
if (iLen != 0)
|
|
|
|
return (-1); /* Must have ran out of output space */
|
|
|
|
return (pOutStr - p);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: This function expects Wide-Char input, not
|
|
|
|
* Multibyte input
|
|
|
|
*/
|
2003-08-21 18:22:11 +02:00
|
|
|
static USHORT sjis_to_lower(TEXTTYPE obj, UCS2_CHAR ch)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2003-02-18 06:24:35 +01:00
|
|
|
if (ch >= (UCS2_CHAR) ASCII_UPPER_A && ch <= (UCS2_CHAR) ASCII_UPPER_Z)
|
|
|
|
return (ch - (UCS2_CHAR) ASCII_UPPER_A + (UCS2_CHAR) ASCII_LOWER_A);
|
2001-05-23 15:26:42 +02:00
|
|
|
return ch;
|
|
|
|
}
|
2003-12-11 11:33:30 +01:00
|
|
|
|