2002-11-22 22:36:42 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2002-11-22 22:36:42 +00:00
|
|
|
|
|
|
|
#include "nsSemanticUnitScanner.h"
|
|
|
|
|
2014-07-14 19:21:34 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsSemanticUnitScanner, nsSampleWordBreaker, nsISemanticUnitScanner)
|
2002-11-22 22:36:42 +00:00
|
|
|
|
|
|
|
nsSemanticUnitScanner::nsSemanticUnitScanner() : nsSampleWordBreaker()
|
|
|
|
{
|
|
|
|
/* member initializers and constructor code */
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSemanticUnitScanner::~nsSemanticUnitScanner()
|
|
|
|
{
|
|
|
|
/* destructor code */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* void start (in string characterSet); */
|
|
|
|
NS_IMETHODIMP nsSemanticUnitScanner::Start(const char *characterSet)
|
|
|
|
{
|
|
|
|
// do nothing for now.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* void next (in wstring text, in long length, in long pos, out boolean hasMoreUnits, out long begin, out long end); */
|
2014-01-04 15:02:17 +00:00
|
|
|
NS_IMETHODIMP nsSemanticUnitScanner::Next(const char16_t *text, int32_t length, int32_t pos, bool isLastBuffer, int32_t *begin, int32_t *end, bool *_retval)
|
2002-11-22 22:36:42 +00:00
|
|
|
{
|
|
|
|
// xxx need to bullet proff and check input pointer
|
2012-07-30 14:20:58 +00:00
|
|
|
// make sure begin, end and _retval is not nullptr here
|
2002-11-22 22:36:42 +00:00
|
|
|
|
|
|
|
// if we reach the end, just return
|
|
|
|
if (pos >= length) {
|
|
|
|
*begin = pos;
|
|
|
|
*end = pos;
|
2011-10-17 14:59:28 +00:00
|
|
|
*_retval = false;
|
2002-11-22 22:36:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t char_class = nsSampleWordBreaker::GetClass(text[pos]);
|
2002-11-22 22:36:42 +00:00
|
|
|
|
2003-05-23 22:06:40 +00:00
|
|
|
// if we are in chinese mode, return one han letter at a time
|
|
|
|
// we should not do this if we are in Japanese or Korean mode
|
2002-11-22 22:36:42 +00:00
|
|
|
if (kWbClassHanLetter == char_class) {
|
|
|
|
*begin = pos;
|
|
|
|
*end = pos+1;
|
2011-10-17 14:59:28 +00:00
|
|
|
*_retval = true;
|
2002-11-22 22:36:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t next;
|
2002-11-22 22:36:42 +00:00
|
|
|
// find the next "word"
|
2012-08-22 15:56:38 +00:00
|
|
|
next = NextWord(text, (uint32_t) length, (uint32_t) pos);
|
2002-11-22 22:36:42 +00:00
|
|
|
|
|
|
|
// if we don't have enough text to make decision, return
|
2005-08-22 03:00:06 +00:00
|
|
|
if (next == NS_WORDBREAKER_NEED_MORE_TEXT) {
|
2003-05-23 22:06:40 +00:00
|
|
|
*begin = pos;
|
|
|
|
*end = isLastBuffer ? length : pos;
|
|
|
|
*_retval = isLastBuffer;
|
|
|
|
return NS_OK;
|
2002-11-22 22:36:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if what we got is space or punct, look at the next break
|
2003-05-23 22:06:40 +00:00
|
|
|
if ((char_class == kWbClassSpace) || (char_class == kWbClassPunct)) {
|
|
|
|
// if the next "word" is not letters,
|
|
|
|
// call itself recursively with the new pos
|
|
|
|
return Next(text, length, next, isLastBuffer, begin, end, _retval);
|
2002-11-22 22:36:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// for the rest, return
|
|
|
|
*begin = pos;
|
|
|
|
*end = next;
|
2011-10-17 14:59:28 +00:00
|
|
|
*_retval = true;
|
2002-11-22 22:36:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|