8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-31 19:23:03 +01:00
firebird-mirror/src/intl/lc_jis.cpp

154 lines
4.2 KiB
C++
Raw Normal View History

2001-05-23 15:26:42 +02:00
/*
* PROGRAM: InterBase International support
* 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"
#include "../intl/kanji.h"
2001-05-23 15:26:42 +02:00
#include "lc_ascii.h"
#include "cv_jis.h"
2003-09-21 01:33:36 +02:00
#include "ld_proto.h"
//static ULONG sjis_str_to_upper(texttype* obj, ULONG iLen, const BYTE* pStr, ULONG iOutLen, BYTE *pOutStr);
//static ULONG sjis_str_to_lower(texttype* obj, ULONG iLen, const BYTE* pStr, ULONG iOutLen, BYTE *pOutStr);
2005-05-28 00:45:31 +02:00
static inline bool FAMILY_MULTIBYTE(texttype* cache,
2003-09-19 00:06:59 +02:00
SSHORT country,
2005-05-28 00:45:31 +02:00
const ASCII* POSIX,
USHORT attributes,
const UCHAR* specific_attributes,
ULONG specific_attributes_length)
2003-09-19 00:06:59 +02:00
//#define FAMILY_MULTIBYTE(id_number, name, charset, country)
{
2005-05-28 00:45:31 +02:00
if ((attributes & ~TEXTTYPE_ATTR_PAD_SPACE) || specific_attributes_length)
return false;
cache->texttype_version = TEXTTYPE_VERSION_1;
cache->texttype_name = POSIX;
2003-09-19 00:06:59 +02:00
cache->texttype_country = country;
2005-05-28 00:45:31 +02:00
cache->texttype_pad_option = (attributes & TEXTTYPE_ATTR_PAD_SPACE) ? true : false;
2004-03-07 08:58:55 +01:00
cache->texttype_fn_key_length = famasc_key_length;
cache->texttype_fn_string_to_key= famasc_string_to_key;
cache->texttype_fn_compare = famasc_compare;
2005-05-28 00:45:31 +02:00
return true;
2003-09-19 00:06:59 +02:00
}
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
2005-05-28 00:45:31 +02:00
if (FAMILY_MULTIBYTE(cache, CC_C, POSIX, attributes, specific_attributes, specific_attributes_length))
{
//cache->texttype_fn_str_to_upper = sjis_str_to_upper;
//cache->texttype_fn_str_to_lower = sjis_str_to_lower;
return true;
}
2008-02-26 08:23:32 +01:00
return false;
2001-05-23 15:26:42 +02:00
}
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
2005-05-28 00:45:31 +02:00
if (FAMILY_MULTIBYTE(cache, CC_C, POSIX, attributes, specific_attributes, specific_attributes_length))
{
//cache->texttype_fn_str_to_upper = famasc_str_to_upper;
//cache->texttype_fn_str_to_lower = famasc_str_to_lower;
return true;
}
2008-02-26 08:23:32 +01:00
return false;
2001-05-23 15:26:42 +02:00
}
2006-01-16 17:49:15 +01:00
#ifdef NOT_USED_OR_REPLACED
2001-05-23 15:26:42 +02:00
/*
2005-05-28 00:45:31 +02:00
* Returns INTL_BAD_STR_LENGTH if output buffer was too small
2001-05-23 15:26:42 +02:00
*/
/*
* Note: This function expects Multibyte input
*/
static ULONG sjis_str_to_upper(texttype* obj, ULONG iLen, const BYTE* pStr, ULONG 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(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)
2005-05-28 00:45:31 +02:00
return (INTL_BAD_STR_LENGTH); /* Must have ran out of output space */
2001-05-23 15:26:42 +02:00
return (pOutStr - p);
}
/*
2005-05-28 00:45:31 +02:00
* Returns INTL_BAD_STR_LENGTH if output buffer was too small
*/
/*
* Note: This function expects Multibyte input
2001-05-23 15:26:42 +02:00
*/
static ULONG sjis_str_to_lower(texttype* obj, ULONG iLen, const BYTE* pStr, ULONG iOutLen, BYTE *pOutStr)
2001-05-23 15:26:42 +02:00
{
2005-05-28 00:45:31 +02:00
bool waiting_for_sjis2 = false;
2005-05-28 00:45:31 +02:00
fb_assert(pStr != NULL);
fb_assert(pOutStr != NULL);
fb_assert(iOutLen >= iLen);
const BYTE* const p = pOutStr;
while (iLen && iOutLen) {
BYTE c = *pStr++;
if (waiting_for_sjis2 || SJIS1(c)) {
waiting_for_sjis2 = !waiting_for_sjis2;
}
else {
if (c >= ASCII_UPPER_A && c <= ASCII_UPPER_Z)
c = (c - ASCII_UPPER_A + ASCII_LOWER_A);
}
*pOutStr++ = c;
iLen--;
iOutLen--;
}
if (iLen != 0)
return (INTL_BAD_STR_LENGTH); /* Must have ran out of output space */
return (pOutStr - p);
}
2006-01-16 17:49:15 +01:00
#endif