2002-06-04 21:36:48 +02:00
|
|
|
/*
|
|
|
|
* PROGRAM: JRD International support
|
|
|
|
* MODULE: intl_classes.h
|
|
|
|
* DESCRIPTION: International text handling definitions
|
|
|
|
*
|
2003-12-27 05:37:23 +01:00
|
|
|
* 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.
|
2002-06-04 21:36:48 +02:00
|
|
|
*
|
2003-12-27 05:37:23 +01:00
|
|
|
* Created by: Nickolay Samofatov <skidder@bssys.com>
|
2002-06-04 21:36:48 +02:00
|
|
|
*
|
2003-12-27 05:37:23 +01:00
|
|
|
* Contributor(s):
|
2002-06-04 21:36:48 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-10-03 03:53:34 +02:00
|
|
|
#ifndef JRD_INTL_CLASSES_H
|
|
|
|
#define JRD_INTL_CLASSES_H
|
2002-06-04 21:36:48 +02:00
|
|
|
|
2003-11-03 18:14:45 +01:00
|
|
|
#include "firebird.h"
|
|
|
|
#include "../jrd/jrd.h"
|
|
|
|
#include "../jrd/intlobj.h"
|
2002-06-04 21:36:48 +02:00
|
|
|
|
2004-03-20 15:57:40 +01:00
|
|
|
namespace Jrd {
|
|
|
|
|
2004-04-25 04:30:32 +02:00
|
|
|
class LikeObject {
|
2002-06-04 21:36:48 +02:00
|
|
|
public:
|
2004-04-25 04:30:32 +02:00
|
|
|
virtual void reset() = 0;
|
|
|
|
virtual bool process(thread_db*, TextType, const UCHAR*, SSHORT) = 0;
|
|
|
|
virtual bool result() = 0;
|
|
|
|
virtual ~LikeObject() {};
|
|
|
|
};
|
2003-12-27 05:37:23 +01:00
|
|
|
|
2004-04-25 04:30:32 +02:00
|
|
|
class ContainsObject {
|
|
|
|
public:
|
|
|
|
virtual void reset() = 0;
|
|
|
|
virtual bool process(Jrd::thread_db*, Jrd::TextType, const UCHAR*, SSHORT) = 0;
|
|
|
|
virtual bool result() = 0;
|
|
|
|
virtual ~ContainsObject() {};
|
|
|
|
};
|
2003-12-27 05:37:23 +01:00
|
|
|
|
2004-04-25 04:30:32 +02:00
|
|
|
class TextType
|
|
|
|
{
|
|
|
|
public:
|
2004-03-11 06:04:26 +01:00
|
|
|
TextType(texttype *_tt) : tt(_tt) {}
|
2003-11-03 18:14:45 +01:00
|
|
|
|
|
|
|
// copy constructor
|
2003-11-03 21:16:03 +01:00
|
|
|
TextType(const TextType& obj) : tt(obj.tt) {}
|
2003-11-03 18:14:45 +01:00
|
|
|
|
|
|
|
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);
|
2003-11-03 18:14:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
USHORT string_to_key(USHORT a,
|
2004-03-07 08:58:55 +01:00
|
|
|
const UCHAR* b,
|
2003-11-03 18:14:45 +01:00
|
|
|
USHORT c,
|
2004-03-07 08:58:55 +01:00
|
|
|
UCHAR* d,
|
2003-11-03 18:14:45 +01:00
|
|
|
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);
|
2003-11-03 18:14:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SSHORT compare(USHORT a,
|
2004-03-07 08:58:55 +01:00
|
|
|
UCHAR* b,
|
2003-11-03 18:14:45 +01:00
|
|
|
USHORT c,
|
2004-03-07 08:58:55 +01:00
|
|
|
UCHAR* d)
|
2003-11-03 18:14:45 +01:00
|
|
|
{
|
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);
|
2003-11-03 18:14:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2003-11-03 18:14:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2003-11-03 18:14:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SSHORT str_to_upper(USHORT a,
|
2004-03-07 08:58:55 +01:00
|
|
|
const UCHAR* b,
|
2003-11-03 18:14:45 +01:00
|
|
|
USHORT c,
|
2004-03-07 08:58:55 +01:00
|
|
|
UCHAR* d)
|
2003-11-03 18:14:45 +01:00
|
|
|
{
|
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);
|
2003-11-03 18:14:45 +01:00
|
|
|
}
|
|
|
|
|
2004-03-07 08:58:55 +01:00
|
|
|
USHORT to_wc(UCS2_CHAR* a,
|
2003-11-03 18:14:45 +01:00
|
|
|
USHORT b,
|
2004-03-07 08:58:55 +01:00
|
|
|
const UCHAR* c,
|
2003-11-03 18:14:45 +01:00
|
|
|
USHORT d,
|
2004-03-07 08:58:55 +01:00
|
|
|
SSHORT* e,
|
|
|
|
USHORT* f)
|
2003-11-03 18:14:45 +01:00
|
|
|
{
|
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);
|
2003-11-03 18:14:45 +01:00
|
|
|
}
|
|
|
|
|
2003-12-11 11:33:30 +01:00
|
|
|
USHORT mbtowc(UCS2_CHAR* a, const UCHAR* b, USHORT c)
|
2003-11-03 18:14:45 +01:00
|
|
|
{
|
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);
|
2003-11-03 18:14:45 +01:00
|
|
|
}
|
|
|
|
|
2004-03-11 06:04:26 +01:00
|
|
|
bool like(thread_db* tdbb, const UCHAR* s, SSHORT sl, const UCHAR* p, SSHORT pl, SSHORT escape)
|
2003-12-27 05:37:23 +01:00
|
|
|
{
|
|
|
|
fb_assert(tt);
|
|
|
|
fb_assert(tt->texttype_fn_like);
|
2004-04-25 04:30:32 +02:00
|
|
|
return (tt->texttype_fn_like)(tdbb, tt, s, sl, p, pl, escape);
|
2003-12-27 05:37:23 +01:00
|
|
|
}
|
|
|
|
|
2004-04-25 04:30:32 +02:00
|
|
|
LikeObject *like_create(thread_db* tdbb, const UCHAR* p, SSHORT pl, SSHORT escape)
|
2003-12-27 05:37:23 +01:00
|
|
|
{
|
|
|
|
fb_assert(tt);
|
|
|
|
fb_assert(tt->texttype_fn_like_create);
|
2004-04-25 04:30:32 +02:00
|
|
|
return (tt->texttype_fn_like_create)(tdbb, *this, p, pl, escape);
|
2003-12-27 05:37:23 +01:00
|
|
|
}
|
|
|
|
|
2004-03-11 06:04:26 +01:00
|
|
|
bool contains(thread_db* tdbb, const UCHAR* s, SSHORT sl, const UCHAR* p, SSHORT pl)
|
2003-11-03 18:14:45 +01:00
|
|
|
{
|
2003-11-04 00:59:24 +01:00
|
|
|
fb_assert(tt);
|
|
|
|
fb_assert(tt->texttype_fn_contains);
|
2004-04-25 04:30:32 +02:00
|
|
|
return (tt->texttype_fn_contains)(tdbb, tt, s, sl, p, pl);
|
2003-11-03 18:14:45 +01:00
|
|
|
}
|
|
|
|
|
2004-04-25 04:30:32 +02:00
|
|
|
ContainsObject *contains_create(thread_db* tdbb, const UCHAR* p, SSHORT pl)
|
2003-11-03 18:14:45 +01:00
|
|
|
{
|
2003-11-04 00:59:24 +01:00
|
|
|
fb_assert(tt);
|
2003-12-27 05:37:23 +01:00
|
|
|
fb_assert(tt->texttype_fn_contains_create);
|
2004-04-25 04:30:32 +02:00
|
|
|
return (tt->texttype_fn_contains_create)(tdbb, tt, p, pl);
|
2003-11-03 18:14:45 +01:00
|
|
|
}
|
|
|
|
|
2004-03-11 06:04:26 +01:00
|
|
|
USHORT matches(thread_db* tdbb, const UCHAR* a, SSHORT b, const UCHAR* c, SSHORT d)
|
2003-11-03 18:14:45 +01:00
|
|
|
{
|
2003-11-04 00:59:24 +01:00
|
|
|
fb_assert(tt);
|
|
|
|
fb_assert(tt->texttype_fn_matches);
|
2004-04-25 04:30:32 +02:00
|
|
|
return (*(tt->texttype_fn_matches))(tdbb, tt, a, b, c, d);
|
2003-11-03 18:14:45 +01:00
|
|
|
}
|
|
|
|
|
2004-03-11 06:04:26 +01:00
|
|
|
USHORT sleuth_check(thread_db* tdbb, USHORT a,
|
2003-12-11 11:33:30 +01:00
|
|
|
const UCHAR* b,
|
2003-11-03 18:14:45 +01:00
|
|
|
USHORT c,
|
2003-12-11 11:33:30 +01:00
|
|
|
const UCHAR* d,
|
2003-11-03 18:14:45 +01:00
|
|
|
USHORT e)
|
|
|
|
{
|
2003-11-04 00:59:24 +01:00
|
|
|
fb_assert(tt);
|
|
|
|
fb_assert(tt->texttype_fn_sleuth_check);
|
2004-04-25 04:30:32 +02:00
|
|
|
return (*(tt->texttype_fn_sleuth_check))(tdbb, tt, a, b, c, d, e);
|
2003-11-03 18:14:45 +01:00
|
|
|
}
|
|
|
|
|
2004-03-11 06:04:26 +01:00
|
|
|
USHORT sleuth_merge(thread_db* tdbb, const UCHAR* a,
|
2003-11-03 18:14:45 +01:00
|
|
|
USHORT b,
|
2003-12-11 11:33:30 +01:00
|
|
|
const UCHAR* c,
|
2003-11-03 18:14:45 +01:00
|
|
|
USHORT d,
|
2003-12-11 11:33:30 +01:00
|
|
|
UCHAR* e,
|
2003-11-03 18:14:45 +01:00
|
|
|
USHORT f)
|
|
|
|
{
|
2003-11-04 00:59:24 +01:00
|
|
|
fb_assert(tt);
|
|
|
|
fb_assert(tt->texttype_fn_sleuth_merge);
|
2004-04-25 04:30:32 +02:00
|
|
|
return (*(tt->texttype_fn_sleuth_merge))(tdbb, tt, a, b, c, d, e, f);
|
2003-11-03 18:14:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-07 08:58:55 +01:00
|
|
|
USHORT getType() const
|
|
|
|
{
|
2003-11-04 00:59:24 +01:00
|
|
|
fb_assert(tt);
|
2003-11-03 18:14:45 +01:00
|
|
|
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);
|
2003-11-03 18:14:45 +01:00
|
|
|
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);
|
2003-11-03 18:14:45 +01:00
|
|
|
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);
|
2003-11-03 18:14:45 +01:00
|
|
|
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);
|
2003-11-03 18:14:45 +01:00
|
|
|
return tt->texttype_bytes_per_char;
|
|
|
|
}
|
2003-11-03 21:16:03 +01:00
|
|
|
|
2004-03-11 06:04:26 +01:00
|
|
|
texttype* getStruct() const { return tt; }
|
2003-11-03 18:14:45 +01:00
|
|
|
|
|
|
|
private:
|
2004-03-11 06:04:26 +01:00
|
|
|
texttype* tt;
|
2002-06-04 21:36:48 +02:00
|
|
|
};
|
|
|
|
|
2003-11-03 18:14:45 +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();
|
2003-11-03 18:14:45 +01:00
|
|
|
}
|
2002-06-04 21:36:48 +02:00
|
|
|
|
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();
|
2003-11-03 18:14:45 +01:00
|
|
|
}
|
2002-06-04 21:36:48 +02:00
|
|
|
|
|
|
|
class CsConvert
|
|
|
|
{
|
|
|
|
public:
|
2004-03-11 06:04:26 +01:00
|
|
|
CsConvert(csconvert* _cnvt) : cnvt(_cnvt) {}
|
2003-11-03 21:16:03 +01:00
|
|
|
CsConvert(const CsConvert& obj) : cnvt(obj.cnvt) {}
|
2003-11-03 18:14:45 +01:00
|
|
|
|
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,
|
2003-11-03 18:14:45 +01:00
|
|
|
USHORT b,
|
2004-03-07 08:58:55 +01:00
|
|
|
const UCHAR* c,
|
2003-11-03 18:14:45 +01:00
|
|
|
USHORT d,
|
2004-03-07 08:58:55 +01:00
|
|
|
SSHORT* e,
|
|
|
|
USHORT* f)
|
2003-11-03 18:14:45 +01:00
|
|
|
{
|
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-03 18:14:45 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2004-03-11 06:04:26 +01:00
|
|
|
csconvert* getStruct() const { return cnvt; }
|
2003-11-04 00:59:24 +01:00
|
|
|
|
2003-11-03 18:14:45 +01:00
|
|
|
private:
|
2004-03-11 06:04:26 +01:00
|
|
|
csconvert* cnvt;
|
2002-06-04 21:36:48 +02:00
|
|
|
};
|
|
|
|
|
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();
|
2003-11-03 18:14:45 +01:00
|
|
|
}
|
2002-06-04 21:36:48 +02:00
|
|
|
|
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();
|
2003-11-03 18:14:45 +01:00
|
|
|
}
|
2002-06-04 21:36:48 +02:00
|
|
|
|
|
|
|
class CharSet
|
|
|
|
{
|
|
|
|
public:
|
2004-03-11 06:04:26 +01:00
|
|
|
CharSet(charset* _cs) : cs(_cs) {}
|
2003-11-03 21:16:03 +01:00
|
|
|
CharSet(const CharSet &obj) : cs(obj.cs) {};
|
2003-11-03 18:14:45 +01:00
|
|
|
|
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-03 18:14:45 +01:00
|
|
|
|
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
|
|
|
|
2004-03-11 06:04:26 +01:00
|
|
|
charset* getStruct() const { return cs; }
|
2003-11-04 00:59:24 +01:00
|
|
|
|
2003-11-03 18:14:45 +01:00
|
|
|
private:
|
2004-03-11 06:04:26 +01:00
|
|
|
charset* cs;
|
2002-06-04 21:36:48 +02:00
|
|
|
};
|
|
|
|
|
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();
|
2003-11-03 18:14:45 +01:00
|
|
|
}
|
2002-06-04 21:36:48 +02:00
|
|
|
|
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();
|
2003-11-03 18:14:45 +01:00
|
|
|
}
|
2002-06-04 21:36:48 +02:00
|
|
|
|
2004-03-20 15:57:40 +01:00
|
|
|
} //namespace Jrd
|
|
|
|
|
2003-10-03 03:53:34 +02:00
|
|
|
#endif /* JRD_INTL_CLASSES_H */
|
2003-11-05 10:02:33 +01:00
|
|
|
|