michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #ifndef nsILineBreaker_h__ michael@0: #define nsILineBreaker_h__ michael@0: michael@0: #include "nsISupports.h" michael@0: michael@0: #include "nscore.h" michael@0: michael@0: #define NS_LINEBREAKER_NEED_MORE_TEXT -1 michael@0: michael@0: // {0x4b0b9e04-6ffb-4647-aa5f-2fa2ebd883e8} michael@0: #define NS_ILINEBREAKER_IID \ michael@0: {0x4b0b9e04, 0x6ffb, 0x4647, \ michael@0: {0xaa, 0x5f, 0x2f, 0xa2, 0xeb, 0xd8, 0x83, 0xe8}} michael@0: michael@0: class nsILineBreaker : public nsISupports michael@0: { michael@0: public: michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(NS_ILINEBREAKER_IID) michael@0: michael@0: enum { michael@0: kWordBreak_Normal = 0, // default michael@0: kWordBreak_BreakAll = 1, // break all michael@0: kWordBreak_KeepAll = 2 // always keep michael@0: }; michael@0: michael@0: virtual int32_t Next( const char16_t* aText, uint32_t aLen, michael@0: uint32_t aPos) = 0; michael@0: michael@0: virtual int32_t Prev( const char16_t* aText, uint32_t aLen, michael@0: uint32_t aPos) = 0; michael@0: michael@0: // Call this on a word with whitespace at either end. We will apply JISx4051 michael@0: // rules to find breaks inside the word. aBreakBefore is set to the break- michael@0: // before status of each character; aBreakBefore[0] will always be false michael@0: // because we never return a break before the first character. michael@0: // aLength is the length of the aText array and also the length of the aBreakBefore michael@0: // output array. michael@0: virtual void GetJISx4051Breaks(const char16_t* aText, uint32_t aLength, michael@0: uint8_t aWordBreak, michael@0: uint8_t* aBreakBefore) = 0; michael@0: virtual void GetJISx4051Breaks(const uint8_t* aText, uint32_t aLength, michael@0: uint8_t aWordBreak, michael@0: uint8_t* aBreakBefore) = 0; michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(nsILineBreaker, NS_ILINEBREAKER_IID) michael@0: michael@0: static inline bool michael@0: NS_IsSpace(char16_t u) michael@0: { michael@0: return u == 0x0020 || // SPACE michael@0: u == 0x0009 || // CHARACTER TABULATION michael@0: u == 0x000D || // CARRIAGE RETURN michael@0: u == 0x1680 || // OGHAM SPACE MARK michael@0: (0x2000 <= u && u <= 0x2006) || // EN QUAD, EM QUAD, EN SPACE, michael@0: // EM SPACE, THREE-PER-EM SPACE, michael@0: // FOUR-PER-SPACE, SIX-PER-EM SPACE, michael@0: (0x2008 <= u && u <= 0x200B) || // PUNCTUATION SPACE, THIN SPACE, michael@0: // HAIR SPACE, ZERO WIDTH SPACE michael@0: u == 0x205F; // MEDIUM MATHEMATICAL SPACE michael@0: } michael@0: michael@0: static inline bool michael@0: NS_NeedsPlatformNativeHandling(char16_t aChar) michael@0: { michael@0: return (0x0e01 <= aChar && aChar <= 0x0fff) || // Thai, Lao, Tibetan michael@0: (0x1780 <= aChar && aChar <= 0x17ff); // Khmer michael@0: } michael@0: michael@0: #endif /* nsILineBreaker_h__ */