mscorlib(4.0.0.0) API with additions
DecoderFallbackBuffer.cs
2 using System.Security;
3 
4 namespace System.Text
5 {
7  [__DynamicallyInvokable]
8  public abstract class DecoderFallbackBuffer
9  {
10  [SecurityCritical]
11  internal unsafe byte* byteStart;
12 
13  [SecurityCritical]
14  internal unsafe char* charEnd;
15 
18  [__DynamicallyInvokable]
19  public abstract int Remaining
20  {
21  [__DynamicallyInvokable]
22  get;
23  }
24 
30  [__DynamicallyInvokable]
31  public abstract bool Fallback(byte[] bytesUnknown, int index);
32 
35  [__DynamicallyInvokable]
36  public abstract char GetNextChar();
37 
41  [__DynamicallyInvokable]
42  public abstract bool MovePrevious();
43 
45  [__DynamicallyInvokable]
46  public virtual void Reset()
47  {
48  while (GetNextChar() != 0)
49  {
50  }
51  }
52 
53  [SecurityCritical]
54  internal unsafe void InternalReset()
55  {
56  byteStart = null;
57  Reset();
58  }
59 
60  [SecurityCritical]
61  internal unsafe void InternalInitialize(byte* byteStart, char* charEnd)
62  {
63  this.byteStart = byteStart;
64  this.charEnd = charEnd;
65  }
66 
67  [SecurityCritical]
68  internal unsafe virtual bool InternalFallback(byte[] bytes, byte* pBytes, ref char* chars)
69  {
70  if (Fallback(bytes, (int)(pBytes - byteStart - bytes.Length)))
71  {
72  char* ptr = chars;
73  bool flag = false;
74  char nextChar;
75  while ((nextChar = GetNextChar()) != 0)
76  {
77  if (char.IsSurrogate(nextChar))
78  {
79  if (char.IsHighSurrogate(nextChar))
80  {
81  if (flag)
82  {
83  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequenceNoIndex"));
84  }
85  flag = true;
86  }
87  else
88  {
89  if (!flag)
90  {
91  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequenceNoIndex"));
92  }
93  flag = false;
94  }
95  }
96  if (ptr >= charEnd)
97  {
98  return false;
99  }
100  char* intPtr = ptr;
101  ptr = intPtr + 1;
102  *intPtr = nextChar;
103  }
104  if (flag)
105  {
106  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequenceNoIndex"));
107  }
108  chars = ptr;
109  }
110  return true;
111  }
112 
113  [SecurityCritical]
114  internal unsafe virtual int InternalFallback(byte[] bytes, byte* pBytes)
115  {
116  if (Fallback(bytes, (int)(pBytes - byteStart - bytes.Length)))
117  {
118  int num = 0;
119  bool flag = false;
120  char nextChar;
121  while ((nextChar = GetNextChar()) != 0)
122  {
123  if (char.IsSurrogate(nextChar))
124  {
125  if (char.IsHighSurrogate(nextChar))
126  {
127  if (flag)
128  {
129  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequenceNoIndex"));
130  }
131  flag = true;
132  }
133  else
134  {
135  if (!flag)
136  {
137  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequenceNoIndex"));
138  }
139  flag = false;
140  }
141  }
142  num++;
143  }
144  if (flag)
145  {
146  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequenceNoIndex"));
147  }
148  return num;
149  }
150  return 0;
151  }
152 
153  internal void ThrowLastBytesRecursive(byte[] bytesUnknown)
154  {
155  StringBuilder stringBuilder = new StringBuilder(bytesUnknown.Length * 3);
156  int i;
157  for (i = 0; i < bytesUnknown.Length && i < 20; i++)
158  {
159  if (stringBuilder.Length > 0)
160  {
161  stringBuilder.Append(" ");
162  }
163  stringBuilder.Append(string.Format(CultureInfo.InvariantCulture, "\\x{0:X2}", bytesUnknown[i]));
164  }
165  if (i == 20)
166  {
167  stringBuilder.Append(" ...");
168  }
169  throw new ArgumentException(Environment.GetResourceString("Argument_RecursiveFallbackBytes", stringBuilder.ToString()), "bytesUnknown");
170  }
171 
173  [__DynamicallyInvokable]
175  {
176  }
177  }
178 }
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
Definition: CultureInfo.cs:263
abstract char GetNextChar()
When overridden in a derived class, retrieves the next character in the fallback buffer.
Definition: __Canon.cs:3
virtual void Reset()
Initializes all data and state information pertaining to this fallback buffer.
DecoderFallbackBuffer()
Initializes a new instance of the T:System.Text.DecoderFallbackBuffer class.
Provides a buffer that allows a fallback handler to return an alternate string to a decoder when it c...
abstract int Remaining
When overridden in a derived class, gets the number of characters in the current T:System....
abstract bool MovePrevious()
When overridden in a derived class, causes the next call to the M:System.Text.DecoderFallbackBuffer....
abstract bool Fallback(byte[] bytesUnknown, int index)
When overridden in a derived class, prepares the fallback buffer to handle the specified input byte s...
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16