mscorlib(4.0.0.0) API with additions
EncoderReplacementFallbackBuffer.cs
1 using System.Security;
2 
3 namespace System.Text
4 {
7  {
8  private string strDefault;
9 
10  private int fallbackCount = -1;
11 
12  private int fallbackIndex = -1;
13 
16  public override int Remaining
17  {
18  get
19  {
20  if (fallbackCount >= 0)
21  {
22  return fallbackCount;
23  }
24  return 0;
25  }
26  }
27 
31  {
32  strDefault = fallback.DefaultString + fallback.DefaultString;
33  }
34 
41  public override bool Fallback(char charUnknown, int index)
42  {
43  if (fallbackCount >= 1)
44  {
45  if (char.IsHighSurrogate(charUnknown) && fallbackCount >= 0 && char.IsLowSurrogate(strDefault[fallbackIndex + 1]))
46  {
47  ThrowLastCharRecursive(char.ConvertToUtf32(charUnknown, strDefault[fallbackIndex + 1]));
48  }
49  ThrowLastCharRecursive(charUnknown);
50  }
51  fallbackCount = strDefault.Length / 2;
52  fallbackIndex = -1;
53  return fallbackCount != 0;
54  }
55 
64  public override bool Fallback(char charUnknownHigh, char charUnknownLow, int index)
65  {
66  if (!char.IsHighSurrogate(charUnknownHigh))
67  {
68  throw new ArgumentOutOfRangeException("charUnknownHigh", Environment.GetResourceString("ArgumentOutOfRange_Range", 55296, 56319));
69  }
70  if (!char.IsLowSurrogate(charUnknownLow))
71  {
72  throw new ArgumentOutOfRangeException("CharUnknownLow", Environment.GetResourceString("ArgumentOutOfRange_Range", 56320, 57343));
73  }
74  if (fallbackCount >= 1)
75  {
76  ThrowLastCharRecursive(char.ConvertToUtf32(charUnknownHigh, charUnknownLow));
77  }
78  fallbackCount = strDefault.Length;
79  fallbackIndex = -1;
80  return fallbackCount != 0;
81  }
82 
85  public override char GetNextChar()
86  {
87  fallbackCount--;
88  fallbackIndex++;
89  if (fallbackCount < 0)
90  {
91  return '\0';
92  }
93  if (fallbackCount == int.MaxValue)
94  {
95  fallbackCount = -1;
96  return '\0';
97  }
98  return strDefault[fallbackIndex];
99  }
100 
104  public override bool MovePrevious()
105  {
106  if (fallbackCount >= -1 && fallbackIndex >= 0)
107  {
108  fallbackIndex--;
109  fallbackCount++;
110  return true;
111  }
112  return false;
113  }
114 
116  [SecuritySafeCritical]
117  public unsafe override void Reset()
118  {
119  fallbackCount = -1;
120  fallbackIndex = 0;
121  charStart = null;
122  bFallingBack = false;
123  }
124  }
125 }
EncoderReplacementFallbackBuffer(EncoderReplacementFallback fallback)
Initializes a new instance of the T:System.Text.EncoderReplacementFallbackBuffer class using the valu...
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
Provides a failure handling mechanism, called a fallback, for an input character that cannot be conve...
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
string DefaultString
Gets the replacement string that is the value of the T:System.Text.EncoderReplacementFallback object.
override bool MovePrevious()
Causes the next call to the M:System.Text.EncoderReplacementFallbackBuffer.GetNextChar method to acce...
unsafe override void Reset()
Initializes all internal state information and data in this instance of T:System.Text....
override bool Fallback(char charUnknownHigh, char charUnknownLow, int index)
Indicates whether a replacement string can be used when an input surrogate pair cannot be encoded,...
override bool Fallback(char charUnknown, int index)
Prepares the replacement fallback buffer to use the current replacement string.
override int Remaining
Gets the number of characters in the replacement fallback buffer that remain to be processed.
Provides a buffer that allows a fallback handler to return an alternate string to an encoder when it ...
override char GetNextChar()
Retrieves the next character in the replacement fallback buffer.
Represents a substitute input string that is used when the original input character cannot be encoded...