2017-12-14 07:17:38 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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/. */
|
|
|
|
#ifndef mozilla_intl_WordBreaker_h__
|
|
|
|
#define mozilla_intl_WordBreaker_h__
|
|
|
|
|
2021-11-15 20:20:35 +03:00
|
|
|
#include <cstdint>
|
2017-12-14 07:17:38 +03:00
|
|
|
|
|
|
|
#define NS_WORDBREAKER_NEED_MORE_TEXT -1
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace intl {
|
|
|
|
|
2021-09-14 02:55:33 +03:00
|
|
|
struct WordRange {
|
2017-12-14 07:17:38 +03:00
|
|
|
uint32_t mBegin;
|
|
|
|
uint32_t mEnd;
|
2021-09-14 02:55:33 +03:00
|
|
|
};
|
2017-12-14 07:17:38 +03:00
|
|
|
|
2021-10-25 22:00:23 +03:00
|
|
|
class WordBreaker final {
|
2017-12-14 07:17:38 +03:00
|
|
|
public:
|
2021-10-25 22:00:23 +03:00
|
|
|
// WordBreaker is a utility class with only static methods. No need to
|
|
|
|
// instantiate it.
|
|
|
|
WordBreaker() = delete;
|
|
|
|
~WordBreaker() = delete;
|
2017-12-14 07:17:38 +03:00
|
|
|
|
2021-09-14 02:55:33 +03:00
|
|
|
// Find the word boundary by scanning forward and backward from aPos.
|
|
|
|
//
|
|
|
|
// @return WordRange where mBegin equals to the offset to first character in
|
|
|
|
// the word and mEnd equals to the offset to the last character plus 1. mEnd
|
|
|
|
// can be aLen if the desired word is at the end of aText.
|
|
|
|
//
|
|
|
|
// If aPos is already at the end of aText or beyond, both mBegin and mEnd
|
|
|
|
// equals to aLen.
|
2021-10-25 22:00:22 +03:00
|
|
|
static WordRange FindWord(const char16_t* aText, uint32_t aLen,
|
|
|
|
uint32_t aPos);
|
2021-09-08 07:19:38 +03:00
|
|
|
|
|
|
|
// Find the next word break opportunity starting from aPos + 1. It can return
|
|
|
|
// aLen if there's no break opportunity between [aPos + 1, aLen - 1].
|
|
|
|
//
|
|
|
|
// If aPos is already at the end of aText or beyond, i.e. aPos >= aLen, return
|
|
|
|
// NS_WORDBREAKER_NEED_MORE_TEXT.
|
2021-11-09 04:14:14 +03:00
|
|
|
//
|
|
|
|
// DEPRECATED: Use WordBreakIteratorUtf16 instead.
|
2021-10-25 22:00:22 +03:00
|
|
|
static int32_t Next(const char16_t* aText, uint32_t aLen, uint32_t aPos);
|
2017-12-14 07:17:38 +03:00
|
|
|
|
|
|
|
private:
|
2021-09-08 07:19:36 +03:00
|
|
|
enum WordBreakClass : uint8_t {
|
|
|
|
kWbClassSpace = 0,
|
|
|
|
kWbClassAlphaLetter,
|
|
|
|
kWbClassPunct,
|
|
|
|
kWbClassHanLetter,
|
|
|
|
kWbClassKatakanaLetter,
|
|
|
|
kWbClassHiraganaLetter,
|
|
|
|
kWbClassHWKatakanaLetter,
|
|
|
|
kWbClassScriptioContinua
|
|
|
|
};
|
|
|
|
|
|
|
|
static WordBreakClass GetClass(char16_t aChar);
|
2017-12-14 07:17:38 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace intl
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* mozilla_intl_WordBreaker_h__ */
|