2006-06-13 04:38:39 +02:00
|
|
|
/*
|
|
|
|
* PROGRAM: Firebird International support
|
|
|
|
* MODULE: lc_icu.cpp
|
|
|
|
* DESCRIPTION: Collations for ICU character sets
|
|
|
|
*
|
|
|
|
* 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 Adriano dos Santos Fernandes
|
|
|
|
* for the Firebird Open Source RDBMS project.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 Adriano dos Santos Fernandes <adrianosf@uol.com.br>
|
|
|
|
* and all contributors signed below.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "firebird.h"
|
2008-02-05 13:48:38 +01:00
|
|
|
#include "../common/classes/alloc.h"
|
2006-06-13 04:38:39 +02:00
|
|
|
#include "ldcommon.h"
|
|
|
|
#include "ld_proto.h"
|
|
|
|
#include "lc_icu.h"
|
|
|
|
#include "cs_icu.h"
|
2007-04-15 17:57:12 +02:00
|
|
|
#include "../jrd/CharSet.h"
|
2006-09-17 22:06:36 +02:00
|
|
|
#include "../jrd/IntlUtil.h"
|
2007-04-15 17:57:12 +02:00
|
|
|
#include "../common/classes/auto.h"
|
|
|
|
|
|
|
|
using namespace Firebird;
|
2006-06-13 04:38:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
static void texttype_destroy(texttype* tt)
|
|
|
|
{
|
|
|
|
delete [] const_cast<ASCII*>(tt->texttype_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool texttype_default_init(texttype* tt,
|
|
|
|
const ASCII* name,
|
|
|
|
const ASCII* charSetName,
|
|
|
|
USHORT attributes,
|
|
|
|
const UCHAR* specificAttributes,
|
2007-04-15 17:57:12 +02:00
|
|
|
ULONG specificAttributesLength,
|
|
|
|
const ASCII* configInfo)
|
2006-06-13 04:38:39 +02:00
|
|
|
{
|
|
|
|
charset cs;
|
|
|
|
memset(&cs, 0, sizeof(cs));
|
|
|
|
|
|
|
|
// test if that ICU charset exist
|
|
|
|
if (CSICU_charset_init(&cs, charSetName))
|
|
|
|
{
|
|
|
|
if (cs.charset_fn_destroy)
|
|
|
|
cs.charset_fn_destroy(&cs);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ((attributes & ~TEXTTYPE_ATTR_PAD_SPACE) ||
|
|
|
|
// disabled TEXTTYPE_ATTR_PAD_SPACE isn't allowed
|
|
|
|
// for our ICU collations yet
|
|
|
|
!(attributes & TEXTTYPE_ATTR_PAD_SPACE) ||
|
|
|
|
specificAttributesLength)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// name comes from stack. Copy it.
|
2008-04-22 13:28:16 +02:00
|
|
|
ASCII* p = FB_NEW(*getDefaultMemoryPool()) ASCII[strlen(name) + 1];
|
|
|
|
strcpy(p, name);
|
|
|
|
tt->texttype_name = p;
|
2006-06-13 04:38:39 +02:00
|
|
|
|
|
|
|
tt->texttype_version = TEXTTYPE_VERSION_1;
|
|
|
|
tt->texttype_country = CC_INTL;
|
|
|
|
tt->texttype_pad_option = (attributes & TEXTTYPE_ATTR_PAD_SPACE) ? true : false;
|
|
|
|
tt->texttype_fn_destroy = texttype_destroy;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool texttype_unicode_init(texttype* tt,
|
|
|
|
const ASCII* name,
|
|
|
|
const ASCII* charSetName,
|
|
|
|
USHORT attributes,
|
|
|
|
const UCHAR* specificAttributes,
|
2007-04-15 17:57:12 +02:00
|
|
|
ULONG specificAttributesLength,
|
|
|
|
const ASCII* configInfo)
|
2006-06-13 04:38:39 +02:00
|
|
|
{
|
2008-02-05 13:48:38 +01:00
|
|
|
charset* cs = FB_NEW(*getDefaultMemoryPool()) charset;
|
2006-09-17 22:06:36 +02:00
|
|
|
memset(cs, 0, sizeof(*cs));
|
2006-06-13 04:38:39 +02:00
|
|
|
|
|
|
|
// test if that charset exist
|
2007-04-15 17:57:12 +02:00
|
|
|
if (!LD_lookup_charset(cs, charSetName, configInfo))
|
2006-06-13 04:38:39 +02:00
|
|
|
{
|
2007-04-15 17:57:12 +02:00
|
|
|
Jrd::CharSet::Delete::clear(cs);
|
2006-06-13 04:38:39 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-09-17 22:06:36 +02:00
|
|
|
Firebird::UCharBuffer specificAttributesBuffer;
|
|
|
|
memcpy(specificAttributesBuffer.getBuffer(specificAttributesLength),
|
|
|
|
specificAttributes, specificAttributesLength);
|
2006-06-13 04:38:39 +02:00
|
|
|
|
2007-04-17 04:24:33 +02:00
|
|
|
// ASF: Don't free "cs". It'will be used in the collation.
|
2007-04-15 17:57:12 +02:00
|
|
|
return Firebird::IntlUtil::initUnicodeCollation(tt, cs, name,
|
|
|
|
attributes, specificAttributesBuffer, configInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LCICU_setup_attributes(const ASCII* name, const ASCII* charSetName, const ASCII* configInfo,
|
|
|
|
const Firebird::string& specificAttributes, Firebird::string& newSpecificAttributes)
|
|
|
|
{
|
|
|
|
int len = strlen(name);
|
|
|
|
|
|
|
|
if (len > 8 && strcmp(name + len - 8, "_UNICODE") == 0)
|
|
|
|
{
|
2008-02-05 13:48:38 +01:00
|
|
|
AutoPtr<charset, Jrd::CharSet::Delete> cs(FB_NEW(*getDefaultMemoryPool()) charset);
|
2007-04-15 17:57:12 +02:00
|
|
|
memset(cs, 0, sizeof(*cs));
|
|
|
|
|
|
|
|
// test if that charset exist
|
|
|
|
if (!LD_lookup_charset(cs, charSetName, configInfo))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return IntlUtil::setupIcuAttributes(cs, specificAttributes, configInfo, newSpecificAttributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2006-06-13 04:38:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LCICU_texttype_init(texttype* tt,
|
|
|
|
const ASCII* name,
|
|
|
|
const ASCII* charSetName,
|
|
|
|
USHORT attributes,
|
|
|
|
const UCHAR* specificAttributes,
|
2007-04-15 17:57:12 +02:00
|
|
|
ULONG specificAttributesLength,
|
|
|
|
const ASCII* configInfo)
|
2006-06-13 04:38:39 +02:00
|
|
|
{
|
|
|
|
int len = strlen(name);
|
|
|
|
|
|
|
|
if (strcmp(name, charSetName) == 0)
|
|
|
|
{
|
2006-09-08 18:19:45 +02:00
|
|
|
return texttype_default_init(
|
2006-06-13 04:38:39 +02:00
|
|
|
tt, name, charSetName, attributes,
|
2007-04-15 17:57:12 +02:00
|
|
|
specificAttributes, specificAttributesLength, configInfo);
|
2006-06-13 04:38:39 +02:00
|
|
|
}
|
2008-02-28 03:43:23 +01:00
|
|
|
|
2008-02-26 08:23:32 +01:00
|
|
|
if (len > 8 && strcmp(name + len - 8, "_UNICODE") == 0)
|
2006-06-13 04:38:39 +02:00
|
|
|
{
|
|
|
|
return texttype_unicode_init(
|
|
|
|
tt, name, charSetName, attributes,
|
2007-04-15 17:57:12 +02:00
|
|
|
specificAttributes, specificAttributesLength, configInfo);
|
2006-06-13 04:38:39 +02:00
|
|
|
}
|
2008-02-28 03:43:23 +01:00
|
|
|
|
2008-02-26 08:23:32 +01:00
|
|
|
return false;
|
2006-06-13 04:38:39 +02:00
|
|
|
}
|