8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-26 06:43:04 +01:00
firebird-mirror/src/jrd/intlobj_new.h

238 lines
6.9 KiB
C
Raw Normal View History

2004-08-12 07:17:49 +02:00
/*
* PROGRAM: JRD International support
* MODULE: intlobj_new.h
* DESCRIPTION: New international text handling definitions (DRAFT)
*
* The contents of this file are subject to the Initial
* Developer's 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.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
*
* Software distributed under the License is distributed AS IS,
* 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 Nickolay Samofatov
* for the Firebird Open Source RDBMS project.
*
* Copyright (c) 2004 Nickolay Samofatov <nickolay@broadviewsoftware.com>
* and all contributors signed below.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*
*/
#ifndef JRD_INTLOBJ_NEW_H
#define JRD_INTLOBJ_NEW_H
#ifndef INCLUDE_FB_TYPES_H
typedef unsigned short USHORT;
typedef short SSHORT;
typedef unsigned char UCHAR;
typedef char CHAR;
typedef unsigned char BYTE;
typedef unsigned int ULONG;
typedef int LONG;
typedef signed int SLONG;
#endif
typedef SCHAR ASCII;
typedef USHORT INTL_BOOL;
/* Forward declarations to be implemented in collation driver */
struct CollationImpl;
struct CharSetImpl;
struct CsConvertImpl;
struct texttype; /* forward decl for the fc signatures before the struct itself. */
struct csconvert;
#define INTL_BAD_KEY_LENGTH ((USHORT)(-1))
#define INTL_BAD_STR_LENGTH ((ULONG)(-1))
/* Returned value of INTL_BAD_KEY_LENGTH means that proposed key is too long */
typedef USHORT (*pfn_INTL_keylength) (
2004-08-12 21:21:03 +02:00
texttype* tt,
2004-08-12 07:17:49 +02:00
USHORT len
);
/* Returned value of INTL_BAD_KEY_LENGTH means that key error happened during key construction */
typedef USHORT (*pfn_INTL_str2key) (
2004-08-12 21:21:03 +02:00
texttype* tt,
2004-08-12 07:17:49 +02:00
USHORT srcLen,
const UCHAR* src,
USHORT dstLen,
UCHAR* dst,
INTL_BOOL partial
);
2004-08-12 21:21:03 +02:00
/* Compare two potentially long strings using the same rules as in str2key transformation.
Return TRUE if str1 > str2 */
typedef INTL_BOOL (*pfn_INTL_greater) (
texttype* tt,
2004-08-12 07:17:49 +02:00
ULONG len1,
const UCHAR* str1,
ULONG len2,
const UCHAR* str2,
INTL_BOOL* error_flag
);
/* Returns resulting string length in bytes or INTL_BAD_STR_LENGTH in case of error */
typedef ULONG (*pfn_INTL_str2case) (
2004-08-12 21:21:03 +02:00
texttype* tt,
2004-08-12 07:17:49 +02:00
ULONG srcLen,
const UCHAR* src,
ULONG dstLen,
UCHAR* dst
);
/* Returns FALSE in case of error */
typedef INTL_BOOL (*pfn_INTL_canonical) (
2004-08-12 21:21:03 +02:00
texttype* t,
2004-08-12 07:17:49 +02:00
ULONG srcLen,
const UCHAR* src,
ULONG dstLen,
2004-08-12 21:21:03 +02:00
UCHAR* dst
2004-08-12 07:17:49 +02:00
);
/* Releases resources associated with collation */
typedef void (*pfn_INTL_tt_destroy) (
2004-08-12 21:21:03 +02:00
texttype* tt
2004-08-12 07:17:49 +02:00
);
typedef struct texttype {
// Data which needs to be initialized by collation driver
USHORT texttype_version; /* version ID of object */
CollationImpl* collation; /* collation object implemented in driver */
const ASCII* texttype_name;
SSHORT texttype_country; /* ID of base country values */
BYTE texttype_canonical_width; /* number bytes in canonical character representation */
BYTE texttype_pad_length; /* Length of pad character in bytes */
const BYTE* texttype_pad_character; /* Character using for string padding */
/* If not set key length is assumed to be equal to string length */
pfn_INTL_keylength texttype_fn_key_length; /* Return key length for given string */
/* If not set string itself is used as a key */
pfn_INTL_str2key texttype_fn_string_to_key;
/* If not set string is assumed to be binary-comparable for sorting purposes */
2004-08-12 21:21:03 +02:00
pfn_INTL_greater texttype_fn_greater;
2004-08-12 07:17:49 +02:00
/* If not set string is converted to Unicode and then uppercased via default case folding table */
pfn_INTL_str2case texttype_fn_str_to_upper; /* Convert string to uppercase */
/* If not set string is converted to Unicode and then lowercased via default case folding table */
pfn_INTL_str2case texttype_fn_str_to_lower; /* Convert string to lowercase */
/* If not set string is assumed to be binary-comparable for equality purposes */
pfn_INTL_canonical texttype_fn_canonical; /* convert string to canonical representation for equality */
/* May be omitted if not needed */
pfn_INTL_tt_destroy texttype_fn_destroy; /* release resources associated with collation */
2004-08-12 21:21:03 +02:00
/* Some space for future extension of collation interface */
void* reserved_for_interface[5];
/* Some space which may be freely used by collation driver */
void* reserved_for_driver[10];
2004-08-12 07:17:49 +02:00
} *TEXTTYPE;
// Returns resulting string length or INTL_BAD_STR_LENGTH in case of error
typedef ULONG (*pfn_INTL_convert) (
2004-08-12 21:21:03 +02:00
csconvert* csc,
2004-08-12 07:17:49 +02:00
ULONG srcLen,
const UCHAR* src,
ULONG dstLen,
UCHAR* dst,
USHORT* error_code,
ULONG* offending_source_character
);
struct csconvert {
USHORT csconvert_version;
2004-08-12 21:21:03 +02:00
CsConvertImpl* csConvert,
2004-08-12 07:17:49 +02:00
const ASCII* csconvert_name;
2004-08-12 21:21:03 +02:00
/* Conversion routine. Must be present. */
2004-08-12 07:17:49 +02:00
pfn_INTL_convert csconvert_convert;
2004-08-12 21:21:03 +02:00
/* Some space for future extension of conversion interface */
void* reserved_for_interface[2];
/* Some space which may be freely used by conversion driver */
void* reserved_for_driver[10];
2004-08-12 07:17:49 +02:00
};
/* Conversion error codes */
#define CS_TRUNCATION_ERROR 1 /* output buffer too small */
#define CS_CONVERT_ERROR 2 /* can't remap a character */
#define CS_BAD_INPUT 3 /* input string detected as bad */
#define CS_CANT_MAP 0 /* Flag table entries that don't map */
/* Returns whether string is well-formed or not */
typedef INTL_BOOL (*pfn_INTL_well_formed) (
2004-08-12 21:21:03 +02:00
charset* cs,
ULONG len,
2004-08-12 07:17:49 +02:00
const UCHAR* str,
);
2004-08-12 21:21:03 +02:00
/* Extracts a portion from a string. Returns INTL_BAD_STR_LENGTH in case of problems. */
typedef ULONG (*pfn_INTL_substring) (
charset* cs,
ULONG srcLen,
const UCHAR* src,
ULONG dstLen,
UCHAR* dst,
ULONG startPos,
ULONG length
);
/* Measures the length of string in characters. Returns INTL_BAD_STR_LENGTH in case of problems. */
typedef ULONG (*pfn_INTL_length) (
charset* cs,
ULONG srcLen,
const UCHAR* src
);
2004-08-12 07:17:49 +02:00
struct charset
{
USHORT charset_version;
2004-08-12 21:21:03 +02:00
CharSetImpl* charset,
2004-08-12 07:17:49 +02:00
const ASCII* charset_name;
BYTE charset_min_bytes_per_char;
BYTE charset_max_bytes_per_char;
csconvert charset_to_unicode;
csconvert charset_from_unicode;
2004-08-12 21:21:03 +02:00
/* If omitted any string is considered well-formed */
pfn_INTL_well_formed charset_well_formed;
2004-08-12 07:17:49 +02:00
/* If not set Unicode representation is used to measure string length. */
pfn_INTL_length texttype_fn_length; /* get length of string in characters */
/* May be omitted for fixed-width character sets.
If not present for MBCS charset string operation is performed by the engine
via intermediate translation of string to Unicode */
pfn_INTL_substring charset_fn_substring; /* get a portion of string */
2004-08-12 21:21:03 +02:00
/* Some space for future extension of charset interface */
void* reserved_for_interface[5];
/* Some space which may be freely used by charset driver */
void* reserved_for_driver[10];
2004-08-12 07:17:49 +02:00
};
#endif /* JRD_INTLOBJ_NEW_H */