This source file includes following definitions.
- endOfFirstWordBoundaryContext
- startOfLastWordBoundaryContext
- findNextWordFromIndex
- findWordBoundary
#include "config.h"
#include "platform/text/TextBoundaries.h"
#include "platform/text/TextBreakIterator.h"
#include "wtf/text/StringImpl.h"
using namespace WTF;
using namespace Unicode;
namespace WebCore {
int endOfFirstWordBoundaryContext(const UChar* characters, int length)
{
for (int i = 0; i < length; ) {
int first = i;
UChar32 ch;
U16_NEXT(characters, i, length, ch);
if (!requiresContextForWordBoundary(ch))
return first;
}
return length;
}
int startOfLastWordBoundaryContext(const UChar* characters, int length)
{
for (int i = length; i > 0; ) {
int last = i;
UChar32 ch;
U16_PREV(characters, 0, i, ch);
if (!requiresContextForWordBoundary(ch))
return last;
}
return 0;
}
int findNextWordFromIndex(const UChar* chars, int len, int position, bool forward)
{
TextBreakIterator* it = wordBreakIterator(chars, len);
if (forward) {
position = it->following(position);
while (position != TextBreakDone) {
if (position < len && isAlphanumeric(chars[position - 1]))
return position;
position = it->following(position);
}
return len;
} else {
position = it->preceding(position);
while (position != TextBreakDone) {
if (position > 0 && isAlphanumeric(chars[position]))
return position;
position = it->preceding(position);
}
return 0;
}
}
void findWordBoundary(const UChar* chars, int len, int position, int* start, int* end)
{
TextBreakIterator* it = wordBreakIterator(chars, len);
*end = it->following(position);
if (*end < 0)
*end = it->last();
*start = it->previous();
}
}