Bug 1097499 part 8 - Move CountGraphemeClusters to mozilla::unicode. r=emk

MozReview-Commit-ID: J9yR8RPs5u8

--HG--
extra : source : 7b937b3ba984e84da808cd072037726b56da1826
This commit is contained in:
Xidorn Quan 2016-04-22 09:18:41 +10:00
parent 20a1eb1cd7
commit 19931babd5
3 changed files with 18 additions and 14 deletions

View File

@ -493,6 +493,18 @@ ClusterIterator::Next()
"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

View File

@ -151,6 +151,9 @@ private:
#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

View File

@ -1846,19 +1846,6 @@ CounterStyle::IsDependentStyle() const
}
}
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,
@ -1889,7 +1876,9 @@ CounterStyle::GetCounterText(CounterValue aOrdinal,
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;