2021-11-23 13:33:08 +01:00
|
|
|
#ifndef CTYPE_UCA_H
|
|
|
|
#define CTYPE_UCA_H
|
|
|
|
/* Copyright (c) 2021, MariaDB
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; version 2
|
|
|
|
of the License.
|
|
|
|
|
|
|
|
This library 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
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library; if not, write to the Free
|
|
|
|
Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
|
|
|
MA 02110-1335 USA */
|
|
|
|
|
2021-11-24 12:11:49 +01:00
|
|
|
#define MY_UCA_VERSION_ID(x,y,z) ((uint) ((x) * 100 + (y) * 10 + (z)))
|
2021-11-23 13:33:08 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Implicit weight handling is done according to
|
|
|
|
the section "Computing Implicit Weights" in
|
|
|
|
https://unicode.org/reports/tr10/#Values_For_Base_Table
|
|
|
|
(as of Unicode 14.0.0)
|
|
|
|
|
|
|
|
Implicit weights for a code CP are constructed as follows:
|
|
|
|
[.AAAA.0020.0002][.BBBB.0000.0000]
|
|
|
|
|
|
|
|
- There are two primary weights, depending on the character type and block.
|
|
|
|
- There is one weight on the secondary and tertiary levels.
|
|
|
|
|
|
|
|
AAAA and BBBB are computed using different formulas for:
|
|
|
|
- Siniform ideographic scripts
|
|
|
|
- Han
|
|
|
|
- Unassigned characters
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct my_uca_implict_weight_t
|
|
|
|
{
|
|
|
|
uint16 weight[2];
|
|
|
|
} MY_UCA_IMPLICIT_WEIGHT;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
By default, implicit weights for a code CP are constructed as follows:
|
|
|
|
[.AAAA.0020.0002][.BBBB.0000.0000]
|
|
|
|
|
|
|
|
where AAAA and BBBB are :
|
|
|
|
AAAA= BASE + (CP >> 15);
|
|
|
|
BBBB= (CP & 0x7FFF) | 0x8000;
|
|
|
|
|
|
|
|
This formula covers the following implicit weight subtypes:
|
|
|
|
- Core Han Unified Ideographs
|
|
|
|
- All other Han Unified Ideographs
|
|
|
|
- Unassigned characters
|
|
|
|
Every mentioned subtype passes a different BASE.
|
|
|
|
|
|
|
|
This formula does not cover Siniform ideographic scripts.
|
|
|
|
They are handled by separate functions.
|
|
|
|
*/
|
|
|
|
static inline MY_UCA_IMPLICIT_WEIGHT
|
|
|
|
my_uca_implicit_weight_primary_default(uint16 base, my_wc_t code)
|
|
|
|
{
|
|
|
|
MY_UCA_IMPLICIT_WEIGHT res;
|
|
|
|
res.weight[0]= (uint16) ((code >> 15) + base);
|
|
|
|
res.weight[1]= (uint16) ((code & 0x7FFF)|0x8000);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Calculate Unicode-5.2.0 implicit weight on the primary level.
|
|
|
|
|
|
|
|
According to UCA, BASE is calculated as follows:
|
|
|
|
- FB40 for Unified_Ideograph=True AND
|
|
|
|
((Block=CJK_Unified_Ideograph) OR
|
|
|
|
(Block=CJK_Compatibility_Ideographs))
|
|
|
|
- FB80 for Unified_Ideograph=True AND NOT
|
|
|
|
((Block=CJK_Unified_Ideograph) OR
|
|
|
|
(Block=CJK_Compatibility_Ideographs))
|
|
|
|
- FBC0 for any other code point
|
|
|
|
|
|
|
|
But for Unicode-5.2.0 and Unicode-4.0.0 we used
|
|
|
|
a simplified formula as implemented before.
|
|
|
|
*/
|
|
|
|
static inline MY_UCA_IMPLICIT_WEIGHT
|
|
|
|
my_uca_520_implicit_weight_primary(my_wc_t code)
|
|
|
|
{
|
|
|
|
uint16 base;
|
|
|
|
/*
|
|
|
|
3400;<CJK Ideograph Extension A, First>
|
|
|
|
4DB5;<CJK Ideograph Extension A, Last>
|
|
|
|
4E00;<CJK Ideograph, First>
|
|
|
|
9FA5;<CJK Ideograph, Last>
|
|
|
|
*/
|
|
|
|
if (code >= 0x3400 && code <= 0x4DB5)
|
|
|
|
base= 0xFB80;
|
|
|
|
else if (code >= 0x4E00 && code <= 0x9FA5)
|
|
|
|
base= 0xFB40;
|
|
|
|
else
|
|
|
|
base= 0xFBC0;
|
|
|
|
|
|
|
|
return my_uca_implicit_weight_primary_default(base, code);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
MDEV-27009 Add UCA-14.0.0 collations
- Added one neutral and 22 tailored (language specific) collations based on
Unicode Collation Algorithm version 14.0.0.
Collations were added for Unicode character sets
utf8mb3, utf8mb4, ucs2, utf16, utf32.
Every tailoring was added with four accent and case
sensitivity flag combinations, e.g:
* utf8mb4_uca1400_swedish_as_cs
* utf8mb4_uca1400_swedish_as_ci
* utf8mb4_uca1400_swedish_ai_cs
* utf8mb4_uca1400_swedish_ai_ci
and their _nopad_ variants:
* utf8mb4_uca1400_swedish_nopad_as_cs
* utf8mb4_uca1400_swedish_nopad_as_ci
* utf8mb4_uca1400_swedish_nopad_ai_cs
* utf8mb4_uca1400_swedish_nopad_ai_ci
- Introducing a conception of contextually typed named collations:
CREATE DATABASE db1 CHARACTER SET utf8mb4;
CREATE TABLE db1.t1 (a CHAR(10) COLLATE uca1400_as_ci);
The idea is that there is no a need to specify the character set prefix
in the new collation names. It's enough to type just the suffix
"uca1400_as_ci". The character set is taken from the context.
In the above example script the context character set is utf8mb4.
So the CREATE TABLE will make a column with the collation
utf8mb4_uca1400_as_ci.
Short collations names can be used in any parts of the SQL syntax
where the COLLATE clause is understood.
- New collations are displayed only one time
(without character set combinations) by these statements:
SELECT * FROM INFORMATION_SCHEMA.COLLATIONS;
SHOW COLLATION;
For example, all these collations:
- utf8mb3_uca1400_swedish_as_ci
- utf8mb4_uca1400_swedish_as_ci
- ucs2_uca1400_swedish_as_ci
- utf16_uca1400_swedish_as_ci
- utf32_uca1400_swedish_as_ci
have just one entry in INFORMATION_SCHEMA.COLLATIONS and SHOW COLLATION,
with COLLATION_NAME equal to "uca1400_swedish_as_ci", which is the suffix
without the character set name:
SELECT COLLATION_NAME FROM INFORMATION_SCHEMA.COLLATIONS
WHERE COLLATION_NAME LIKE '%uca1400_swedish_as_ci';
+-----------------------+
| COLLATION_NAME |
+-----------------------+
| uca1400_swedish_as_ci |
+-----------------------+
Note, the behaviour of old collations did not change.
Non-unicode collations (e.g. latin1_swedish_ci) and
old UCA-4.0.0 collations (e.g. utf8mb4_unicode_ci)
are still displayed with the character set prefix, as before.
- The structure of the table INFORMATION_SCHEMA.COLLATIONS was changed.
The NOT NULL constraint was removed from these columns:
- CHARACTER_SET_NAME
- ID
- IS_DEFAULT
and from the corresponding columns in SHOW COLLATION.
For example:
SELECT COLLATION_NAME, CHARACTER_SET_NAME, ID, IS_DEFAULT
FROM INFORMATION_SCHEMA.COLLATIONS
WHERE COLLATION_NAME LIKE '%uca1400_swedish_as_ci';
+-----------------------+--------------------+------+------------+
| COLLATION_NAME | CHARACTER_SET_NAME | ID | IS_DEFAULT |
+-----------------------+--------------------+------+------------+
| uca1400_swedish_as_ci | NULL | NULL | NULL |
+-----------------------+--------------------+------+------------+
The NULL value in these columns now means that the collation
is applicable to multiple character sets.
The behavioir of old collations did not change.
Make sure your client programs can handle NULL values in these columns.
- The structure of the table
INFORMATION_SCHEMA.COLLATION_CHARACTER_SET_APPLICABILITY was changed.
Three new NOT NULL columns were added:
- FULL_COLLATION_NAME
- ID
- IS_DEFAULT
New collations have multiple entries in COLLATION_CHARACTER_SET_APPLICABILITY.
The column COLLATION_NAME contains the collation name without the character
set prefix. The column FULL_COLLATION_NAME contains the collation name with
the character set prefix.
Old collations have full collation name in both FULL_COLLATION_NAME and
COLLATION_NAME.
SELECT COLLATION_NAME, FULL_COLLATION_NAME, CHARACTER_SET_NAME, ID, IS_DEFAULT
FROM INFORMATION_SCHEMA.COLLATION_CHARACTER_SET_APPLICABILITY
WHERE FULL_COLLATION_NAME RLIKE '^(utf8mb4|latin1).*swedish.*ci$';
+-----------------------------+-------------------------------------+--------------------+------+------------+
| COLLATION_NAME | FULL_COLLATION_NAME | CHARACTER_SET_NAME | ID | IS_DEFAULT |
+-----------------------------+-------------------------------------+--------------------+------+------------+
| latin1_swedish_ci | latin1_swedish_ci | latin1 | 8 | Yes |
| latin1_swedish_nopad_ci | latin1_swedish_nopad_ci | latin1 | 1032 | |
| utf8mb4_swedish_ci | utf8mb4_swedish_ci | utf8mb4 | 232 | |
| uca1400_swedish_ai_ci | utf8mb4_uca1400_swedish_ai_ci | utf8mb4 | 2368 | |
| uca1400_swedish_as_ci | utf8mb4_uca1400_swedish_as_ci | utf8mb4 | 2370 | |
| uca1400_swedish_nopad_ai_ci | utf8mb4_uca1400_swedish_nopad_ai_ci | utf8mb4 | 2372 | |
| uca1400_swedish_nopad_as_ci | utf8mb4_uca1400_swedish_nopad_as_ci | utf8mb4 | 2374 | |
+-----------------------------+-------------------------------------+--------------------+------+------------+
- Other INFORMATION_SCHEMA queries:
SELECT COLLATION_NAME FROM INFORMATION_SCHEMA.COLUMNS;
SELECT COLLATION_NAME FROM INFORMATION_SCHEMA.PARAMETERS;
SELECT TABLE_COLLATION FROM INFORMATION_SCHEMA.TABLES;
SELECT DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.SCHEMATA;
SELECT COLLATION_NAME FROM INFORMATION_SCHEMA.ROUTINES;
SELECT COLLATION_CONNECTION FROM INFORMATION_SCHEMA.EVENTS;
SELECT DATABASE_COLLATION FROM INFORMATION_SCHEMA.EVENTS;
SELECT COLLATION_CONNECTION FROM INFORMATION_SCHEMA.ROUTINES;
SELECT DATABASE_COLLATION FROM INFORMATION_SCHEMA.ROUTINES;
SELECT COLLATION_CONNECTION FROM INFORMATION_SCHEMA.TRIGGERS;
SELECT DATABASE_COLLATION FROM INFORMATION_SCHEMA.TRIGGERS;
SELECT COLLATION_CONNECTION FROM INFORMATION_SCHEMA.VIEWS;
display full collation names, including character sets prefix,
for all collations, including new collations.
Corresponding SHOW commands also display full collation names
in collation related columns:
SHOW CREATE TABLE t1;
SHOW CREATE DATABASE db1;
SHOW TABLE STATUS;
SHOW CREATE FUNCTION f1;
SHOW CREATE PROCEDURE p1;
SHOW CREATE EVENT ev1;
SHOW CREATE TRIGGER tr1;
SHOW CREATE VIEW;
These INFORMATION_SCHEMA queries and SHOW statements may change in
the future, to display show collation names.
2021-11-28 13:55:15 +01:00
|
|
|
typedef enum my_cs_encoding_enum
|
|
|
|
{
|
|
|
|
MY_CS_ENCODING_UTF8MB3= 0,
|
|
|
|
MY_CS_ENCODING_UTF8MB4= 1,
|
|
|
|
MY_CS_ENCODING_UCS2= 2,
|
|
|
|
MY_CS_ENCODING_UTF16= 3,
|
|
|
|
MY_CS_ENCODING_UTF32= 4,
|
|
|
|
} my_cs_encoding_t;
|
|
|
|
|
|
|
|
#define MY_CS_ENCODING_LAST MY_CS_ENCODING_UTF32
|
|
|
|
|
|
|
|
|
2021-11-24 12:11:49 +01:00
|
|
|
#include "ctype-uca1400.h"
|
|
|
|
|
|
|
|
|
|
|
|
static inline MY_UCA_IMPLICIT_WEIGHT
|
|
|
|
my_uca_implicit_weight_primary(uint version, my_wc_t code)
|
|
|
|
{
|
|
|
|
return version >= 1400 ?
|
|
|
|
my_uca_1400_implicit_weight_primary(code) :
|
|
|
|
my_uca_520_implicit_weight_primary(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-23 13:33:08 +01:00
|
|
|
static inline MY_UCA_IMPLICIT_WEIGHT
|
|
|
|
my_uca_implicit_weight_secondary()
|
|
|
|
{
|
|
|
|
MY_UCA_IMPLICIT_WEIGHT res;
|
|
|
|
res.weight[0]= 0x0020;
|
|
|
|
res.weight[1]= 0;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline MY_UCA_IMPLICIT_WEIGHT
|
|
|
|
my_uca_implicit_weight_tertiary()
|
|
|
|
{
|
|
|
|
MY_UCA_IMPLICIT_WEIGHT res;
|
|
|
|
res.weight[0]= 0x0002;
|
|
|
|
res.weight[1]= 0;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline MY_UCA_IMPLICIT_WEIGHT
|
|
|
|
my_uca_implicit_weight_quaternary()
|
|
|
|
{
|
|
|
|
MY_UCA_IMPLICIT_WEIGHT res;
|
|
|
|
res.weight[0]= 0x0001;
|
|
|
|
res.weight[1]= 0;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline MY_UCA_IMPLICIT_WEIGHT
|
2021-11-24 12:11:49 +01:00
|
|
|
my_uca_implicit_weight_on_level(uint version, my_wc_t code, uint level)
|
2021-11-23 13:33:08 +01:00
|
|
|
{
|
|
|
|
switch (level) {
|
|
|
|
case 0:
|
2021-11-24 12:11:49 +01:00
|
|
|
return my_uca_implicit_weight_primary(version, code);
|
2021-11-23 13:33:08 +01:00
|
|
|
case 1:
|
|
|
|
return my_uca_implicit_weight_secondary();
|
|
|
|
case 2:
|
|
|
|
return my_uca_implicit_weight_tertiary();
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return my_uca_implicit_weight_quaternary();
|
|
|
|
}
|
|
|
|
|
MDEV-27009 Add UCA-14.0.0 collations
- Added one neutral and 22 tailored (language specific) collations based on
Unicode Collation Algorithm version 14.0.0.
Collations were added for Unicode character sets
utf8mb3, utf8mb4, ucs2, utf16, utf32.
Every tailoring was added with four accent and case
sensitivity flag combinations, e.g:
* utf8mb4_uca1400_swedish_as_cs
* utf8mb4_uca1400_swedish_as_ci
* utf8mb4_uca1400_swedish_ai_cs
* utf8mb4_uca1400_swedish_ai_ci
and their _nopad_ variants:
* utf8mb4_uca1400_swedish_nopad_as_cs
* utf8mb4_uca1400_swedish_nopad_as_ci
* utf8mb4_uca1400_swedish_nopad_ai_cs
* utf8mb4_uca1400_swedish_nopad_ai_ci
- Introducing a conception of contextually typed named collations:
CREATE DATABASE db1 CHARACTER SET utf8mb4;
CREATE TABLE db1.t1 (a CHAR(10) COLLATE uca1400_as_ci);
The idea is that there is no a need to specify the character set prefix
in the new collation names. It's enough to type just the suffix
"uca1400_as_ci". The character set is taken from the context.
In the above example script the context character set is utf8mb4.
So the CREATE TABLE will make a column with the collation
utf8mb4_uca1400_as_ci.
Short collations names can be used in any parts of the SQL syntax
where the COLLATE clause is understood.
- New collations are displayed only one time
(without character set combinations) by these statements:
SELECT * FROM INFORMATION_SCHEMA.COLLATIONS;
SHOW COLLATION;
For example, all these collations:
- utf8mb3_uca1400_swedish_as_ci
- utf8mb4_uca1400_swedish_as_ci
- ucs2_uca1400_swedish_as_ci
- utf16_uca1400_swedish_as_ci
- utf32_uca1400_swedish_as_ci
have just one entry in INFORMATION_SCHEMA.COLLATIONS and SHOW COLLATION,
with COLLATION_NAME equal to "uca1400_swedish_as_ci", which is the suffix
without the character set name:
SELECT COLLATION_NAME FROM INFORMATION_SCHEMA.COLLATIONS
WHERE COLLATION_NAME LIKE '%uca1400_swedish_as_ci';
+-----------------------+
| COLLATION_NAME |
+-----------------------+
| uca1400_swedish_as_ci |
+-----------------------+
Note, the behaviour of old collations did not change.
Non-unicode collations (e.g. latin1_swedish_ci) and
old UCA-4.0.0 collations (e.g. utf8mb4_unicode_ci)
are still displayed with the character set prefix, as before.
- The structure of the table INFORMATION_SCHEMA.COLLATIONS was changed.
The NOT NULL constraint was removed from these columns:
- CHARACTER_SET_NAME
- ID
- IS_DEFAULT
and from the corresponding columns in SHOW COLLATION.
For example:
SELECT COLLATION_NAME, CHARACTER_SET_NAME, ID, IS_DEFAULT
FROM INFORMATION_SCHEMA.COLLATIONS
WHERE COLLATION_NAME LIKE '%uca1400_swedish_as_ci';
+-----------------------+--------------------+------+------------+
| COLLATION_NAME | CHARACTER_SET_NAME | ID | IS_DEFAULT |
+-----------------------+--------------------+------+------------+
| uca1400_swedish_as_ci | NULL | NULL | NULL |
+-----------------------+--------------------+------+------------+
The NULL value in these columns now means that the collation
is applicable to multiple character sets.
The behavioir of old collations did not change.
Make sure your client programs can handle NULL values in these columns.
- The structure of the table
INFORMATION_SCHEMA.COLLATION_CHARACTER_SET_APPLICABILITY was changed.
Three new NOT NULL columns were added:
- FULL_COLLATION_NAME
- ID
- IS_DEFAULT
New collations have multiple entries in COLLATION_CHARACTER_SET_APPLICABILITY.
The column COLLATION_NAME contains the collation name without the character
set prefix. The column FULL_COLLATION_NAME contains the collation name with
the character set prefix.
Old collations have full collation name in both FULL_COLLATION_NAME and
COLLATION_NAME.
SELECT COLLATION_NAME, FULL_COLLATION_NAME, CHARACTER_SET_NAME, ID, IS_DEFAULT
FROM INFORMATION_SCHEMA.COLLATION_CHARACTER_SET_APPLICABILITY
WHERE FULL_COLLATION_NAME RLIKE '^(utf8mb4|latin1).*swedish.*ci$';
+-----------------------------+-------------------------------------+--------------------+------+------------+
| COLLATION_NAME | FULL_COLLATION_NAME | CHARACTER_SET_NAME | ID | IS_DEFAULT |
+-----------------------------+-------------------------------------+--------------------+------+------------+
| latin1_swedish_ci | latin1_swedish_ci | latin1 | 8 | Yes |
| latin1_swedish_nopad_ci | latin1_swedish_nopad_ci | latin1 | 1032 | |
| utf8mb4_swedish_ci | utf8mb4_swedish_ci | utf8mb4 | 232 | |
| uca1400_swedish_ai_ci | utf8mb4_uca1400_swedish_ai_ci | utf8mb4 | 2368 | |
| uca1400_swedish_as_ci | utf8mb4_uca1400_swedish_as_ci | utf8mb4 | 2370 | |
| uca1400_swedish_nopad_ai_ci | utf8mb4_uca1400_swedish_nopad_ai_ci | utf8mb4 | 2372 | |
| uca1400_swedish_nopad_as_ci | utf8mb4_uca1400_swedish_nopad_as_ci | utf8mb4 | 2374 | |
+-----------------------------+-------------------------------------+--------------------+------+------------+
- Other INFORMATION_SCHEMA queries:
SELECT COLLATION_NAME FROM INFORMATION_SCHEMA.COLUMNS;
SELECT COLLATION_NAME FROM INFORMATION_SCHEMA.PARAMETERS;
SELECT TABLE_COLLATION FROM INFORMATION_SCHEMA.TABLES;
SELECT DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.SCHEMATA;
SELECT COLLATION_NAME FROM INFORMATION_SCHEMA.ROUTINES;
SELECT COLLATION_CONNECTION FROM INFORMATION_SCHEMA.EVENTS;
SELECT DATABASE_COLLATION FROM INFORMATION_SCHEMA.EVENTS;
SELECT COLLATION_CONNECTION FROM INFORMATION_SCHEMA.ROUTINES;
SELECT DATABASE_COLLATION FROM INFORMATION_SCHEMA.ROUTINES;
SELECT COLLATION_CONNECTION FROM INFORMATION_SCHEMA.TRIGGERS;
SELECT DATABASE_COLLATION FROM INFORMATION_SCHEMA.TRIGGERS;
SELECT COLLATION_CONNECTION FROM INFORMATION_SCHEMA.VIEWS;
display full collation names, including character sets prefix,
for all collations, including new collations.
Corresponding SHOW commands also display full collation names
in collation related columns:
SHOW CREATE TABLE t1;
SHOW CREATE DATABASE db1;
SHOW TABLE STATUS;
SHOW CREATE FUNCTION f1;
SHOW CREATE PROCEDURE p1;
SHOW CREATE EVENT ev1;
SHOW CREATE TRIGGER tr1;
SHOW CREATE VIEW;
These INFORMATION_SCHEMA queries and SHOW statements may change in
the future, to display show collation names.
2021-11-28 13:55:15 +01:00
|
|
|
uint
|
|
|
|
my_ci_get_id_uca(CHARSET_INFO *cs, my_collation_id_type_t type);
|
|
|
|
|
|
|
|
|
|
|
|
LEX_CSTRING
|
|
|
|
my_ci_get_collation_name_uca(CHARSET_INFO *cs, my_collation_name_mode_t mode);
|
|
|
|
|
2021-11-23 13:33:08 +01:00
|
|
|
|
|
|
|
#endif /* CTYPE_UCA_H */
|