mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1848282 - Part 1. Move IsPunctuation to nsUnicharUtils. r=TYLin
Remove duplication code. Differential Revision: https://phabricator.services.mozilla.com/D188784
This commit is contained in:
parent
b20238137a
commit
9dde11abbe
@ -31,7 +31,7 @@
|
||||
#include "nsStyleStructInlines.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsTextFrame.h"
|
||||
#include "nsUnicodeProperties.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "Pivot.h"
|
||||
#include "TextAttrs.h"
|
||||
|
||||
@ -300,30 +300,7 @@ static WordBreakClass GetWordBreakClass(char16_t aChar) {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// Based on ClusterIterator::IsPunctuation in
|
||||
// layout/generic/nsTextFrame.cpp.
|
||||
uint8_t cat = unicode::GetGeneralCategory(aChar);
|
||||
switch (cat) {
|
||||
case HB_UNICODE_GENERAL_CATEGORY_CONNECT_PUNCTUATION: /* Pc */
|
||||
if (aChar == '_' &&
|
||||
!StaticPrefs::layout_word_select_stop_at_underscore()) {
|
||||
return eWbcOther;
|
||||
}
|
||||
[[fallthrough]];
|
||||
case HB_UNICODE_GENERAL_CATEGORY_DASH_PUNCTUATION: /* Pd */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_CLOSE_PUNCTUATION: /* Pe */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_FINAL_PUNCTUATION: /* Pf */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_INITIAL_PUNCTUATION: /* Pi */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_OTHER_PUNCTUATION: /* Po */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_OPEN_PUNCTUATION: /* Ps */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_CURRENCY_SYMBOL: /* Sc */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_MATH_SYMBOL: /* Sm */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL: /* So */
|
||||
return eWbcPunct;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return eWbcOther;
|
||||
return mozilla::IsPunctuationForWordSelect(aChar) ? eWbcPunct : eWbcOther;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "mozilla/Likely.h"
|
||||
#include "mozilla/HashFunctions.h"
|
||||
#include "mozilla/intl/UnicodeProperties.h"
|
||||
#include "mozilla/StaticPrefs_layout.h"
|
||||
|
||||
// We map x -> x, except for upper-case letters,
|
||||
// which we map to their lower-case equivalents.
|
||||
@ -519,4 +520,29 @@ bool IsSegmentBreakSkipChar(uint32_t u) {
|
||||
intl::UnicodeProperties::GetScriptCode(u) != intl::Script::HANGUL;
|
||||
}
|
||||
|
||||
bool IsPunctuationForWordSelect(char16_t aCh) {
|
||||
const uint8_t cat = unicode::GetGeneralCategory(aCh);
|
||||
switch (cat) {
|
||||
case HB_UNICODE_GENERAL_CATEGORY_CONNECT_PUNCTUATION: /* Pc */
|
||||
if (aCh == '_' && !StaticPrefs::layout_word_select_stop_at_underscore()) {
|
||||
return false;
|
||||
}
|
||||
[[fallthrough]];
|
||||
case HB_UNICODE_GENERAL_CATEGORY_DASH_PUNCTUATION: /* Pd */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_CLOSE_PUNCTUATION: /* Pe */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_FINAL_PUNCTUATION: /* Pf */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_INITIAL_PUNCTUATION: /* Pi */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_OTHER_PUNCTUATION: /* Po */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_OPEN_PUNCTUATION: /* Ps */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_CURRENCY_SYMBOL: /* Sc */
|
||||
// Deliberately omitted:
|
||||
// case HB_UNICODE_GENERAL_CATEGORY_MODIFIER_SYMBOL: /* Sk */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_MATH_SYMBOL: /* Sm */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL: /* So */
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
@ -155,6 +155,13 @@ uint32_t HashUTF8AsUTF16(const char* aUTF8, size_t aLength, bool* aErr);
|
||||
|
||||
bool IsSegmentBreakSkipChar(uint32_t u);
|
||||
|
||||
/**
|
||||
* Return true for all Punctuation categories (Unicode general category P?),
|
||||
* and also for Symbol categories (S?) except for Modifier Symbol, which is
|
||||
* kept together with any adjacent letter/number. (Bug 1066756)
|
||||
*/
|
||||
bool IsPunctuationForWordSelect(char16_t aCh);
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* nsUnicharUtils_h__ */
|
||||
|
@ -7833,32 +7833,8 @@ bool ClusterIterator::IsNewline() const {
|
||||
|
||||
bool ClusterIterator::IsPunctuation() const {
|
||||
NS_ASSERTION(mCharIndex >= 0, "No cluster selected");
|
||||
// Return true for all Punctuation categories (Unicode general category P?),
|
||||
// and also for Symbol categories (S?) except for Modifier Symbol, which is
|
||||
// kept together with any adjacent letter/number. (Bug 1066756)
|
||||
const char16_t ch = mFrag->CharAt(AssertedCast<uint32_t>(mCharIndex));
|
||||
const uint8_t cat = unicode::GetGeneralCategory(ch);
|
||||
switch (cat) {
|
||||
case HB_UNICODE_GENERAL_CATEGORY_CONNECT_PUNCTUATION: /* Pc */
|
||||
if (ch == '_' && !StaticPrefs::layout_word_select_stop_at_underscore()) {
|
||||
return false;
|
||||
}
|
||||
[[fallthrough]];
|
||||
case HB_UNICODE_GENERAL_CATEGORY_DASH_PUNCTUATION: /* Pd */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_CLOSE_PUNCTUATION: /* Pe */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_FINAL_PUNCTUATION: /* Pf */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_INITIAL_PUNCTUATION: /* Pi */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_OTHER_PUNCTUATION: /* Po */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_OPEN_PUNCTUATION: /* Ps */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_CURRENCY_SYMBOL: /* Sc */
|
||||
// Deliberately omitted:
|
||||
// case HB_UNICODE_GENERAL_CATEGORY_MODIFIER_SYMBOL: /* Sk */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_MATH_SYMBOL: /* Sm */
|
||||
case HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL: /* So */
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return mozilla::IsPunctuationForWordSelect(ch);
|
||||
}
|
||||
|
||||
int32_t ClusterIterator::GetAfterInternal() const {
|
||||
|
Loading…
Reference in New Issue
Block a user