mscorlib(4.0.0.0) API with additions
EncoderFallbackBuffer.cs
1 using System.Security;
2 
3 namespace System.Text
4 {
6  [__DynamicallyInvokable]
7  public abstract class EncoderFallbackBuffer
8  {
9  [SecurityCritical]
10  internal unsafe char* charStart;
11 
12  [SecurityCritical]
13  internal unsafe char* charEnd;
14 
15  internal EncoderNLS encoder;
16 
17  internal bool setEncoder;
18 
19  internal bool bUsedEncoder;
20 
21  internal bool bFallingBack;
22 
23  internal int iRecursionCount;
24 
25  private const int iMaxRecursion = 250;
26 
29  [__DynamicallyInvokable]
30  public abstract int Remaining
31  {
32  [__DynamicallyInvokable]
33  get;
34  }
35 
41  [__DynamicallyInvokable]
42  public abstract bool Fallback(char charUnknown, int index);
43 
50  [__DynamicallyInvokable]
51  public abstract bool Fallback(char charUnknownHigh, char charUnknownLow, int index);
52 
55  [__DynamicallyInvokable]
56  public abstract char GetNextChar();
57 
61  [__DynamicallyInvokable]
62  public abstract bool MovePrevious();
63 
65  [__DynamicallyInvokable]
66  public virtual void Reset()
67  {
68  while (GetNextChar() != 0)
69  {
70  }
71  }
72 
73  [SecurityCritical]
74  internal unsafe void InternalReset()
75  {
76  charStart = null;
77  bFallingBack = false;
78  iRecursionCount = 0;
79  Reset();
80  }
81 
82  [SecurityCritical]
83  internal unsafe void InternalInitialize(char* charStart, char* charEnd, EncoderNLS encoder, bool setEncoder)
84  {
85  this.charStart = charStart;
86  this.charEnd = charEnd;
87  this.encoder = encoder;
88  this.setEncoder = setEncoder;
89  bUsedEncoder = false;
90  bFallingBack = false;
91  iRecursionCount = 0;
92  }
93 
94  internal char InternalGetNextChar()
95  {
96  char nextChar = GetNextChar();
97  bFallingBack = (nextChar != '\0');
98  if (nextChar == '\0')
99  {
100  iRecursionCount = 0;
101  }
102  return nextChar;
103  }
104 
105  [SecurityCritical]
106  internal unsafe virtual bool InternalFallback(char ch, ref char* chars)
107  {
108  int index = (int)(chars - charStart) - 1;
109  if (char.IsHighSurrogate(ch))
110  {
111  if (chars >= charEnd)
112  {
113  if (encoder != null && !encoder.MustFlush)
114  {
115  if (setEncoder)
116  {
117  bUsedEncoder = true;
118  encoder.charLeftOver = ch;
119  }
120  bFallingBack = false;
121  return false;
122  }
123  }
124  else
125  {
126  char c = *chars;
127  if (char.IsLowSurrogate(c))
128  {
129  if (bFallingBack && iRecursionCount++ > 250)
130  {
131  ThrowLastCharRecursive(char.ConvertToUtf32(ch, c));
132  }
133  chars++;
134  bFallingBack = Fallback(ch, c, index);
135  return bFallingBack;
136  }
137  }
138  }
139  if (bFallingBack && iRecursionCount++ > 250)
140  {
141  ThrowLastCharRecursive(ch);
142  }
143  bFallingBack = Fallback(ch, index);
144  return bFallingBack;
145  }
146 
147  internal void ThrowLastCharRecursive(int charRecursive)
148  {
149  throw new ArgumentException(Environment.GetResourceString("Argument_RecursiveFallback", charRecursive), "chars");
150  }
151 
153  [__DynamicallyInvokable]
155  {
156  }
157  }
158 }
EncoderFallbackBuffer()
Initializes a new instance of the T:System.Text.EncoderFallbackBuffer class.
Definition: __Canon.cs:3
abstract int Remaining
When overridden in a derived class, gets the number of characters in the current T:System....
abstract char GetNextChar()
When overridden in a derived class, retrieves the next character in the fallback buffer.
virtual void Reset()
Initializes all data and state information pertaining to this fallback buffer.
Provides a buffer that allows a fallback handler to return an alternate string to an encoder when it ...
abstract bool Fallback(char charUnknown, int index)
When overridden in a derived class, prepares the fallback buffer to handle the specified input charac...
abstract bool MovePrevious()
When overridden in a derived class, causes the next call to the M:System.Text.EncoderFallbackBuffer....