InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TextCharBuffer.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Nat McCully
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 __TextCharBuffer__
25 #define __TextCharBuffer__
26 
27 
28 #include "WideString.h"
29 
30 
31 inline bool IsHighSurrogate(UTF16TextChar c)
32 { return (c >= kTextChar_HighSurrogateStart && c <= kTextChar_HighSurrogateEnd); }
33 
34 inline bool IsLowSurrogate(UTF16TextChar c)
35 { return (c >= kTextChar_LowSurrogateStart && c <= kTextChar_LowSurrogateEnd); }
36 
37 inline UTF32TextChar BuildUTF32Char(UTF16TextChar hi, UTF16TextChar low)
38 { return ((hi - 0xD800) * 0x400 + (low - 0xDC00) + 0x10000); }
39 
40 
41 
50 {
51  public:
53  { fCharCount = e - b; }
54  TextCharBuffer(const TextCharBuffer& o) :fBegin(o.fBegin), fEnd(o.fEnd), fCharCount(o.fCharCount)
55  {}
56  explicit TextCharBuffer(const WideString& s) :fBegin(s.begin_raw()), fEnd(s.end_raw()), fCharCount(s.Length())
57  {}
58  TextCharBuffer(const UTF16TextChar *begin, const UTF16TextChar *end, int32 charCount)
59  :fBegin(begin), fEnd(end), fCharCount(charCount)
60  {}
61 
66  { return !IsHighSurrogate(*fBegin) ? *fBegin : BuildUTF32Char(fBegin[0], fBegin[1]); }
67 
72  const UTF16TextChar* begin_raw() const
73  { return fBegin; }
78  const UTF16TextChar* end_raw() const
79  { return fEnd; }
80 
84  int32 CharCount() const
85  { return fCharCount; }
86 
89  void RemoveFirst()
90  { --fCharCount;
91  if (!IsHighSurrogate(*fBegin))
92  ++fBegin; // not high surrogate
93  else
94  fBegin += 2; }
95 
98  void RemoveLast()
99  { --fCharCount;
100  --fEnd;
101  if (IsLowSurrogate(*fEnd))
102  --fEnd; } // was low surrogate
103 
104  private:
105  TextCharBuffer() :fBegin(nil), fEnd(nil), fCharCount(0)
106  {}
107 
108  const UTF16TextChar *fBegin;
109  const UTF16TextChar *fEnd;
110  int32 fCharCount;
111 };
112 
113 
114 #endif
115  // __TextCharBuffer__