1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/lwbrk/public/nsILineBreaker.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,74 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 +#ifndef nsILineBreaker_h__ 1.9 +#define nsILineBreaker_h__ 1.10 + 1.11 +#include "nsISupports.h" 1.12 + 1.13 +#include "nscore.h" 1.14 + 1.15 +#define NS_LINEBREAKER_NEED_MORE_TEXT -1 1.16 + 1.17 +// {0x4b0b9e04-6ffb-4647-aa5f-2fa2ebd883e8} 1.18 +#define NS_ILINEBREAKER_IID \ 1.19 +{0x4b0b9e04, 0x6ffb, 0x4647, \ 1.20 + {0xaa, 0x5f, 0x2f, 0xa2, 0xeb, 0xd8, 0x83, 0xe8}} 1.21 + 1.22 +class nsILineBreaker : public nsISupports 1.23 +{ 1.24 +public: 1.25 + NS_DECLARE_STATIC_IID_ACCESSOR(NS_ILINEBREAKER_IID) 1.26 + 1.27 + enum { 1.28 + kWordBreak_Normal = 0, // default 1.29 + kWordBreak_BreakAll = 1, // break all 1.30 + kWordBreak_KeepAll = 2 // always keep 1.31 + }; 1.32 + 1.33 + virtual int32_t Next( const char16_t* aText, uint32_t aLen, 1.34 + uint32_t aPos) = 0; 1.35 + 1.36 + virtual int32_t Prev( const char16_t* aText, uint32_t aLen, 1.37 + uint32_t aPos) = 0; 1.38 + 1.39 + // Call this on a word with whitespace at either end. We will apply JISx4051 1.40 + // rules to find breaks inside the word. aBreakBefore is set to the break- 1.41 + // before status of each character; aBreakBefore[0] will always be false 1.42 + // because we never return a break before the first character. 1.43 + // aLength is the length of the aText array and also the length of the aBreakBefore 1.44 + // output array. 1.45 + virtual void GetJISx4051Breaks(const char16_t* aText, uint32_t aLength, 1.46 + uint8_t aWordBreak, 1.47 + uint8_t* aBreakBefore) = 0; 1.48 + virtual void GetJISx4051Breaks(const uint8_t* aText, uint32_t aLength, 1.49 + uint8_t aWordBreak, 1.50 + uint8_t* aBreakBefore) = 0; 1.51 +}; 1.52 + 1.53 +NS_DEFINE_STATIC_IID_ACCESSOR(nsILineBreaker, NS_ILINEBREAKER_IID) 1.54 + 1.55 +static inline bool 1.56 +NS_IsSpace(char16_t u) 1.57 +{ 1.58 + return u == 0x0020 || // SPACE 1.59 + u == 0x0009 || // CHARACTER TABULATION 1.60 + u == 0x000D || // CARRIAGE RETURN 1.61 + u == 0x1680 || // OGHAM SPACE MARK 1.62 + (0x2000 <= u && u <= 0x2006) || // EN QUAD, EM QUAD, EN SPACE, 1.63 + // EM SPACE, THREE-PER-EM SPACE, 1.64 + // FOUR-PER-SPACE, SIX-PER-EM SPACE, 1.65 + (0x2008 <= u && u <= 0x200B) || // PUNCTUATION SPACE, THIN SPACE, 1.66 + // HAIR SPACE, ZERO WIDTH SPACE 1.67 + u == 0x205F; // MEDIUM MATHEMATICAL SPACE 1.68 +} 1.69 + 1.70 +static inline bool 1.71 +NS_NeedsPlatformNativeHandling(char16_t aChar) 1.72 +{ 1.73 + return (0x0e01 <= aChar && aChar <= 0x0fff) || // Thai, Lao, Tibetan 1.74 + (0x1780 <= aChar && aChar <= 0x17ff); // Khmer 1.75 +} 1.76 + 1.77 +#endif /* nsILineBreaker_h__ */