Line data Source code
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 :
6 : #ifndef IrishCasing_h_
7 : #define IrishCasing_h_
8 :
9 : #include <stdint.h>
10 : #include "mozilla/Attributes.h"
11 :
12 : namespace mozilla {
13 :
14 : class IrishCasing {
15 : private:
16 : enum IrishStates {
17 : kState_Start,
18 : kState_InWord,
19 : kState_b,
20 : kState_bh,
21 : kState_d,
22 : kState_g,
23 : kState_h,
24 : kState_m,
25 : kState_n,
26 : kState_nt_,
27 : kState_t,
28 : kState_ts,
29 : kNumStates
30 : };
31 :
32 : enum IrishClasses {
33 : kClass_b,
34 : kClass_B,
35 : kClass_cC,
36 : kClass_d,
37 : kClass_DG,
38 : kClass_fF,
39 : kClass_g,
40 : kClass_h,
41 : kClass_lLNrR,
42 : kClass_m,
43 : kClass_n,
44 : kClass_pP,
45 : kClass_sS,
46 : kClass_t,
47 : kClass_T,
48 : kClass_vowel,
49 : kClass_Vowel,
50 : kClass_hyph,
51 : kClass_letter,
52 : kClass_other,
53 : kNumClasses
54 : };
55 :
56 : public:
57 : class State {
58 : friend class IrishCasing;
59 :
60 : public:
61 0 : State()
62 0 : : mState(kState_Start)
63 : {
64 0 : }
65 :
66 : MOZ_IMPLICIT State(const IrishStates& aState)
67 : : mState(aState)
68 : {
69 : }
70 :
71 0 : void Reset()
72 : {
73 0 : mState = kState_Start;
74 0 : }
75 :
76 0 : operator IrishStates() const
77 : {
78 0 : return mState;
79 : }
80 :
81 : private:
82 0 : explicit State(uint8_t aState)
83 0 : : mState(IrishStates(aState))
84 : {
85 0 : }
86 :
87 : uint8_t GetClass(uint32_t aCh);
88 :
89 : IrishStates mState;
90 : };
91 :
92 : enum {
93 : kMarkPositionFlag = 0x80,
94 : kActionMask = 0x30,
95 : kActionShift = 4,
96 : kNextStateMask = 0x0f
97 : };
98 :
99 : static const uint8_t sUppercaseStateTable[kNumClasses][kNumStates];
100 : static const uint8_t sLcClasses[26];
101 : static const uint8_t sUcClasses[26];
102 :
103 : static uint32_t UpperCase(uint32_t aCh, State& aState,
104 : bool& aMarkPos, uint8_t& aAction);
105 :
106 0 : static bool IsUpperVowel(uint32_t aCh)
107 : {
108 0 : return GetClass(aCh) == kClass_Vowel;
109 : }
110 :
111 : private:
112 : static uint8_t GetClass(uint32_t aCh);
113 : };
114 :
115 : } // namespace mozilla
116 :
117 : #endif
|