ASCIIEncoding.Silverlight.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Net;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Documents;
  6. using System.Windows.Ink;
  7. using System.Windows.Input;
  8. using System.Windows.Media;
  9. using System.Windows.Media.Animation;
  10. using System.Windows.Shapes;
  11. using System.Text;
  12. namespace Renci.SshNet.Common
  13. {
  14. public partial class ASCIIEncoding : Encoding
  15. {
  16. /// <summary>
  17. /// Gets the name registered with the
  18. /// Internet Assigned Numbers Authority (IANA) for the current encoding.
  19. /// </summary>
  20. /// <returns>
  21. /// The IANA name for the current <see cref="System.Text.Encoding"/>.
  22. /// </returns>
  23. public override string WebName
  24. {
  25. get
  26. {
  27. return "iso-8859-1";
  28. }
  29. }
  30. /// <summary>
  31. /// Decodes all the bytes in the specified byte array into a string.
  32. /// </summary>
  33. /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
  34. /// <returns>
  35. /// A <see cref="T:System.String"/> containing the results of decoding the specified sequence of bytes.
  36. /// </returns>
  37. /// <exception cref="T:System.ArgumentException">The byte array contains invalid Unicode code points.</exception>
  38. ///
  39. /// <exception cref="T:System.ArgumentNullException">
  40. /// <paramref name="bytes"/> is null. </exception>
  41. ///
  42. /// <exception cref="T:System.Text.DecoderFallbackException">A fallback occurred (see Understanding Encodings for complete explanation)-and-<see cref="P:System.Text.Encoding.DecoderFallback"/> is set to <see cref="T:System.Text.DecoderExceptionFallback"/>.</exception>
  43. public String GetString(byte[] bytes)
  44. {
  45. if (bytes == null)
  46. {
  47. throw new ArgumentNullException("bytes");
  48. }
  49. if (bytes.Length == 0)
  50. {
  51. return String.Empty;
  52. }
  53. int count = bytes.Length;
  54. int posn = 0;
  55. char[] chars = new char[count];
  56. while (count-- > 0)
  57. {
  58. chars[posn] = (char)(bytes[posn]);
  59. ++posn;
  60. }
  61. return new string(chars);
  62. }
  63. }
  64. }