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

304 lines
7.8 KiB
C
Raw Normal View History

/*
* PROGRAM: JRD International support
* MODULE: intl_classes.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_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:
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,
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,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);
}
USHORT contains(class tdbb* 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_contains);
return (*(reinterpret_cast<
USHORT (*)(class tdbb*, TextType, const UCHAR*, USHORT, const UCHAR*, USHORT)>
(tt->texttype_fn_contains)))
(a,tt,b,c,d,e);
}
USHORT like(class tdbb* tdbb, const UCHAR* a,
SSHORT b,
const UCHAR* c,
SSHORT d,
SSHORT e)
{
2003-11-04 00:59:24 +01:00
fb_assert(tt);
fb_assert(tt->texttype_fn_like);
return (*(reinterpret_cast<
USHORT(*)(class tdbb*, TextType, const UCHAR*, short, const UCHAR*, short, short)>
(tt->texttype_fn_like)))(tdbb,tt,a,b,c,d,e);
}
USHORT matches(class 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 (*)(class tdbb*, TextType, const UCHAR*, short, const UCHAR*, short)>
(tt->texttype_fn_matches)))
(tdbb,tt,a,b,c,d);
}
USHORT sleuth_check(class 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(*)(class tdbb*, TextType, USHORT, const UCHAR*, USHORT, const UCHAR*, USHORT)>
(tt->texttype_fn_sleuth_check)))
(tdbb,tt,a,b,c,d,e);
}
USHORT sleuth_merge(class 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(*)(class 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 */