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

388 lines
11 KiB
C
Raw Normal View History

/*
* PROGRAM: JRD International support
* MODULE: intl_classes.h
* DESCRIPTION: International text handling definitions
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* You may obtain a copy of the Licence at
* http://www.gnu.org/licences/lgpl.html
*
* As a special exception this file can also be included in modules
* with other source code as long as that source code has been
* released under an Open Source Initiative certificed licence.
* More information about OSI certification can be found at:
* http://www.opensource.org
*
* This module is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public Licence for more details.
*
* This module was created by members of the firebird development
* team. All individual contributions remain the Copyright (C) of
* those individuals and all rights are reserved. Contributors to
* this file are either listed below or can be obtained from a CVS
* history command.
*
* Created by: Nickolay Samofatov <skidder@bssys.com>
*
* Contributor(s):
*
*/
#ifndef JRD_INTL_CLASSES_H
#define JRD_INTL_CLASSES_H
#include "firebird.h"
#include "../jrd/jrd.h"
#include "../jrd/constants.h"
#include "../jrd/intlobj.h"
class TextType
{
public:
typedef bool (*FPTR_CONTAINS)(TDBB tdbb, TextType ttype, const UCHAR* s, SSHORT ls, const UCHAR* p, SSHORT lp);
typedef void* (*FPTR_CONTAINS_CREATE)(TDBB tdbb, TextType ttype, const UCHAR* p, SSHORT lp);
typedef void (*FPTR_CONTAINS_DESTROY)(void* object);
typedef void (*FPTR_CONTAINS_RESET)(void* object);
typedef bool (*FPTR_CONTAINS_PROCESS)(TDBB tdbb, TextType ttype, void* object, const UCHAR* s, SSHORT ls);
typedef bool (*FPTR_CONTAINS_RESULT)(void* object);
typedef bool (*FPTR_LIKE)(TDBB tdbb, TextType ttype, const UCHAR* s, SSHORT ls, const UCHAR* p, SSHORT lp, UCS2_CHAR escape);
typedef void* (*FPTR_LIKE_CREATE)(TDBB tdbb, TextType ttype, const UCHAR* p, SSHORT lp, UCS2_CHAR escape);
typedef void (*FPTR_LIKE_DESTROY)(void* object);
typedef void (*FPTR_LIKE_RESET)(void* object);
typedef bool (*FPTR_LIKE_PROCESS)(TDBB tdbb, TextType ttype, void* object, const UCHAR* s, SSHORT ls);
typedef bool (*FPTR_LIKE_RESULT)(void* object);
TextType(struct texttype *_tt) : tt(_tt) {}
// copy constructor
2003-11-03 21:16:03 +01:00
TextType(const TextType& obj) : tt(obj.tt) {}
USHORT key_length(USHORT a) {
2003-11-04 00:59:24 +01:00
fb_assert(tt);
fb_assert(tt->texttype_fn_key_length);
return (*(reinterpret_cast<USHORT (*)(TEXTTYPE,USHORT)>
(tt->texttype_fn_key_length)))(tt,a);
}
USHORT string_to_key(USHORT a,
const UCHAR *b,
USHORT c,
UCHAR *d,
USHORT e)
{
2003-11-04 00:59:24 +01:00
fb_assert(tt);
fb_assert(tt->texttype_fn_string_to_key);
return (*(reinterpret_cast
<USHORT(*)(TEXTTYPE,USHORT,const UCHAR*,USHORT,UCHAR*,USHORT)>
(tt->texttype_fn_string_to_key)))
(tt,a,b,c,d,e);
}
SSHORT compare(USHORT a,
UCHAR *b,
USHORT c,
UCHAR *d)
{
2003-11-04 00:59:24 +01:00
fb_assert(tt);
fb_assert(tt->texttype_fn_compare);
return (*(reinterpret_cast
<short (*)(TEXTTYPE,USHORT,UCHAR*,USHORT,UCHAR*)>
(tt->texttype_fn_compare)))(tt,a,b,c,d);
}
USHORT to_upper(USHORT a)
{
2003-11-04 00:59:24 +01:00
fb_assert(tt);
fb_assert(tt->texttype_fn_to_upper);
return (*(reinterpret_cast
<short (*)(TEXTTYPE,USHORT)>
(tt->texttype_fn_to_upper)))(tt,a);
}
USHORT to_lower(USHORT a)
{
2003-11-04 00:59:24 +01:00
fb_assert(tt);
fb_assert(tt->texttype_fn_to_lower);
return (*(reinterpret_cast
<USHORT (*)(TEXTTYPE,USHORT)>
(tt->texttype_fn_to_lower)))(tt,a);
}
SSHORT str_to_upper(USHORT a,
const UCHAR *b,
USHORT c,
UCHAR *d)
{
2003-11-04 00:59:24 +01:00
fb_assert(tt);
fb_assert(tt->texttype_fn_str_to_upper);
return (*(reinterpret_cast
<short (*)(TEXTTYPE,USHORT,const UCHAR*,USHORT,UCHAR*)>
(tt->texttype_fn_str_to_upper)))
(tt,a,b,c,d);
}
USHORT to_wc(UCS2_CHAR *a,
USHORT b,
const UCHAR *c,
USHORT d,
SSHORT *e,
USHORT *f)
{
2003-11-04 00:59:24 +01:00
fb_assert(tt);
fb_assert(tt->texttype_fn_to_wc);
return (*(reinterpret_cast
<USHORT (*)(TEXTTYPE,UCS2_CHAR*,USHORT,const UCHAR*,USHORT,short*,USHORT*)>
(tt->texttype_fn_to_wc)))
(tt,a,b,c,d,e,f);
}
USHORT mbtowc(UCS2_CHAR* a, const UCHAR* b, USHORT c)
{
2003-11-04 00:59:24 +01:00
fb_assert(tt);
fb_assert(tt->texttype_fn_mbtowc);
return (*(reinterpret_cast<
USHORT (*)(TEXTTYPE, UCS2_CHAR*, const UCHAR*, USHORT)>
(tt->texttype_fn_mbtowc)))(tt,a,b,c);
}
bool like(struct tdbb* tdbb, const UCHAR* s, SSHORT sl, const UCHAR* p, SSHORT pl, SSHORT escape)
{
fb_assert(tt);
fb_assert(tt->texttype_fn_like);
return reinterpret_cast<FPTR_LIKE>(tt->texttype_fn_like)(tdbb,tt,s,sl,p,pl,escape);
}
void *like_create(struct tdbb* tdbb, const UCHAR* p, SSHORT pl, SSHORT escape)
{
fb_assert(tt);
fb_assert(tt->texttype_fn_like_create);
return reinterpret_cast<FPTR_LIKE_CREATE>(tt->texttype_fn_like_create)(tdbb,tt,p,pl,escape);
}
void like_reset(void* object)
{
fb_assert(tt);
fb_assert(tt->texttype_fn_like_reset);
reinterpret_cast<FPTR_LIKE_RESET>(tt->texttype_fn_like_reset)(object);
}
bool like_result(void* object)
{
fb_assert(tt);
fb_assert(tt->texttype_fn_like_result);
return reinterpret_cast<FPTR_LIKE_RESULT>(tt->texttype_fn_like_result)(object);
}
void like_destroy(void* object)
{
fb_assert(tt);
fb_assert(tt->texttype_fn_like_destroy);
reinterpret_cast<FPTR_LIKE_DESTROY>(tt->texttype_fn_like_destroy)(object);
}
bool like_process(struct tdbb* tdbb, void* object, const UCHAR* s, SSHORT sl)
{
fb_assert(tt);
fb_assert(tt->texttype_fn_like_process);
return reinterpret_cast<FPTR_LIKE_PROCESS>(tt->texttype_fn_like_process)(tdbb,tt,object,s,sl);
}
bool contains(struct tdbb* tdbb, const UCHAR* s, SSHORT sl, const UCHAR* p, SSHORT pl)
{
2003-11-04 00:59:24 +01:00
fb_assert(tt);
fb_assert(tt->texttype_fn_contains);
return reinterpret_cast<FPTR_CONTAINS>(tt->texttype_fn_contains)(tdbb,tt,s,sl,p,pl);
}
void *contains_create(struct tdbb* tdbb, const UCHAR* p, SSHORT pl)
{
2003-11-04 00:59:24 +01:00
fb_assert(tt);
fb_assert(tt->texttype_fn_contains_create);
return reinterpret_cast<FPTR_CONTAINS_CREATE>(tt->texttype_fn_contains_create)(tdbb,tt,p,pl);
}
void contains_reset(void* object)
{
fb_assert(tt);
fb_assert(tt->texttype_fn_contains_reset);
reinterpret_cast<FPTR_CONTAINS_RESET>(tt->texttype_fn_contains_reset)(object);
}
bool contains_result(void* object)
{
fb_assert(tt);
fb_assert(tt->texttype_fn_contains_result);
return reinterpret_cast<FPTR_CONTAINS_RESULT>(tt->texttype_fn_contains_result)(object);
}
void contains_destroy(void* object)
{
fb_assert(tt);
fb_assert(tt->texttype_fn_contains_destroy);
reinterpret_cast<FPTR_CONTAINS_DESTROY>(tt->texttype_fn_contains_destroy)(object);
}
bool contains_process(struct tdbb* tdbb, void* object, const UCHAR* s, SSHORT sl)
{
fb_assert(tt);
fb_assert(tt->texttype_fn_contains_process);
return reinterpret_cast<FPTR_CONTAINS_PROCESS>(tt->texttype_fn_contains_process)(tdbb,tt,object,s,sl);
}
USHORT matches(struct tdbb* tdbb, const UCHAR* a, SSHORT b, const UCHAR* c, SSHORT d)
{
2003-11-04 00:59:24 +01:00
fb_assert(tt);
fb_assert(tt->texttype_fn_matches);
return (*(reinterpret_cast<
USHORT (*)(struct tdbb*, TextType, const UCHAR*, short, const UCHAR*, short)>
(tt->texttype_fn_matches)))
(tdbb,tt,a,b,c,d);
}
USHORT sleuth_check(struct tdbb* tdbb, USHORT a,
const UCHAR* b,
USHORT c,
const UCHAR* d,
USHORT e)
{
2003-11-04 00:59:24 +01:00
fb_assert(tt);
fb_assert(tt->texttype_fn_sleuth_check);
return (*(reinterpret_cast<
USHORT(*)(struct tdbb*, TextType, USHORT, const UCHAR*, USHORT, const UCHAR*, USHORT)>
(tt->texttype_fn_sleuth_check)))
(tdbb,tt,a,b,c,d,e);
}
USHORT sleuth_merge(struct tdbb* tdbb, const UCHAR* a,
USHORT b,
const UCHAR* c,
USHORT d,
UCHAR* e,
USHORT f)
{
2003-11-04 00:59:24 +01:00
fb_assert(tt);
fb_assert(tt->texttype_fn_sleuth_merge);
return (*(reinterpret_cast<
USHORT(*)(struct tdbb*, TextType, const UCHAR*, USHORT, const UCHAR*, USHORT, UCHAR*, USHORT)>
(tt->texttype_fn_sleuth_merge)))
(tdbb,tt,a,b,c,d,e,f);
}
USHORT getType() const {
2003-11-04 00:59:24 +01:00
fb_assert(tt);
return tt->texttype_type;
}
const char *getName() const {
2003-11-04 00:59:24 +01:00
fb_assert(tt);
return tt->texttype_name;
}
CHARSET_ID getCharSet() const {
2003-11-04 00:59:24 +01:00
fb_assert(tt);
return tt->texttype_character_set;
}
SSHORT getCountry() const {
2003-11-04 00:59:24 +01:00
fb_assert(tt);
return tt->texttype_country;
}
UCHAR getBytesPerChar() const {
2003-11-04 00:59:24 +01:00
fb_assert(tt);
return tt->texttype_bytes_per_char;
}
2003-11-03 21:16:03 +01:00
struct texttype *getStruct() const { return tt; }
private:
struct texttype *tt;
};
static inline bool operator ==(const TextType& tt1, const TextType& tt2) {
2003-11-03 21:16:03 +01:00
return tt1.getStruct() == tt2.getStruct();
}
static inline bool operator !=(const TextType& tt1, const TextType& tt2) {
2003-11-03 21:16:03 +01:00
return tt1.getStruct() != tt2.getStruct();
}
class CsConvert
{
public:
CsConvert(struct csconvert *_cnvt) : cnvt(_cnvt) {}
2003-11-03 21:16:03 +01:00
CsConvert(const CsConvert& obj) : cnvt(obj.cnvt) {}
USHORT convert(UCHAR *a,
USHORT b,
UCHAR *c,
USHORT d,
SSHORT *e,
USHORT *f)
{
2003-11-04 00:59:24 +01:00
fb_assert(cnvt != NULL);
return (*(reinterpret_cast<USHORT (*)(struct csconvert*, UCHAR*,USHORT,
UCHAR*,USHORT,short*,USHORT*)>(cnvt->csconvert_convert)))
(cnvt,a,b,c,d,e,f);
}
2003-11-04 00:59:24 +01:00
SSHORT getId() const { fb_assert(cnvt); return cnvt->csconvert_id; }
const char *getName() const { fb_assert(cnvt); return cnvt->csconvert_name; }
CHARSET_ID getFromCS() const { fb_assert(cnvt); return cnvt->csconvert_from; }
CHARSET_ID getToCS() const { fb_assert(cnvt); return cnvt->csconvert_to; }
2003-11-03 21:16:03 +01:00
struct csconvert *getStruct() const { return cnvt; }
2003-11-04 00:59:24 +01:00
private:
struct csconvert *cnvt;
};
static inline bool operator ==(const CsConvert& cv1, const CsConvert& cv2) {
2003-11-03 21:16:03 +01:00
return cv1.getStruct() == cv2.getStruct();
}
static inline bool operator !=(const CsConvert& cv1, const CsConvert& cv2) {
2003-11-03 21:16:03 +01:00
return cv1.getStruct() != cv2.getStruct();
}
class CharSet
{
public:
CharSet(struct charset *_cs) : cs(_cs) {}
2003-11-03 21:16:03 +01:00
CharSet(const CharSet &obj) : cs(obj.cs) {};
2003-11-04 00:59:24 +01:00
CHARSET_ID getId() const { fb_assert(cs); return cs->charset_id; }
const char *getName() const { fb_assert(cs); return cs->charset_name; }
UCHAR minBytesPerChar() const { fb_assert(cs); return cs->charset_min_bytes_per_char; }
UCHAR maxBytesPerChar() const { fb_assert(cs); return cs->charset_max_bytes_per_char; }
UCHAR getSpaceLength() const { fb_assert(cs); return cs->charset_space_length; }
const UCHAR *getSpace() const { fb_assert(cs); return cs->charset_space_character; }
2003-11-04 00:59:24 +01:00
CsConvert getConvToUnicode() { fb_assert(cs); return &cs->charset_to_unicode; }
2003-11-03 21:16:03 +01:00
2003-11-04 00:59:24 +01:00
CsConvert getConvFromUnicode() { fb_assert(cs); return &cs->charset_from_unicode; }
2003-11-03 21:16:03 +01:00
struct charset *getStruct() const { return cs; }
2003-11-04 00:59:24 +01:00
private:
struct charset *cs;
};
static inline bool operator ==(const CharSet& cs1, const CharSet& cs2) {
2003-11-03 21:16:03 +01:00
return cs1.getStruct() == cs2.getStruct();
}
static inline bool operator !=(const CharSet& cs1, const CharSet& cs2) {
2003-11-03 21:16:03 +01:00
return cs1.getStruct() != cs2.getStruct();
}
#endif /* JRD_INTL_CLASSES_H */