Bug 724538 - When ICU is available in the build, replace most of nsCharProps2 fields with ICU property accessors. r=emk

This commit is contained in:
Jonathan Kew
2016-01-13 15:45:22 +00:00
parent d8144a9303
commit 0ff3300765
6 changed files with 220 additions and 268 deletions

View File

@@ -11,12 +11,12 @@
#if ENABLE_INTL_API
#include "unicode/uchar.h"
#include "unicode/uscript.h"
#endif
#define UNICODE_BMP_LIMIT 0x10000
#define UNICODE_LIMIT 0x110000
#ifndef ENABLE_INTL_API
static const nsCharProps1&
GetCharProps1(uint32_t aCh)
@@ -56,14 +56,21 @@ GetCharProps2(uint32_t aCh)
NS_NOTREACHED("Getting CharProps for codepoint outside Unicode range");
// Default values for unassigned
using namespace mozilla::unicode;
static const nsCharProps2 undefined = {
MOZ_SCRIPT_UNKNOWN, // Script code
0, // East Asian Width
HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED, // General Category
eCharType_LeftToRight, // Bidi Category
mozilla::unicode::XIDMOD_NOT_CHARS, // Xidmod
-1, // Numeric Value
mozilla::unicode::HVT_NotHan // Han variant
#if ENABLE_INTL_API
PAIRED_BRACKET_TYPE_NONE,
VERTICAL_ORIENTATION_R,
XIDMOD_NOT_CHARS
#else
MOZ_SCRIPT_UNKNOWN,
PAIRED_BRACKET_TYPE_NONE,
HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED,
eCharType_LeftToRight,
XIDMOD_NOT_CHARS,
-1, // Numeric Value
VERTICAL_ORIENTATION_R
#endif
};
return undefined;
}
@@ -93,7 +100,7 @@ to provide the most compact storage, depending on the distribution
of values.
*/
nsIUGenCategory::nsUGenCategory sDetailedToGeneralCategory[] = {
const nsIUGenCategory::nsUGenCategory sDetailedToGeneralCategory[] = {
/*
* The order here corresponds to the HB_UNICODE_GENERAL_CATEGORY_* constants
* of the hb_unicode_general_category_t enum in gfx/harfbuzz/src/hb-unicode.h.
@@ -130,6 +137,69 @@ nsIUGenCategory::nsUGenCategory sDetailedToGeneralCategory[] = {
/* SPACE_SEPARATOR */ nsIUGenCategory::kSeparator
};
#ifdef ENABLE_INTL_API
const hb_unicode_general_category_t sICUtoHBcategory[U_CHAR_CATEGORY_COUNT] = {
HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED, // U_GENERAL_OTHER_TYPES = 0,
HB_UNICODE_GENERAL_CATEGORY_UPPERCASE_LETTER, // U_UPPERCASE_LETTER = 1,
HB_UNICODE_GENERAL_CATEGORY_LOWERCASE_LETTER, // U_LOWERCASE_LETTER = 2,
HB_UNICODE_GENERAL_CATEGORY_TITLECASE_LETTER, // U_TITLECASE_LETTER = 3,
HB_UNICODE_GENERAL_CATEGORY_MODIFIER_LETTER, // U_MODIFIER_LETTER = 4,
HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER, // U_OTHER_LETTER = 5,
HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK, // U_NON_SPACING_MARK = 6,
HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK, // U_ENCLOSING_MARK = 7,
HB_UNICODE_GENERAL_CATEGORY_SPACING_MARK, // U_COMBINING_SPACING_MARK = 8,
HB_UNICODE_GENERAL_CATEGORY_DECIMAL_NUMBER, // U_DECIMAL_DIGIT_NUMBER = 9,
HB_UNICODE_GENERAL_CATEGORY_LETTER_NUMBER, // U_LETTER_NUMBER = 10,
HB_UNICODE_GENERAL_CATEGORY_OTHER_NUMBER, // U_OTHER_NUMBER = 11,
HB_UNICODE_GENERAL_CATEGORY_SPACE_SEPARATOR, // U_SPACE_SEPARATOR = 12,
HB_UNICODE_GENERAL_CATEGORY_LINE_SEPARATOR, // U_LINE_SEPARATOR = 13,
HB_UNICODE_GENERAL_CATEGORY_PARAGRAPH_SEPARATOR, // U_PARAGRAPH_SEPARATOR = 14,
HB_UNICODE_GENERAL_CATEGORY_CONTROL, // U_CONTROL_CHAR = 15,
HB_UNICODE_GENERAL_CATEGORY_FORMAT, // U_FORMAT_CHAR = 16,
HB_UNICODE_GENERAL_CATEGORY_PRIVATE_USE, // U_PRIVATE_USE_CHAR = 17,
HB_UNICODE_GENERAL_CATEGORY_SURROGATE, // U_SURROGATE = 18,
HB_UNICODE_GENERAL_CATEGORY_DASH_PUNCTUATION, // U_DASH_PUNCTUATION = 19,
HB_UNICODE_GENERAL_CATEGORY_OPEN_PUNCTUATION, // U_START_PUNCTUATION = 20,
HB_UNICODE_GENERAL_CATEGORY_CLOSE_PUNCTUATION, // U_END_PUNCTUATION = 21,
HB_UNICODE_GENERAL_CATEGORY_CONNECT_PUNCTUATION, // U_CONNECTOR_PUNCTUATION = 22,
HB_UNICODE_GENERAL_CATEGORY_OTHER_PUNCTUATION, // U_OTHER_PUNCTUATION = 23,
HB_UNICODE_GENERAL_CATEGORY_MATH_SYMBOL, // U_MATH_SYMBOL = 24,
HB_UNICODE_GENERAL_CATEGORY_CURRENCY_SYMBOL, // U_CURRENCY_SYMBOL = 25,
HB_UNICODE_GENERAL_CATEGORY_MODIFIER_SYMBOL, // U_MODIFIER_SYMBOL = 26,
HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL, // U_OTHER_SYMBOL = 27,
HB_UNICODE_GENERAL_CATEGORY_INITIAL_PUNCTUATION, // U_INITIAL_PUNCTUATION = 28,
HB_UNICODE_GENERAL_CATEGORY_FINAL_PUNCTUATION, // U_FINAL_PUNCTUATION = 29,
};
#endif
uint8_t GetGeneralCategory(uint32_t aCh) {
#if ENABLE_INTL_API
return sICUtoHBcategory[u_charType(aCh)];
#else
return GetCharProps2(aCh).mCategory;
#endif
}
nsCharType GetBidiCat(uint32_t aCh) {
#if ENABLE_INTL_API
return nsCharType(u_charDirection(aCh));
#else
return nsCharType(GetCharProps2(aCh).mBidiCategory);
#endif
}
int8_t GetNumericValue(uint32_t aCh) {
#if ENABLE_INTL_API
UNumericType type =
UNumericType(u_getIntPropertyValue(aCh, UCHAR_NUMERIC_TYPE));
return type == U_NT_DECIMAL || type == U_NT_DIGIT
? int8_t(u_getNumericValue(aCh))
: -1;
#else
return GetCharProps2(aCh).mNumericValue;
#endif
}
uint32_t
GetMirroredChar(uint32_t aCh)
{
@@ -160,14 +230,30 @@ GetCombiningClass(uint32_t aCh)
#endif
}
uint8_t
GetScriptCode(uint32_t aCh)
{
#if ENABLE_INTL_API
UErrorCode err = U_ZERO_ERROR;
return uscript_getScript(aCh, &err);
#else
return GetCharProps2(aCh).mScriptCode;
#endif
}
uint32_t
GetScriptTagForCode(int32_t aScriptCode)
{
#if ENABLE_INTL_API
const char* tag = uscript_getShortName(UScriptCode(aScriptCode));
return HB_TAG(tag[0], tag[1], tag[2], tag[3]);
#else
// this will safely return 0 for negative script codes, too :)
if (uint32_t(aScriptCode) > ArrayLength(sScriptCodeToTag)) {
return 0;
}
return sScriptCodeToTag[aScriptCode];
#endif
}
PairedBracketType GetPairedBracketType(uint32_t aCh)
@@ -254,6 +340,7 @@ GetTitlecaseForAll(uint32_t aCh)
return aCh;
}
#if 0 // currently unused - bug 857481
HanVariantType
GetHanVariant(uint32_t aCh)
{
@@ -272,6 +359,7 @@ GetHanVariant(uint32_t aCh)
// extract the appropriate 2-bit field from the value
return HanVariantType((v >> ((aCh & 3) * 2)) & 3);
}
#endif
uint32_t
GetFullWidth(uint32_t aCh)