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:
State()61     State() : mState(kState_Start) {}
62 
State(const IrishStates & aState)63     MOZ_IMPLICIT State(const IrishStates& aState) : mState(aState) {}
64 
Reset()65     void Reset() { mState = kState_Start; }
66 
IrishStates()67     operator IrishStates() const { return mState; }
68 
69    private:
State(uint8_t aState)70     explicit State(uint8_t aState) : mState(IrishStates(aState)) {}
71 
72     uint8_t GetClass(uint32_t aCh);
73 
74     IrishStates mState;
75   };
76 
77   enum {
78     kMarkPositionFlag = 0x80,
79     kActionMask = 0x30,
80     kActionShift = 4,
81     kNextStateMask = 0x0f
82   };
83 
84   static const uint8_t sUppercaseStateTable[kNumClasses][kNumStates];
85   static const uint8_t sLcClasses[26];
86   static const uint8_t sUcClasses[26];
87 
88   static uint32_t UpperCase(uint32_t aCh, State& aState, bool& aMarkPos,
89                             uint8_t& aAction);
90 
IsUpperVowel(uint32_t aCh)91   static bool IsUpperVowel(uint32_t aCh) {
92     return GetClass(aCh) == kClass_Vowel;
93   }
94 
95  private:
96   static uint8_t GetClass(uint32_t aCh);
97 };
98 
99 }  // namespace mozilla
100 
101 #endif
102