|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef __WEBTEXTFORMATMASK_H__ |
|
19 #define __WEBTEXTFORMATMASK_H__ |
|
20 |
|
21 #include <unicode/umachine.h> |
|
22 #include <e32cmn.h> |
|
23 #include <ctype.h> |
|
24 |
|
25 typedef enum { |
|
26 |
|
27 ELeLoSymPuc, |
|
28 ELeUpSymPuc, |
|
29 ENumSymPuc, |
|
30 ENumChar, |
|
31 ELeLoNumSymPuc, |
|
32 ELeUpNumSymPuc, |
|
33 EAnyLow, |
|
34 EAnyUpper, |
|
35 EStatic, |
|
36 ENoFormat |
|
37 |
|
38 }TInputFormatMaskType; |
|
39 |
|
40 namespace WebCore |
|
41 { |
|
42 class Frame; |
|
43 class String; |
|
44 } |
|
45 |
|
46 class WebTextFormatMask; |
|
47 |
|
48 class MaskBase |
|
49 { |
|
50 public: |
|
51 friend class WebTextFormatMask; |
|
52 |
|
53 MaskBase() : m_next(0) {} |
|
54 virtual ~MaskBase() { m_next=NULL; } |
|
55 |
|
56 virtual bool check(UChar) = 0; |
|
57 virtual TInputFormatMaskType getInputFormatMaskType() = 0; |
|
58 virtual MaskBase* nextMask() { return m_next; } |
|
59 virtual bool isComposite() { return false; } |
|
60 virtual int multitude() const { return 1; } |
|
61 |
|
62 protected: |
|
63 MaskBase* m_next; |
|
64 |
|
65 private: |
|
66 MaskBase(const MaskBase&); // not implemented |
|
67 MaskBase& operator=(const MaskBase&); // not implemented |
|
68 }; |
|
69 |
|
70 class MaskSingle : public MaskBase |
|
71 { |
|
72 public: |
|
73 MaskSingle(TInputFormatMaskType t) : m_type(t) {} |
|
74 bool check(UChar); |
|
75 TInputFormatMaskType getInputFormatMaskType() { return m_type; }; |
|
76 |
|
77 private: |
|
78 TInputFormatMaskType m_type; |
|
79 }; |
|
80 |
|
81 class MaskStatic : public MaskBase |
|
82 { |
|
83 public: |
|
84 MaskStatic(UChar ch) : m_char(ch) {} |
|
85 bool check(UChar); |
|
86 UChar getStatic() { return m_char; } |
|
87 TInputFormatMaskType getInputFormatMaskType() { return EStatic; }; |
|
88 |
|
89 private: |
|
90 UChar m_char; |
|
91 }; |
|
92 |
|
93 class MaskComposite : public MaskSingle |
|
94 { |
|
95 public: |
|
96 MaskComposite(TInputFormatMaskType, int); |
|
97 |
|
98 MaskBase* nextMask(); |
|
99 bool isComposite() { return true; } |
|
100 int multitude() const { return m_length; } |
|
101 |
|
102 private: |
|
103 int m_offset; |
|
104 int m_length; |
|
105 }; |
|
106 |
|
107 class WebTextFormatMask |
|
108 { |
|
109 public: |
|
110 struct ErrorBlock |
|
111 { |
|
112 int m_start; |
|
113 int m_extent; |
|
114 |
|
115 ErrorBlock() : m_start(-1), m_extent(-1) {} |
|
116 void set(int s, int e) { m_start = s; m_extent = e; } |
|
117 }; |
|
118 |
|
119 WebTextFormatMask(const WebCore::String&, bool); |
|
120 ~WebTextFormatMask(); |
|
121 |
|
122 bool checkText(const WebCore::String&, ErrorBlock&); |
|
123 |
|
124 public: |
|
125 int getMultitude(); |
|
126 TInputFormatMaskType getInputFormatMaskType(WebCore::Frame *frame, int aOffset); |
|
127 |
|
128 public: |
|
129 static bool checkTelWtaiNumber(const WebCore::String&, bool); |
|
130 |
|
131 private: |
|
132 void buildMaskList(const WebCore::String&); |
|
133 bool appendMask(MaskBase* m); |
|
134 |
|
135 void clearMaskList(); |
|
136 |
|
137 bool createMask(TInputFormatMaskType, int&); |
|
138 bool createStaticMask(const UChar*&); |
|
139 int parseMultitude(const UChar*&, bool&); |
|
140 |
|
141 private: |
|
142 MaskBase* m_masks; |
|
143 MaskBase* m_currentMask; |
|
144 bool m_acceptAll; |
|
145 bool m_inputRequired; |
|
146 }; |
|
147 |
|
148 #endif |