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

394 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:
2004-03-20 04:07:21 +01:00
//typedef bool (*FPTR_CONTAINS)(thread_db* tdbb, TextType ttype, const UCHAR* s, SSHORT ls, const UCHAR* p, SSHORT lp);
//typedef void* (*FPTR_CONTAINS_CREATE)(thread_db* 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)(thread_db* tdbb, TextType ttype, void* object, const UCHAR* s, SSHORT ls);
//typedef bool (*FPTR_CONTAINS_RESULT)(void* object);
2004-03-20 04:07:21 +01:00
//typedef bool (*FPTR_LIKE)(thread_db* tdbb, TextType ttype, const UCHAR* s, SSHORT ls, const UCHAR* p, SSHORT lp, UCS2_CHAR escape);
//typedef void* (*FPTR_LIKE_CREATE)(thread_db* 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)(thread_db* tdbb, TextType ttype, void* object, const UCHAR* s, SSHORT ls);
//typedef bool (*FPTR_LIKE_RESULT)(void* object);
TextType(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);
2004-03-07 08:58:55 +01:00
return (*tt->texttype_fn_key_length)(tt, a);
}
USHORT string_to_key(USHORT a,
2004-03-07 08:58:55 +01:00
const UCHAR* b,
USHORT c,
2004-03-07 08:58:55 +01:00
UCHAR* d,
USHORT e)
{
2003-11-04 00:59:24 +01:00
fb_assert(tt);
fb_assert(tt->texttype_fn_string_to_key);
2004-03-07 08:58:55 +01:00
return (*tt->texttype_fn_string_to_key)(tt, a, b, c, d, e);
}
SSHORT compare(USHORT a,
2004-03-07 08:58:55 +01:00
UCHAR* b,
USHORT c,
2004-03-07 08:58:55 +01:00
UCHAR* d)
{
2003-11-04 00:59:24 +01:00
fb_assert(tt);
fb_assert(tt->texttype_fn_compare);
2004-03-07 08:58:55 +01:00
return (*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);
2004-03-07 08:58:55 +01:00
return (*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);
2004-03-07 08:58:55 +01:00
return (*tt->texttype_fn_to_lower)(tt, a);
}
SSHORT str_to_upper(USHORT a,
2004-03-07 08:58:55 +01:00
const UCHAR* b,
USHORT c,
2004-03-07 08:58:55 +01:00
UCHAR* d)
{
2003-11-04 00:59:24 +01:00
fb_assert(tt);
fb_assert(tt->texttype_fn_str_to_upper);
2004-03-07 08:58:55 +01:00
return (*tt->texttype_fn_str_to_upper)(tt, a, b, c, d);
}
2004-03-07 08:58:55 +01:00
USHORT to_wc(UCS2_CHAR* a,
USHORT b,
2004-03-07 08:58:55 +01:00
const UCHAR* c,
USHORT d,
2004-03-07 08:58:55 +01:00
SSHORT* e,
USHORT* f)
{
2003-11-04 00:59:24 +01:00
fb_assert(tt);
fb_assert(tt->texttype_fn_to_wc);
2004-03-07 08:58:55 +01:00
return (*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);
2004-03-07 08:58:55 +01:00
return (*tt->texttype_fn_mbtowc)(tt, a, b, c);
}
bool like(thread_db* tdbb, const UCHAR* s, SSHORT sl, const UCHAR* p, SSHORT pl, SSHORT escape)
{
fb_assert(tt);
fb_assert(tt->texttype_fn_like);
2004-03-20 04:07:21 +01:00
return //reinterpret_cast<FPTR_LIKE>
(tt->texttype_fn_like)(tdbb, tt, s, sl, p, pl, escape);
}
void *like_create(thread_db* tdbb, const UCHAR* p, SSHORT pl, SSHORT escape)
{
fb_assert(tt);
fb_assert(tt->texttype_fn_like_create);
2004-03-20 04:07:21 +01:00
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);
2004-03-20 04:07:21 +01:00
//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);
2004-03-20 04:07:21 +01:00
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);
2004-03-20 04:07:21 +01:00
//reinterpret_cast<FPTR_LIKE_DESTROY>
(tt->texttype_fn_like_destroy)(object);
}
bool like_process(thread_db* tdbb, void* object, const UCHAR* s, SSHORT sl)
{
fb_assert(tt);
fb_assert(tt->texttype_fn_like_process);
2004-03-20 04:07:21 +01:00
return //reinterpret_cast<FPTR_LIKE_PROCESS>
(tt->texttype_fn_like_process)(tdbb, tt, object, s, sl);
}
bool contains(thread_db* 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);
2004-03-20 04:07:21 +01:00
return //reinterpret_cast<FPTR_CONTAINS>
(tt->texttype_fn_contains)(tdbb, tt, s, sl, p, pl);
}
void *contains_create(thread_db* tdbb, const UCHAR* p, SSHORT pl)
{
2003-11-04 00:59:24 +01:00
fb_assert(tt);
fb_assert(tt->texttype_fn_contains_create);
2004-03-20 04:07:21 +01:00
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);
2004-03-20 04:07:21 +01:00
//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);
2004-03-20 04:07:21 +01:00
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);
2004-03-20 04:07:21 +01:00
//reinterpret_cast<FPTR_CONTAINS_DESTROY>
(tt->texttype_fn_contains_destroy)(object);
}
bool contains_process(thread_db* tdbb, void* object, const UCHAR* s, SSHORT sl)
{
fb_assert(tt);
fb_assert(tt->texttype_fn_contains_process);
2004-03-20 04:07:21 +01:00
return //reinterpret_cast<FPTR_CONTAINS_PROCESS>
(tt->texttype_fn_contains_process)(tdbb, tt, object, s, sl);
}
USHORT matches(thread_db* 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);
2004-03-20 04:07:21 +01:00
return (*(//reinterpret_cast<
// USHORT (*)(thread_db*, TextType, const UCHAR*, short, const UCHAR*, short)>
(tt->texttype_fn_matches)))
2004-03-07 08:58:55 +01:00
(tdbb, tt, a, b, c, d);
}
USHORT sleuth_check(thread_db* 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);
2004-03-20 04:07:21 +01:00
return (*(//reinterpret_cast<
// USHORT(*)(thread_db*, TextType, USHORT, const UCHAR*, USHORT, const UCHAR*, USHORT)>
(tt->texttype_fn_sleuth_check)))
2004-03-07 08:58:55 +01:00
(tdbb, tt, a, b, c, d, e);
}
USHORT sleuth_merge(thread_db* 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);
2004-03-20 04:07:21 +01:00
return (*(//reinterpret_cast<
// USHORT(*)(thread_db*, TextType, const UCHAR*, USHORT, const UCHAR*, USHORT, UCHAR*, USHORT)>
(tt->texttype_fn_sleuth_merge)))
2004-03-07 08:58:55 +01:00
(tdbb, tt, a, b, c, d, e, f);
}
2004-03-07 08:58:55 +01:00
USHORT getType() const
{
2003-11-04 00:59:24 +01:00
fb_assert(tt);
return tt->texttype_type;
}
2004-03-07 08:58:55 +01:00
const char *getName() const
{
2003-11-04 00:59:24 +01:00
fb_assert(tt);
return tt->texttype_name;
}
2004-03-07 08:58:55 +01:00
CHARSET_ID getCharSet() const
{
2003-11-04 00:59:24 +01:00
fb_assert(tt);
return tt->texttype_character_set;
}
2004-03-07 08:58:55 +01:00
SSHORT getCountry() const
{
2003-11-04 00:59:24 +01:00
fb_assert(tt);
return tt->texttype_country;
}
2004-03-07 08:58:55 +01:00
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
texttype* getStruct() const { return tt; }
private:
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();
}
2004-03-07 08:58:55 +01:00
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(csconvert* _cnvt) : cnvt(_cnvt) {}
2003-11-03 21:16:03 +01:00
CsConvert(const CsConvert& obj) : cnvt(obj.cnvt) {}
2004-03-07 08:58:55 +01:00
// CVC: Beware of this can of worms: csconvert_convert gets assigned
// different functions that not necessarily take the same argument. Typically,
// the src pointer and the dest pointer use different types.
// How does this work without crashing is a miracle of IT.
USHORT convert(UCHAR* a,
USHORT b,
2004-03-07 08:58:55 +01:00
const UCHAR* c,
USHORT d,
2004-03-07 08:58:55 +01:00
SSHORT* e,
USHORT* f)
{
2003-11-04 00:59:24 +01:00
fb_assert(cnvt != NULL);
2004-03-07 08:58:55 +01:00
return (*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; }
2004-03-07 08:58:55 +01:00
const char* getName() const { fb_assert(cnvt); return cnvt->csconvert_name; }
2003-11-04 00:59:24 +01:00
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
csconvert* getStruct() const { return cnvt; }
2003-11-04 00:59:24 +01:00
private:
csconvert* cnvt;
};
2004-03-07 08:58:55 +01:00
static inline bool operator ==(const CsConvert& cv1, const CsConvert& cv2)
{
2003-11-03 21:16:03 +01:00
return cv1.getStruct() == cv2.getStruct();
}
2004-03-07 08:58:55 +01:00
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(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; }
2004-03-07 08:58:55 +01:00
const char* getName() const { fb_assert(cs); return cs->charset_name; }
2003-11-04 00:59:24 +01:00
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; }
2004-03-07 08:58:55 +01:00
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
charset* getStruct() const { return cs; }
2003-11-04 00:59:24 +01:00
private:
charset* cs;
};
2004-03-07 08:58:55 +01:00
static inline bool operator ==(const CharSet& cs1, const CharSet& cs2)
{
2003-11-03 21:16:03 +01:00
return cs1.getStruct() == cs2.getStruct();
}
2004-03-07 08:58:55 +01:00
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 */