// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0
+#if NET_2_0 || NET_2_0_BOOTSTRAP
namespace System.Text
{
+ // This DecoderFallbackBuffer is simple. It ignores the input buffers.
+ // DecoderFallbackBuffer users could implement their own complex
+ // fallback buffers.
+
public sealed class DecoderReplacementFallbackBuffer
: DecoderFallbackBuffer
{
- DecoderReplacementFallback fallback;
+ bool fallback_assigned;
+ int current;
+ string replacement;
public DecoderReplacementFallbackBuffer (
DecoderReplacementFallback fallback)
{
- this.fallback = fallback;
+ if (fallback == null)
+ throw new ArgumentNullException ("fallback");
+ replacement = fallback.DefaultString;
+ current = 0;
}
- [MonoTODO]
public override int Remaining {
- get { throw new NotImplementedException (); }
+ get { return replacement.Length - current; }
}
- [MonoTODO]
public override bool Fallback (byte [] bytesUnknown, int index)
{
- throw new NotImplementedException ();
+ if (bytesUnknown == null)
+ throw new ArgumentNullException ("bytesUnknown");
+ if (fallback_assigned && Remaining != 0)
+ throw new ArgumentException ("Reentrant Fallback method invocation occured. It might be because either this FallbackBuffer is incorrectly shared by multiple threads, invoked inside Encoding recursively, or Reset invocation is forgotten.");
+ if (index < 0 || bytesUnknown.Length < index)
+ throw new ArgumentOutOfRangeException ("index");
+ fallback_assigned = true;
+ current = 0;
+
+ return replacement.Length > 0;
}
- [MonoTODO]
public override char GetNextChar ()
{
- throw new NotImplementedException ();
+ if (current >= replacement.Length)
+ return char.MinValue;
+ return replacement [current++];
}
- [MonoTODO]
public override bool MovePrevious ()
{
- throw new NotImplementedException ();
+ if (current == 0)
+ return false;
+ current--;
+ return true;
+ }
+
+ public override void Reset ()
+ {
+ current = 0;
}
}
}