2
0

FF8TextEncoding.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. namespace OpenVIII.Encoding
  3. {
  4. public sealed class FF8TextEncoding : System.Text.Encoding
  5. {
  6. private readonly FF8TextEncoder _encoder;
  7. private readonly FF8TextDecoder _decoder;
  8. private static readonly Object _lock = new Object();
  9. private static volatile FF8TextEncoding _instance;
  10. public new static FF8TextEncoding Default
  11. {
  12. get
  13. {
  14. if (_instance != null)
  15. return _instance;
  16. lock (_lock)
  17. {
  18. if (_instance != null)
  19. return _instance;
  20. _instance = new FF8TextEncoding(FF8TextEncodingCodepage.Create());
  21. }
  22. return _instance;
  23. }
  24. }
  25. public FF8TextEncoding(FF8TextEncodingCodepage codepage)
  26. {
  27. _encoder = new FF8TextEncoder(codepage);
  28. _decoder = new FF8TextDecoder(codepage);
  29. }
  30. public override Int32 GetByteCount(Char[] chars, Int32 index, Int32 count)
  31. {
  32. return _encoder.GetByteCount(chars, index, count);
  33. }
  34. public override Int32 GetBytes(Char[] chars, Int32 charIndex, Int32 charCount, Byte[] bytes, Int32 byteIndex)
  35. {
  36. return _encoder.GetBytes(chars, charIndex, charCount, bytes, byteIndex);
  37. }
  38. public override Int32 GetCharCount(Byte[] bytes, Int32 index, Int32 count)
  39. {
  40. return _decoder.GetCharCount(bytes, index, count);
  41. }
  42. public override Int32 GetChars(Byte[] bytes, Int32 byteIndex, Int32 byteCount, Char[] chars, Int32 charIndex)
  43. {
  44. return _decoder.GetChars(bytes, byteIndex, byteCount, chars, charIndex);
  45. }
  46. public override Int32 GetMaxByteCount(Int32 charCount)
  47. {
  48. return _encoder.GetMaxByteCount(charCount);
  49. }
  50. public override Int32 GetMaxCharCount(Int32 byteCount)
  51. {
  52. return _decoder.GetMaxCharCount(byteCount);
  53. }
  54. }
  55. }