Browse Source

use Encoding.GetEndocing("ASCII") instead of Endocing.UTF8

pull/181/head
Johannes Bildstein 9 years ago
parent
commit
d7fa2978e7
  1. 4
      src/ImageSharp/MetaData/Profiles/ICC/IccDataReader.cs
  2. 7
      src/ImageSharp/MetaData/Profiles/ICC/IccDataWriter.cs
  3. 5
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs

4
src/ImageSharp/MetaData/Profiles/ICC/IccDataReader.cs

@ -17,6 +17,7 @@ namespace ImageSharp
internal sealed class IccDataReader internal sealed class IccDataReader
{ {
private static readonly bool IsLittleEndian = BitConverter.IsLittleEndian; private static readonly bool IsLittleEndian = BitConverter.IsLittleEndian;
private static readonly Encoding AsciiEncoding = Encoding.GetEncoding("ASCII");
/// <summary> /// <summary>
/// The data that is read /// The data that is read
@ -129,8 +130,7 @@ namespace ImageSharp
/// <returns>The value as a string</returns> /// <returns>The value as a string</returns>
public string ReadASCIIString(int length) public string ReadASCIIString(int length)
{ {
// Encoding.ASCII is missing in netstandard1.1, use UTF8 instead because it's compatible with ASCII string value = AsciiEncoding.GetString(this.data, this.AddIndex(length), length);
string value = Encoding.UTF8.GetString(this.data, this.AddIndex(length), length);
// remove data after (potential) null terminator // remove data after (potential) null terminator
int pos = value.IndexOf('\0'); int pos = value.IndexOf('\0');

7
src/ImageSharp/MetaData/Profiles/ICC/IccDataWriter.cs

@ -16,6 +16,7 @@ namespace ImageSharp
internal sealed class IccDataWriter internal sealed class IccDataWriter
{ {
private static readonly bool IsLittleEndian = BitConverter.IsLittleEndian; private static readonly bool IsLittleEndian = BitConverter.IsLittleEndian;
private static readonly Encoding AsciiEncoding = Encoding.GetEncoding("ASCII");
private static readonly double[,] IdentityMatrix = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }; private static readonly double[,] IdentityMatrix = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
@ -222,8 +223,7 @@ namespace ImageSharp
/// <returns>the number of bytes written</returns> /// <returns>the number of bytes written</returns>
public int WriteASCIIString(string value) public int WriteASCIIString(string value)
{ {
// Encoding.ASCII is missing in netstandard1.1, use UTF8 instead because it's compatible with ASCII byte[] data = AsciiEncoding.GetBytes(value);
byte[] data = Encoding.UTF8.GetBytes(value);
this.dataStream.Write(data, 0, data.Length); this.dataStream.Write(data, 0, data.Length);
return data.Length; return data.Length;
} }
@ -239,8 +239,7 @@ namespace ImageSharp
{ {
value = value.Substring(0, Math.Min(length - 1, value.Length)); value = value.Substring(0, Math.Min(length - 1, value.Length));
// Encoding.ASCII is missing in netstandard1.1, use UTF8 instead because it's compatible with ASCII byte[] textData = AsciiEncoding.GetBytes(value);
byte[] textData = Encoding.UTF8.GetBytes(value);
int actualLength = Math.Min(length - 1, textData.Length); int actualLength = Math.Min(length - 1, textData.Length);
this.dataStream.Write(textData, 0, actualLength); this.dataStream.Write(textData, 0, actualLength);
for (int i = 0; i < length - actualLength; i++) for (int i = 0; i < length - actualLength; i++)

5
src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs

@ -14,6 +14,8 @@ namespace ImageSharp
/// </summary> /// </summary>
internal sealed class IccDataTagDataEntry : IccTagDataEntry internal sealed class IccDataTagDataEntry : IccTagDataEntry
{ {
private static readonly Encoding AsciiEncoding = Encoding.GetEncoding("ASCII");
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="IccDataTagDataEntry"/> class. /// Initializes a new instance of the <see cref="IccDataTagDataEntry"/> class.
/// </summary> /// </summary>
@ -67,8 +69,7 @@ namespace ImageSharp
{ {
if (this.IsAscii) if (this.IsAscii)
{ {
// Encoding.ASCII is missing in netstandard1.1, use UTF8 instead because it's compatible with ASCII return AsciiEncoding.GetString(this.Data, 0, this.Data.Length);
return Encoding.UTF8.GetString(this.Data, 0, this.Data.Length);
} }
else else
{ {

Loading…
Cancel
Save