InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PlatformChar.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Margie Vogel
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //========================================================================================
23 
24 #ifndef __PLATFORMCHAR__
25 #define __PLATFORMCHAR__
26 
27 #define USE_CHARCOUNTER_CLASS 0
28 #define USE_PLATFORMCHAR_CLASS 1
29 
30 #if USE_CHARCOUNTER_CLASS
31 class CharCounter
32 {
33 public:
34  CharCounter()
35  { fNumChars = 0; };
36 
37  CharCounter(int32 value)
38  { fNumChars = value; };
39 
40  inline void Set(int32 value)
41  { fNumChars = value; }
42 
43  inline int32 GetInt32() const
44  { return (fNumChars); }
45 
46  //----------OPERATORS---------------
47 
48  operator int32() const
49  { return fNumChars; }
50 
51  int32& operator = (const int32 &newValue)
52  { fNumChars = newValue; return fNumChars; }
53 
54  inline bool16 operator == (const CharCounter &value) const
55  { return (value.GetInt32() == fNumChars);}
56  inline bool16 operator != (const CharCounter &value) const
57  { return (value.GetInt32() != fNumChars);}
58 
59  inline bool16 operator < (const CharCounter &value) const
60  { return (fNumChars < value.GetInt32());}
61  inline bool16 operator > (const CharCounter &value) const
62  { return (fNumChars > value.GetInt32());}
63 
64  inline bool16 operator <= (const CharCounter &value) const
65  { return (fNumChars <= value.GetInt32()); }
66  inline bool16 operator >= (const CharCounter &value) const
67  { return (fNumChars >= value.GetInt32()); }
68 
69  inline CharCounter& operator ++ ()
70  { fNumChars++; return *this; }
71  inline CharCounter operator ++ (int)
72  { CharCounter temp = *this; ++*this; return temp; }
73  inline CharCounter operator += (const CharCounter &value)
74  { return (fNumChars += value.GetInt32()); }
75  inline CharCounter operator + (const CharCounter &value) const
76  { return (fNumChars + value.GetInt32()); }
77  inline CharCounter& operator -- ()
78  { fNumChars--; return *this; }
79  inline CharCounter operator -- (int)
80  { CharCounter temp = *this; --*this; return temp; }
81  inline CharCounter operator -= (const CharCounter &value)
82  { return (fNumChars -= value.GetInt32()); }
83  inline CharCounter operator - (const CharCounter &value) const
84  { return (fNumChars - value.GetInt32()); }
85 
86  inline CharCounter operator / (const CharCounter &value) const
87  { return (fNumChars / value.GetInt32()); }
88 
89  inline CharCounter operator * (const CharCounter &value) const
90  { return (fNumChars * value.GetInt32()); }
91 
92 private:
93  int32 fNumChars;
94 };
95 
96  // TODO: Take these out, use implicit convertion operator
97 inline int32 CharCounter_GetInt32(CharCounter i)
98  { return i.GetInt32(); }
99 inline void CharCounter_SetInt32(CharCounter i, int32 newValue)
100  { i.Set(newValue); }
101 #else
102 typedef int32 CharCounter;
103 
104 inline int32 CharCounter_GetInt32(CharCounter i)
105  { return i; }
106 inline void CharCounter_SetInt32(CharCounter i, int32 newValue)
107  { i = newValue; }
108 #endif
109 
110 class PMString;
112 {
113 public:
114  PlatformChar()
115  { fPlatformChar = 0; fScript = -1; };
116 
117  PlatformChar(char inChar, int8 script = -1)
118  { fPlatformChar = inChar; fScript = script; }
119 
120  PlatformChar(uchar16 inChar, int8 script = -1)
121  { fPlatformChar = inChar; fScript = script; }
122 
123  PlatformChar(uchar highByte, uchar lowByte, int8 script = -1)
124  { Set(highByte, lowByte, script); };
125 
131  inline void Set(uchar highByte, uchar lowByte, int8 script = -1)
132  {
133  fPlatformChar = highByte<<8 | lowByte;
134  fScript = script;
135 #ifdef DEBUG //following function will assert if fPlatformChar is invalid
137 #endif
138  }
139 
144  inline void Set(uchar16 inChar, int8 script = -1)
145  {
146  fPlatformChar = inChar;
147  fScript = script;
148  #ifdef DEBUG //following function will assert if fPlatformChar is invalid
150  #endif
151  }
152 
157  inline void Set(char inChar, int8 script = -1)
158  { fPlatformChar = inChar; fScript = script; }
159 
164  inline void Set(uchar inChar, int8 script = -1)
165  { fPlatformChar = inChar; fScript = script; }
166 
170  void SetFromUnicode(textchar uniChar);
171 
175  inline bool16 IsTwoByte() const
176  { return (fPlatformChar & 0xFF00); }
177 
181  inline bool16 IsLowASCII() const
182  { return (fPlatformChar < 128); }
183 
187  inline bool16 IsNumber() const
188  { return (fPlatformChar >= '0' && fPlatformChar <= '9'); }
189 
193  inline bool16 IsHexNumber() const
194  { return ((fPlatformChar >= '0' && fPlatformChar <= '9')
195  || (fPlatformChar >= 'a' && fPlatformChar <= 'f')
196  || (fPlatformChar >= 'A' && fPlatformChar <= 'F') ); }
197 
201  inline bool16 IsAlpha() const
202  { return ((fPlatformChar >= 'a' && fPlatformChar <= 'z') || (fPlatformChar >= 'A' && fPlatformChar <= 'Z')); }
203 
207  bool16 IsUpper() const;
208 
212  bool16 IsLower() const;
213 
217  PlatformChar ToUpper() const;
218 
222  PlatformChar ToLower() const;
223 
224  // character == methods
225  inline bool16 IsSpace() const
226  { return (fPlatformChar == ' '); }
227  inline bool16 IsComma() const
228  { return (fPlatformChar == ','); }
229  inline bool16 IsDash() const
230  { return (fPlatformChar == '-'); }
231  inline bool16 IsPeriod() const
232  { return (fPlatformChar == '.'); }
233  inline bool16 IsColon() const
234  { return (fPlatformChar == ':'); }
235  inline bool16 IsSemiColon() const
236  { return (fPlatformChar == ';'); }
237  inline bool16 IsBackSlash() const
238  { return (fPlatformChar == '\\'); }
239  inline bool16 IsSlash() const
240  { return (fPlatformChar == '/'); }
241  inline bool16 IsTilde() const
242  { return (fPlatformChar == '~'); }
243  inline bool16 IsLineBreakChar() const
244  { return (fPlatformChar == '\r' || fPlatformChar == '\n'); }
245  inline bool16 IsChar(char compareChar) const
246  { return (fPlatformChar == compareChar); }
247 
248  inline uchar HighByte() const
249  { return (uchar)(fPlatformChar >> 8); }
250  inline uchar LowByte() const
251  { return (uchar)(fPlatformChar & 0x00FF); }
252 
253  // this is used in epsparsecolor.cpp
254  // to compare hex values. That code really shouldnt be
255  // using a PMString as it seems to be parse a bunch of
256  // data. should remove this method.
264  uchar GetAsOneByteChar() const;
265 
269  uchar16 GetValue() const { return fPlatformChar; };
270 
271  inline int32 GetScript() const
272  { return (fScript); }
273 
274 
278  PMString *GetAsHexString() const;
279 
280  typedef enum {
281  kNoError = 0,
282  kNotNumber
283  } ConversionError;
289  int16 GetAsNumber( ConversionError *pError = nil ) const;
290  void SetFromNumber(int16 number);
291 
292 
293  inline bool16 IsValid() const
294  { return (fPlatformChar != 0); }
295 
296 
301  bool16 IsValidCharForScript(int32 script = -1) const;
302 
307  bool16 IsValidInUnicode(int32 script = -1) const;
308 
309 
310  //----------OPERATORS---------------
311 
312  inline bool16 operator == (const PlatformChar &value) const
313  { return (value.GetValue() == fPlatformChar);}
314  inline bool16 operator != (const PlatformChar &value) const
315  { return (value.GetValue() != fPlatformChar);}
316 
317  inline bool16 operator < (const PlatformChar &value) const
318  { return (fPlatformChar < value.GetValue());}
319  inline bool16 operator > (const PlatformChar &value) const
320  { return (fPlatformChar > value.GetValue());}
321 
322  inline bool16 operator <= (const PlatformChar &value) const
323  { return (fPlatformChar <= value.GetValue()); }
324  inline bool16 operator >= (const PlatformChar &value) const
325  { return (fPlatformChar >= value.GetValue()); }
326 
327  inline PlatformChar& operator ++ ()
328  { fPlatformChar++; return *this; }
329  inline PlatformChar operator ++ (int)
330  { PlatformChar temp = *this; ++*this; return temp; }
331  inline PlatformChar operator += (const PlatformChar &value)
332  { return PlatformChar(fPlatformChar += value.GetValue(), fScript); }
333  inline PlatformChar operator + (const PlatformChar &value) const
334  { return PlatformChar((uchar16)(fPlatformChar + value.GetValue()), fScript); }
335  inline PlatformChar& operator -- ()
336  { fPlatformChar--; return *this; }
337  inline PlatformChar operator -- (int)
338  { PlatformChar temp = *this; --*this; return temp; }
339  inline PlatformChar operator -= (const PlatformChar &value)
340  { return PlatformChar(fPlatformChar -= value.GetValue(), fScript); }
341  inline PlatformChar operator - (const PlatformChar &value) const
342  { return PlatformChar((uchar16)(fPlatformChar - value.GetValue()), fScript); }
343 
344 private:
345  uchar16 fPlatformChar;
346  int8 fScript;
347 };
348 #endif