8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-27 05:23:02 +01:00
firebird-mirror/src/jrd/intl.h

157 lines
4.9 KiB
C
Raw Normal View History

2001-05-23 15:26:42 +02:00
/*
* PROGRAM: JRD International support
* MODULE: intl.h
* DESCRIPTION: International text handling definitions
*
* 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): ______________________________________.
*/
#ifndef JRD_INTL_H
#define JRD_INTL_H
2001-05-23 15:26:42 +02:00
2010-10-12 10:02:57 +02:00
#include "../common/dsc.h"
2001-05-23 15:26:42 +02:00
#include "../intl/charsets.h"
2009-11-27 09:34:34 +01:00
#define ASCII_SPACE 32 // ASCII code for space
2001-05-23 15:26:42 +02:00
2004-05-19 00:00:21 +02:00
//#define INTL_name_not_found 1
//#define INTL_subtype_not_implemented 2
2001-05-23 15:26:42 +02:00
/*
* Default character set name for specification of COLLATE clause without
* a CHARACTER SET clause.
*
* NATIONAL_CHARACTER_SET is used for SQL's NATIONAL character type.
*/
2003-01-25 04:12:46 +01:00
#define DEFAULT_CHARACTER_SET_NAME "ISO8859_1"
2001-05-23 15:26:42 +02:00
#define NATIONAL_CHARACTER_SET DEFAULT_CHARACTER_SET_NAME
#define DEFAULT_DB_CHARACTER_SET_NAME "NONE"
2001-05-23 15:26:42 +02:00
2009-11-27 09:34:34 +01:00
// Character Set used for system metadata information
#define CS_METADATA CS_UNICODE_FSS // metadata charset
2001-05-23 15:26:42 +02:00
2009-11-27 09:34:34 +01:00
// text type definitions
2001-05-23 15:26:42 +02:00
2009-11-27 09:34:34 +01:00
#define ttype_none CS_NONE // 0
#define ttype_ascii CS_ASCII // 2
#define ttype_binary CS_BINARY // 1
#define ttype_unicode_fss CS_UNICODE_FSS // 3
#define ttype_last_internal CS_UTF8 // 4 // not internal yet, but will be in the future
#define ttype_dynamic CS_dynamic // use att_charset
2001-05-23 15:26:42 +02:00
#define ttype_sort_key ttype_binary
#define ttype_metadata ttype_unicode_fss
2009-11-27 09:34:34 +01:00
// Note:
// changing the value of ttype_metadata is an ODS System Metadata change
// changing the value of CS_METADATA is an ODS System Metadata change
2001-05-23 15:26:42 +02:00
2009-11-27 09:34:34 +01:00
#define COLLATE_NONE 0 // No special collation, use codepoint order
2001-05-23 15:26:42 +02:00
#define INTL_ASSIGN_DSC(dsc, cs, coll) \
{ (dsc)->dsc_sub_type = (SSHORT) ((coll) << 8 | (cs)); }
2001-05-23 15:26:42 +02:00
#define INTL_GET_TTYPE(dsc) \
((dsc)->dsc_sub_type)
#define INTL_GET_CHARSET(dsc) ((UCHAR)((dsc)->dsc_sub_type & 0x00FF))
#define INTL_GET_COLLATE(dsc) ((UCHAR)((dsc)->dsc_sub_type >> 8))
2001-05-23 15:26:42 +02:00
2009-11-27 09:34:34 +01:00
// Define tests for international data
2001-05-23 15:26:42 +02:00
#define INTL_TTYPE(desc) ((desc)->dsc_ttype())
2001-05-23 15:26:42 +02:00
#define INTERNAL_TTYPE(d) (((USHORT)((d)->dsc_ttype())) <= ttype_last_internal)
2001-05-23 15:26:42 +02:00
#define IS_INTL_DATA(d) ((d)->dsc_dtype <= dtype_any_text && \
(((USHORT)((d)->dsc_ttype())) > ttype_last_internal))
2001-05-23 15:26:42 +02:00
2006-05-13 03:19:31 +02:00
inline USHORT INTL_TEXT_TYPE(const dsc& desc)
{
if (DTYPE_IS_TEXT(desc.dsc_dtype))
return INTL_TTYPE(&desc);
2008-12-20 09:12:19 +01:00
if (desc.dsc_dtype == dtype_blob || desc.dsc_dtype == dtype_quad)
2006-05-13 03:19:31 +02:00
{
if (desc.dsc_sub_type == isc_blob_text)
return desc.dsc_blob_ttype();
2008-12-20 09:12:19 +01:00
return ttype_binary;
2006-05-13 03:19:31 +02:00
}
2008-12-20 09:12:19 +01:00
return ttype_ascii;
2006-05-13 03:19:31 +02:00
}
2001-05-23 15:26:42 +02:00
#define INTL_DYNAMIC_CHARSET(desc) (INTL_GET_CHARSET(desc) == CS_dynamic)
/*
* There are several ways text types are used internally to Firebird
2001-05-23 15:26:42 +02:00
* 1) As a CHARACTER_SET_ID & COLLATION_ID pair (in metadata).
* 2) As a CHARACTER_SET_ID (when collation isn't relevent, like UDF parms)
* 3) As an index type - (btr.h)
* 4) As a driver ID (used to lookup the code which implements the locale)
* This is also known as dsc_ttype() (aka text subtype).
2001-05-23 15:26:42 +02:00
*
* In Descriptors (DSC) the data is encoded as:
* dsc_charset overloaded into dsc_scale
* dsc_collate overloaded into dsc_sub_type
*
* Index types are converted to driver ID's via INTL_INDEX_TYPE
*
*/
/* There must be a 1-1 mapping between index types and International text
2008-12-05 01:56:15 +01:00
* subtypes -
2001-05-23 15:26:42 +02:00
* Index-to-subtype: to compute a KEY from a Text string we must know both
* the TEXT format and the COLLATE routine to use (eg: the subtype info).
* We need the text-format as the datavalue for key creation may not
2008-12-05 01:56:15 +01:00
* match that needed for the index.
2001-05-23 15:26:42 +02:00
* Subtype-to-index: When creating indices, they are assigned an
* Index type, which is derived from the datatype of the target.
*
*/
2006-09-01 12:51:57 +02:00
#define INTL_INDEX_TO_TEXT(idxType) ((USHORT)((idxType) - idx_offset_intl_range))
2001-05-23 15:26:42 +02:00
2009-11-27 09:34:34 +01:00
// Maps a text_type to an index ID
2001-05-23 15:26:42 +02:00
#define INTL_TEXT_TO_INDEX(tType) ((USHORT)((tType) + idx_offset_intl_range))
#define MAP_CHARSET_TO_TTYPE(cs) (cs & 0x00FF)
#define INTL_RES_TTYPE(desc) (INTL_DYNAMIC_CHARSET(desc) ?\
MAP_CHARSET_TO_TTYPE(tdbb->getCharSet()) :\
2001-05-23 15:26:42 +02:00
INTL_GET_TTYPE (desc))
#define INTL_INDEX_TYPE(desc) INTL_TEXT_TO_INDEX (INTL_RES_TTYPE (desc))
2009-11-27 09:34:34 +01:00
// Maps a Character_set_id & collation_id to a text_type (driver ID)
2009-11-28 20:39:23 +01:00
#define INTL_CS_COLL_TO_TTYPE(cs, coll) ((USHORT) ((coll) << 8 | ((cs) & 0x00FF)))
2001-05-23 15:26:42 +02:00
#define TTYPE_TO_CHARSET(tt) ((USHORT)((tt) & 0x00FF))
#define TTYPE_TO_COLLATION(tt) ((USHORT)((tt) >> 8))
2004-03-07 08:58:55 +01:00
2006-08-08 04:42:10 +02:00
#endif // JRD_INTL_H