Bug 1760684 [wpt PR 33213] - Update wpt metadata, a=testonly
[gecko.git] / intl / lwbrk / WordBreaker.h
blobf508e41ba6cf6fe55431d8ce93170165ce3c3279
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_intl_WordBreaker_h__
6 #define mozilla_intl_WordBreaker_h__
8 #include <cstdint>
10 #define NS_WORDBREAKER_NEED_MORE_TEXT -1
12 namespace mozilla {
13 namespace intl {
15 struct WordRange {
16 uint32_t mBegin;
17 uint32_t mEnd;
20 class WordBreaker final {
21 public:
22 // WordBreaker is a utility class with only static methods. No need to
23 // instantiate it.
24 WordBreaker() = delete;
25 ~WordBreaker() = delete;
27 // Find the word boundary by scanning forward and backward from aPos.
29 // @return WordRange where mBegin equals to the offset to first character in
30 // the word and mEnd equals to the offset to the last character plus 1. mEnd
31 // can be aLen if the desired word is at the end of aText.
33 // If aPos is already at the end of aText or beyond, both mBegin and mEnd
34 // equals to aLen.
35 static WordRange FindWord(const char16_t* aText, uint32_t aLen,
36 uint32_t aPos);
38 // Find the next word break opportunity starting from aPos + 1. It can return
39 // aLen if there's no break opportunity between [aPos + 1, aLen - 1].
41 // If aPos is already at the end of aText or beyond, i.e. aPos >= aLen, return
42 // NS_WORDBREAKER_NEED_MORE_TEXT.
44 // DEPRECATED: Use WordBreakIteratorUtf16 instead.
45 static int32_t Next(const char16_t* aText, uint32_t aLen, uint32_t aPos);
47 private:
48 enum WordBreakClass : uint8_t {
49 kWbClassSpace = 0,
50 kWbClassAlphaLetter,
51 kWbClassPunct,
52 kWbClassHanLetter,
53 kWbClassKatakanaLetter,
54 kWbClassHiraganaLetter,
55 kWbClassHWKatakanaLetter,
56 kWbClassScriptioContinua
59 static WordBreakClass GetClass(char16_t aChar);
62 } // namespace intl
63 } // namespace mozilla
65 #endif /* mozilla_intl_WordBreaker_h__ */