Bug 1097499 part 8 - Move CountGraphemeClusters to mozilla::unicode. r=emk
MozReview-Commit-ID: J9yR8RPs5u8
--- a/intl/unicharutil/util/nsUnicodeProperties.cpp
+++ b/intl/unicharutil/util/nsUnicodeProperties.cpp
@@ -488,11 +488,23 @@ ClusterIterator::Next()
mPos++;
}
}
NS_ASSERTION(mText < mPos && mPos <= mLimit,
"ClusterIterator::Next has overshot the string!");
}
+uint32_t
+CountGraphemeClusters(const char16_t* aText, uint32_t aLength)
+{
+ ClusterIterator iter(aText, aLength);
+ uint32_t result = 0;
+ while (!iter.AtEnd()) {
+ ++result;
+ iter.Next();
+ }
+ return result;
+}
+
} // end namespace unicode
} // end namespace mozilla
--- a/intl/unicharutil/util/nsUnicodeProperties.h
+++ b/intl/unicharutil/util/nsUnicodeProperties.h
@@ -146,13 +146,16 @@ public:
private:
const char16_t* mPos;
const char16_t* mLimit;
#ifdef DEBUG
const char16_t* mText;
#endif
};
+// Count the number of grapheme clusters in the given string
+uint32_t CountGraphemeClusters(const char16_t* aText, uint32_t aLength);
+
} // end namespace unicode
} // end namespace mozilla
#endif /* NS_UNICODEPROPERTIES_H */
--- a/layout/style/CounterStyleManager.cpp
+++ b/layout/style/CounterStyleManager.cpp
@@ -1841,29 +1841,16 @@ CounterStyle::IsDependentStyle() const
return true;
// BuiltinCounterStyle
default:
return false;
}
}
-static int32_t
-CountGraphemeClusters(const nsSubstring& aText)
-{
- using mozilla::unicode::ClusterIterator;
- ClusterIterator iter(aText.Data(), aText.Length());
- int32_t result = 0;
- while (!iter.AtEnd()) {
- ++result;
- iter.Next();
- }
- return result;
-}
-
void
CounterStyle::GetCounterText(CounterValue aOrdinal,
WritingMode aWritingMode,
nsSubstring& aResult,
bool& aIsRTL)
{
bool success = IsOrdinalInRange(aOrdinal);
aIsRTL = false;
@@ -1884,17 +1871,19 @@ CounterStyle::GetCounterText(CounterValu
ordinal, aWritingMode, initialText, aIsRTL);
// add pad & negative, build the final result
if (success) {
PadType pad;
GetPad(pad);
// We have to calculate the difference here since suffix part of negative
// sign may be appended to initialText later.
- int32_t diff = pad.width - CountGraphemeClusters(initialText);
+ int32_t diff = pad.width -
+ unicode::CountGraphemeClusters(initialText.Data(),
+ initialText.Length());
aResult.Truncate();
if (useNegativeSign && aOrdinal < 0) {
NegativeType negative;
GetNegative(negative);
aResult.Append(negative.before);
// There is nothing between the suffix part of negative and initial
// representation, so we append it directly here.
initialText.Append(negative.after);