bug 738101 - Use the new mozilla::unicode::GetBidiCat instead of the old GetBidiCat. r=jfkthame

This commit is contained in:
Simon Montagu 2012-04-18 21:54:54 -07:00
Родитель c73b93163a
Коммит aa166b4d78
5 изменённых файлов: 15 добавлений и 4641 удалений

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,417 +0,0 @@
#!/usr/local/bin/perl
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (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.mozilla.org/MPL/
#
# 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 is mozilla.org code.
#
# The Initial Developer of the Original Code is
# IBM Corporation.
# Portions created by the Initial Developer are Copyright (C) 2000
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
######################################################################
#
# Initial global variable
#
######################################################################
%gcount = ();
%pat = ();
%map = (
"L" => "1", # Left-to-Right
"R" => "2", # Right-to-Left
"AL" => "3", # Right-to-Left Arabic
"AN" => "4", # Arabic Number
"EN" => "5", # European Number
"ES" => "6", # European Number Separator
"ET" => "7", # European Number Terminator
"CS" => "8", # Common Number Separator
"ON" => "9", # Other Neutrals
"NSM" => "10", # Non-Spacing Mark
"BN" => "11", # Boundary Neutral
"B" => "12", # Paragraph Separator
"S" => "13", # Segment Separator
"WS" => "14", # Whitespace
"LRE" => "15", # Left-to-Right Embedding
"RLE" => "15", # Right-to-Left Embedding
"PDF" => "15", # Pop Directional Format
"LRO" => "15", # Left-to-Right Override
"RLO" => "15" # Right-to-Left Override
);
%special = ();
######################################################################
#
# Open the unicode database file
#
######################################################################
open ( UNICODATA , "< UnicodeData-Latest.txt")
|| die "cannot find UnicodeData-Latest.txt";
######################################################################
#
# Open the output file
#
######################################################################
open ( OUT , "> bidicattable.h")
|| die "cannot open output bidicattable.h file";
######################################################################
#
# Generate license and header
#
######################################################################
$npl = <<END_OF_NPL;
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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.mozilla.org/MPL/
*
* 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 is mozilla.org Code.
*
* The Initial Developer of the Original Code is
* IBM Corporation.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
DO NOT EDIT THIS DOCUMENT !!! THIS DOCUMENT IS GENERATED BY
mozilla/intl/unicharutil/util/genbidicattable.pl
*/
END_OF_NPL
print OUT $npl;
print OUT "\n\n#include \"nscore.h\" \n\n";
%bidicategory = ();
%sh = ();
%sl = ();
%sc = ();
######################################################################
#
# Process the file line by line
#
######################################################################
while(<UNICODATA>) {
chop;
######################################################################
#
# Get value from fields
#
######################################################################
@f = split(/;/ , $_);
$c = $f[0]; # The unicode value
$n = $f[1]; # The unicode name
$g = $f[2]; # The General Category
$b = $f[4]; # The Bidi Category
if(( substr($n, 0, 1) ne "<") || ($n eq "<control>"))
{
#
# print $g;
#
$gcount{$b}++;
$bidicategory{$c} = $b;
} else {
# Handle special block
@pair=split(/, /, $n );
$catnum = $map{$b};
# printf "[%s][%s] => %d\n", $pair[0], $pair[1], $catnum;
if( $pair[1] eq "First>") {
$sl{$pair[0]} = $c;
$sc{$pair[0]} = $catnum;
} elsif ( $pair[1] eq "Last>") {
$sh{$pair[0]} = $c;
if($sc{$pair[0]} ne $catnum)
{
print "WARNING !!!! error in handling special block\n\n";
}
} else {
print "WARNING !!!! error in handling special block\n\n";
}
}
}
# XXX - How can this be made more flexible as new blocks are added to the UCDB?
@range = (
0x0000, 0x33ff,
0x4dc0, 0x4dff,
0xa000, 0xabff,
0xd7b0, 0xd7ff,
0xf900, 0x1019f,
0x101d0, 0x101ff,
0x10280, 0x104ff,
0x10800, 0x1085f,
0x10900, 0x1093f,
0x10980, 0x10a7f,
0x10b00, 0x10b7f,
0x10c00, 0x10c4f,
0x10e60, 0x10e7f,
0x11000, 0x111ff,
0x11680, 0x116ff,
0x12000, 0x1247f,
0x13000, 0x1342f,
0x16800, 0x16a3f,
0x16f00, 0x16fff,
0x1b000, 0x1b00f,
0x1d000, 0x1d7ff,
0x1ee00, 0x1eeff,
0x1f000, 0x1f77f,
0x2f800, 0x2fa1f,
0xe0000, 0xe01ff
);
$totaldata = 0;
$tt=($#range+1) / 2;
@patarray = ();
# This should improve performance: put all the patterns like 0x11111111, 0x22222222 etc at the beginning of the table.
# Since there are a lot of blocks with the same category, we should be able to save a lot of time extracting the digits
for (0..15) {
$pattern = "0x".(sprintf("%X", $_) x 8);
$patarray[$_] = $pattern;
$pat{$pattern} = $_;
}
$newidx = 0x10;
for($t = 1; $t <= $tt; $t++)
{
$tl = $range[($t-1) * 2];
$th = $range[($t-1) * 2 + 1];
$ts = ( $th - $tl ) >> 3;
$totaldata += $ts + 1;
printf OUT "static PRUint8 gBidiCatIdx%d[%d] = {\n", $t, $ts + 1;
for($i = ($tl >> 3); $i <= ($th >> 3) ; $i ++ )
{
$data = 0;
for($j = 0; $j < 8 ; $j++)
{
#defaults for unassigned characters
#see http://www.unicode.org/Public/UNIDATA/extracted/DerivedBidiClass.txt
#and http://www.unicode.org/Public/UNIDATA/Blocks.txt
$test = ($i << 3) + $j;
if ((($test >= 0x0590) && ($test <= 0x5FF)) ||
(($test >= 0x07C0) && ($test <= 0x89F)) ||
(($test >= 0xFB1D) && ($test <= 0xFB4F)) ||
(($test >= 0x10800) && ($test <=0x10FFF)) ||
(($test >= 0x1E800) && ($test <=0x1EDFF)) ||
(($test >= 0x1EF00) && ($test <=0x1EFFF)))
{
$default = $map{"R"};
} elsif ((($test >= 0x0600) && ($test <= 0x7BF)) ||
(($test >= 0x08A0) && ($test <= 0x08FF)) ||
(($test >= 0xFB50) && ($test <= 0xFDFF)) ||
(($test >= 0xFE70) && ($test <= 0xFEFE)) ||
(($test >= 0x1EE00) && ($test <= 0x1EEFF)))
{
$default = $map{"AL"};
} else
{
$default = $map{"L"};
}
$k = sprintf("%04X", (($i << 3) + $j));
$cat = $bidicategory{$k};
if( $cat eq "")
{
$data = $data + ($default << (4*$j));
} else {
$data = $data + ($map{$cat} << (4*$j));
}
}
$pattern = sprintf("0x%08X", $data);
$idx = $pat{$pattern};
unless( exists($pat{$pattern})){
$idx = $newidx++;
$patarray[$idx] = $pattern;
$pat{$pattern} = $idx;
}
printf OUT " %3d, /* U+%04X - U+%04X : %s */\n" ,
$idx, ($i << 3),((($i +1)<< 3)-1), $pattern ;
}
printf OUT "};\n\n";
if($t ne $tt)
{
$tl = $range[($t-1) * 2 + 1] + 1;
$th = $range[$t * 2] - 1;
for($i = ($tl >> 3); $i <= ($th >> 3) ; $i ++ )
{
$data = 0;
for($j = 0; $j < 8 ; $j++)
{
$k = sprintf("%04X", (($i << 3) + $j));
$cat = $bidicategory{$k};
if( $cat ne "")
{
$data = $data + ($map{$cat} << (4*$j));
}
}
$pattern = sprintf("0x%08X", $data);
if($data ne 0)
{
print "WARNING, Unicode Database now contain characters" .
"which we have not consider, change this program !!!\n\n";
printf "Problem- U+%04X - U+%04X range\n", ($i << 3),((($i +1)<< 3)-1);
}
}
}
}
if($newidx > 255)
{
die "We have more than 255 patterns !!! - $newidx\n\n" .
"This program is now broken!!!\n\n\n";
}
printf OUT "static PRUint32 gBidiCatPat[$newidx] = {\n";
for($i = 0 ; $i < $newidx; $i++)
{
printf OUT " %s, /* $i */\n", $patarray[$i] ;
}
printf OUT "};\n\n";
$totaldata += $newidx * 4;
printf OUT "static eBidiCategory GetBidiCat(PRUint32 u)\n{\n";
printf OUT " PRUint32 pat;\n";
printf OUT " PRUint16 patidx;\n\n";
@special = keys(%sh);
$sp = 0;
foreach $s ( sort(@special) ) {
# don't bother to define the special blocks unless they have a different
# value from the default they would be given if they were undefined
unless ($sc{$s} == $map{"L"}) {
unless ($sp++) {
%by_value = reverse %map;
printf OUT " /* Handle blocks which share the same category */\n\n";
}
printf OUT " /* Handle %s block */\n", substr($s, 1);
printf OUT " if((((PRUint32)0x%s)<=u)&&(u<=((PRUint32)0x%s))) \n", $sl{$s}, $sh{$s};
printf OUT " return eBidiCat_$by_value{$sc{$s}}; \n\n";
}
}
printf OUT " /* Handle blocks which use index table mapping */ \n\n";
for($t = 1; $t <= $tt; $t++)
{
$tl = $range[($t-1) * 2];
$th = $range[($t-1) * 2 + 1];
if ($tl == 0) {
printf OUT " /* Handle U+%04X to U+%04X */\n", $tl, $th;
printf OUT " if (u<=((PRUint32)0x%04X)) {\n", $th;
printf OUT " patidx = gBidiCatIdx%d [( u >> 3 )];\n", $t;
} else {
printf OUT " /* Handle U+%04X to U+%04X */\n", $tl, $th;
printf OUT " else if ((((PRUint32)0x%04X)<=u)&&(u<=((PRUint32)0x%04X))) {\n", $tl, $th;
printf OUT " patidx = gBidiCatIdx%d [( (u -(PRUint32) 0x%04X) >> 3 )];\n", $t, $tl;
}
printf OUT " }\n\n";
}
printf OUT " else {\n";
printf OUT " /* defaults for unassigned characters\n";
printf OUT " * see http://www.unicode.org/Public/UNIDATA/extracted/DerivedBidiClass.txt\n";
printf OUT " * and http://www.unicode.org/Public/UNIDATA/Blocks.txt\n";
printf OUT " */\n";
printf OUT " if (((u >= 0x0590) && (u <= 0x05FF)) ||\n";
printf OUT " ((u >= 0x07C0) && (u <= 0x08FF)) ||\n";
printf OUT " ((u >= 0xFB1D) && (u <= 0xFB4F)) ||\n";
printf OUT " ((u >= 0x10800) && (u <=0x10FFF)))\n";
printf OUT " return eBidiCat_R;\n";
printf OUT " else if (((u >= 0x0600) && (u <= 0x07BF)) ||\n";
printf OUT " ((u >= 0xFB50) && (u <= 0xFDFF)) ||\n";
printf OUT " ((u >= 0xFE70) && (u <= 0xFEFE)))\n";
printf OUT " return eBidiCat_AL;\n";
printf OUT " else\n";
printf OUT " return eBidiCat_L;\n";
printf OUT " }\n\n";
printf OUT " if (patidx < 0x10)\n";
printf OUT " return (eBidiCategory)patidx;\n";
printf OUT " else {\n";
printf OUT " pat = gBidiCatPat[patidx];\n";
printf OUT " return (eBidiCategory)((pat >> ((u % 8) * 4)) & 0x0F);\n";
printf OUT " }\n}\n\n";
printf OUT "/* total data size = $totaldata */\n";
print "total = $totaldata\n";
######################################################################
#
# Close files
#
######################################################################
close(UNIDATA);
close(OUT);

Просмотреть файл

@ -41,34 +41,8 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include "nsBidiUtils.h" #include "nsBidiUtils.h"
#include "bidicattable.h"
#include "nsCharTraits.h" #include "nsCharTraits.h"
#include "nsUnicodeProperties.h"
static nsCharType ebc2ucd[15] = {
eCharType_OtherNeutral, /* Placeholder -- there will never be a 0 index value */
eCharType_LeftToRight,
eCharType_RightToLeft,
eCharType_RightToLeftArabic,
eCharType_ArabicNumber,
eCharType_EuropeanNumber,
eCharType_EuropeanNumberSeparator,
eCharType_EuropeanNumberTerminator,
eCharType_CommonNumberSeparator,
eCharType_OtherNeutral,
eCharType_DirNonSpacingMark,
eCharType_BoundaryNeutral,
eCharType_BlockSeparator,
eCharType_SegmentSeparator,
eCharType_WhiteSpaceNeutral
};
static nsCharType cc2ucd[5] = {
eCharType_LeftToRightEmbedding,
eCharType_RightToLeftEmbedding,
eCharType_PopDirectionalFormat,
eCharType_LeftToRightOverride,
eCharType_RightToLeftOverride
};
#define ARABIC_TO_HINDI_DIGIT_INCREMENT (START_HINDI_DIGITS - START_ARABIC_DIGITS) #define ARABIC_TO_HINDI_DIGIT_INCREMENT (START_HINDI_DIGITS - START_ARABIC_DIGITS)
#define PERSIAN_TO_HINDI_DIGIT_INCREMENT (START_HINDI_DIGITS - START_FARSI_DIGITS) #define PERSIAN_TO_HINDI_DIGIT_INCREMENT (START_HINDI_DIGITS - START_FARSI_DIGITS)
@ -148,12 +122,14 @@ nsresult HandleNumbers(PRUnichar* aBuffer, PRUint32 aSize, PRUint32 aNumFlag)
} }
#define LRM_CHAR 0x200e #define LRM_CHAR 0x200e
#define LRE_CHAR 0x202a
#define RLO_CHAR 0x202e
bool IsBidiControl(PRUint32 aChar) bool IsBidiControl(PRUint32 aChar)
{ {
// This method is used when stripping Bidi control characters for // This method is used when stripping Bidi control characters for
// display, so it will return TRUE for LRM and RLM as // display, so it will return TRUE for LRM, RLM, LRE, RLE, PDF, LRO and RLO
// well as the characters with category eBidiCat_CC return ((LRE_CHAR <= aChar && aChar <= RLO_CHAR) ||
return (eBidiCat_CC == GetBidiCat(aChar) || ((aChar)&0xfffffe)==LRM_CHAR); ((aChar)&0xfffffe)==LRM_CHAR);
} }
bool HasRTLChars(const nsAString& aString) bool HasRTLChars(const nsAString& aString)
@ -171,23 +147,3 @@ bool HasRTLChars(const nsAString& aString)
} }
return false; return false;
} }
nsCharType GetCharType(PRUint32 aChar)
{
nsCharType oResult;
eBidiCategory bCat = GetBidiCat(aChar);
if (eBidiCat_CC != bCat) {
NS_ASSERTION((PRUint32) bCat < (sizeof(ebc2ucd)/sizeof(nsCharType)), "size mismatch");
if((PRUint32) bCat < (sizeof(ebc2ucd)/sizeof(nsCharType)))
oResult = ebc2ucd[bCat];
else
oResult = ebc2ucd[0]; // something is very wrong, but we need to return a value
} else {
NS_ASSERTION((aChar-0x202a) < (sizeof(cc2ucd)/sizeof(nsCharType)), "size mismatch");
if((aChar-0x202a) < (sizeof(cc2ucd)/sizeof(nsCharType)))
oResult = cc2ucd[aChar - 0x202a];
else
oResult = ebc2ucd[0]; // something is very wrong, but we need to return a value
}
return oResult;
}

Просмотреть файл

@ -49,35 +49,10 @@
* section BIDIRECTIONAL PROPERTIES * section BIDIRECTIONAL PROPERTIES
* for the detailed definition of the following categories * for the detailed definition of the following categories
* *
* The values here must match the equivalents in %map in * The values here must match the equivalents in %bidicategorycode in
* mozilla/intl/unicharutil/tools/genbidicattable.pl * mozilla/intl/unicharutil/tools/genUnicodePropertyData.pl
*/ */
typedef enum {
eBidiCat_Undefined,
eBidiCat_L, /* Left-to-Right */
eBidiCat_R, /* Right-to-Left */
eBidiCat_AL, /* Right-to-Left Arabic */
eBidiCat_AN, /* Arabic Number */
eBidiCat_EN, /* European Number */
eBidiCat_ES, /* European Number Separator */
eBidiCat_ET, /* European Number Terminator */
eBidiCat_CS, /* Common Number Separator */
eBidiCat_ON, /* Other Neutrals */
eBidiCat_NSM, /* Non-Spacing Mark */
eBidiCat_BN, /* Boundary Neutral */
eBidiCat_B, /* Paragraph Separator */
eBidiCat_S, /* Segment Separator */
eBidiCat_WS, /* Whitespace */
eBidiCat_CC = 0xf, /* Control Code */
/* (internal use only - will never be outputed) */
eBidiCat_LRE = 0x2a, /* Left-to-Right Embedding */
eBidiCat_RLE = 0x2b, /* Right-to-Left Embedding */
eBidiCat_PDF = 0x2c, /* Pop Directional Formatting */
eBidiCat_LRO = 0x2d, /* Left-to-Right Override */
eBidiCat_RLO = 0x2e /* Right-to-Left Override */
} eBidiCategory;
enum nsCharType { enum nsCharType {
eCharType_LeftToRight = 0, eCharType_LeftToRight = 0,
eCharType_RightToLeft = 1, eCharType_RightToLeft = 1,
@ -141,11 +116,6 @@ typedef enum nsCharType nsCharType;
*/ */
nsresult HandleNumbers(PRUnichar* aBuffer, PRUint32 aSize, PRUint32 aNumFlag); nsresult HandleNumbers(PRUnichar* aBuffer, PRUint32 aSize, PRUint32 aNumFlag);
/**
* Give a UTF-32 codepoint, return a nsCharType (compatible with ICU)
*/
nsCharType GetCharType(PRUint32 aChar);
/** /**
* Give a UTF-32 codepoint * Give a UTF-32 codepoint
* return true if the codepoint is a Bidi control character (LRE, RLE, PDF, LRO, RLO, LRM, RLM) * return true if the codepoint is a Bidi control character (LRE, RLE, PDF, LRO, RLO, LRM, RLM)

Просмотреть файл

@ -40,9 +40,11 @@
#include "prmem.h" #include "prmem.h"
#include "nsBidi.h" #include "nsBidi.h"
#include "nsBidiUtils.h" #include "nsUnicodeProperties.h"
#include "nsCRT.h" #include "nsCRT.h"
using namespace mozilla::unicode;
// These are #defined in <sys/regset.h> under Solaris 10 x86 // These are #defined in <sys/regset.h> under Solaris 10 x86
#undef CS #undef CS
#undef ES #undef ES
@ -460,11 +462,11 @@ void nsBidi::GetDirProps(const PRUnichar *aText)
uchar=aText[i]; uchar=aText[i];
if(!IS_FIRST_SURROGATE(uchar) || i+1==length || !IS_SECOND_SURROGATE(aText[i+1])) { if(!IS_FIRST_SURROGATE(uchar) || i+1==length || !IS_SECOND_SURROGATE(aText[i+1])) {
/* not a surrogate pair */ /* not a surrogate pair */
flags|=DIRPROP_FLAG(dirProps[i]=dirProp=GetCharType((PRUint32)uchar)); flags|=DIRPROP_FLAG(dirProps[i]=dirProp=GetBidiCat((PRUint32)uchar));
} else { } else {
/* a surrogate pair */ /* a surrogate pair */
dirProps[i++]=BN; /* first surrogate in the pair gets the BN type */ dirProps[i++]=BN; /* first surrogate in the pair gets the BN type */
flags|=DIRPROP_FLAG(dirProps[i]=dirProp=GetCharType(GET_UTF_32(uchar, aText[i])))|DIRPROP_FLAG(BN); flags|=DIRPROP_FLAG(dirProps[i]=dirProp=GetBidiCat(GET_UTF_32(uchar, aText[i])))|DIRPROP_FLAG(BN);
} }
++i; ++i;
if(dirProp==L) { if(dirProp==L) {
@ -490,11 +492,11 @@ void nsBidi::GetDirProps(const PRUnichar *aText)
uchar=aText[i]; uchar=aText[i];
if(!IS_FIRST_SURROGATE(uchar) || i+1==length || !IS_SECOND_SURROGATE(aText[i+1])) { if(!IS_FIRST_SURROGATE(uchar) || i+1==length || !IS_SECOND_SURROGATE(aText[i+1])) {
/* not a surrogate pair */ /* not a surrogate pair */
flags|=DIRPROP_FLAG(dirProps[i]=GetCharType((PRUint32)uchar)); flags|=DIRPROP_FLAG(dirProps[i]=GetBidiCat((PRUint32)uchar));
} else { } else {
/* a surrogate pair */ /* a surrogate pair */
dirProps[i++]=BN; /* second surrogate in the pair gets the BN type */ dirProps[i++]=BN; /* second surrogate in the pair gets the BN type */
flags|=DIRPROP_FLAG(dirProps[i]=GetCharType(GET_UTF_32(uchar, aText[i])))|DIRPROP_FLAG(BN); flags|=DIRPROP_FLAG(dirProps[i]=GetBidiCat(GET_UTF_32(uchar, aText[i])))|DIRPROP_FLAG(BN);
} }
++i; ++i;
} }