Bug 1745113 Part 3 - Change CountGraphemeClusters() to take a Span parameter. r=jfkthame

Differential Revision: https://phabricator.services.mozilla.com/D135641
This commit is contained in:
Ting-Yu Lin
2022-01-13 18:36:04 +00:00
parent 2790167c28
commit 18989890b3
4 changed files with 8 additions and 8 deletions

View File

@@ -167,8 +167,9 @@ bool IsClusterExtender(uint32_t aCh, uint8_t aCategory) {
(aCh >= 0xe0020 && aCh <= 0xe007f)); // emoji (flag) tag characters
}
uint32_t CountGraphemeClusters(const char16_t* aText, uint32_t aLength) {
intl::GraphemeClusterBreakIteratorUtf16 iter(aText, aLength);
uint32_t CountGraphemeClusters(Span<const char16_t> aText) {
intl::GraphemeClusterBreakIteratorUtf16 iter(aText.Elements(),
aText.Length());
uint32_t result = 0;
while (!iter.AtEnd()) {
++result;

View File

@@ -9,6 +9,7 @@
#include "mozilla/intl/UnicodeProperties.h"
#include "mozilla/Span.h"
#include "nsBidiUtils.h"
#include "nsUGenCategory.h"
#include "harfbuzz/hb.h"
@@ -159,7 +160,7 @@ inline bool IsClusterExtender(uint32_t aCh) {
}
// Count the number of grapheme clusters in the given string
uint32_t CountGraphemeClusters(const char16_t* aText, uint32_t aLength);
uint32_t CountGraphemeClusters(Span<const char16_t> aText);
// Determine whether a character is a "combining diacritic" for the purpose
// of diacritic-insensitive text search. Examples of such characters include

View File

@@ -10481,7 +10481,7 @@ uint32_t nsTextFrame::CountGraphemeClusters() const {
nsAutoString content;
frag->AppendTo(content, AssertedCast<uint32_t>(GetContentOffset()),
AssertedCast<uint32_t>(GetContentLength()));
return unicode::CountGraphemeClusters(content.Data(), content.Length());
return unicode::CountGraphemeClusters(content);
}
bool nsTextFrame::HasNonSuppressedText() const {

View File

@@ -1681,10 +1681,8 @@ void CounterStyle::GetCounterText(CounterValue aOrdinal,
GetPad(pad);
int32_t diff =
pad.width -
narrow_cast<int32_t>(
unicode::CountGraphemeClusters(initialText.Data(),
initialText.Length()) +
unicode::CountGraphemeClusters(aResult.Data(), aResult.Length()));
narrow_cast<int32_t>(unicode::CountGraphemeClusters(initialText) +
unicode::CountGraphemeClusters(aResult));
if (diff > 0) {
auto length = pad.symbol.Length();
if (diff > LENGTH_LIMIT || length > LENGTH_LIMIT ||