This source file includes following definitions.
- numGraphemeClusters
- numCharactersInGraphemeClusters
#include "config.h"
#include "platform/text/TextBreakIterator.h"
namespace WebCore {
unsigned numGraphemeClusters(const String& string)
{
unsigned stringLength = string.length();
if (!stringLength)
return 0;
if (string.is8Bit() && !string.contains('\r'))
return stringLength;
NonSharedCharacterBreakIterator it(string);
if (!it)
return stringLength;
unsigned num = 0;
while (it.next() != TextBreakDone)
++num;
return num;
}
unsigned numCharactersInGraphemeClusters(const String& string, unsigned numGraphemeClusters)
{
unsigned stringLength = string.length();
if (!stringLength)
return 0;
if (string.is8Bit() && !string.contains('\r'))
return std::min(stringLength, numGraphemeClusters);
NonSharedCharacterBreakIterator it(string);
if (!it)
return std::min(stringLength, numGraphemeClusters);
for (unsigned i = 0; i < numGraphemeClusters; ++i) {
if (it.next() == TextBreakDone)
return stringLength;
}
return it.current();
}
}