mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Revert ReadAsciiZ and ReadUtf8Z changes
This commit is contained in:
parent
85e555095f
commit
58226afd7b
1 changed files with 25 additions and 17 deletions
|
@ -32,11 +32,17 @@ namespace LibHac
|
||||||
public static bool ArraysEqual<T>(T[] a1, T[] a2)
|
public static bool ArraysEqual<T>(T[] a1, T[] a2)
|
||||||
{
|
{
|
||||||
if (a1 == null || a2 == null) return false;
|
if (a1 == null || a2 == null) return false;
|
||||||
|
if (a1 == a2) return true;
|
||||||
if (a1.Length != a2.Length) return false;
|
if (a1.Length != a2.Length) return false;
|
||||||
|
|
||||||
for (int i = 0; i < a1.Length; i++)
|
for (int i = 0; i < a1.Length; i++)
|
||||||
{
|
{
|
||||||
if (!a1[i].Equals(a2[i])) return false;
|
if (!a1[i].Equals(a2[i]))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,34 +89,36 @@ namespace LibHac
|
||||||
|
|
||||||
public static string ReadAsciiZ(this BinaryReader reader, int maxLength = int.MaxValue)
|
public static string ReadAsciiZ(this BinaryReader reader, int maxLength = int.MaxValue)
|
||||||
{
|
{
|
||||||
var str = new List<byte>();
|
long start = reader.BaseStream.Position;
|
||||||
byte ch;
|
|
||||||
int size = 0;
|
int size = 0;
|
||||||
while (size < maxLength)
|
|
||||||
|
// Read until we hit the end of the stream (-1) or a zero
|
||||||
|
while (reader.BaseStream.ReadByte() - 1 > 0 && size < maxLength)
|
||||||
{
|
{
|
||||||
size++;
|
size++;
|
||||||
ch = reader.ReadByte();
|
|
||||||
if (ch == 0)
|
|
||||||
break;
|
|
||||||
str.Add(ch);
|
|
||||||
}
|
}
|
||||||
return Encoding.ASCII.GetString(str.ToArray());
|
|
||||||
|
reader.BaseStream.Position = start;
|
||||||
|
string text = reader.ReadAscii(size);
|
||||||
|
reader.BaseStream.Position++; // Skip the null byte
|
||||||
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string ReadUtf8Z(this BinaryReader reader, int maxLength = int.MaxValue)
|
public static string ReadUtf8Z(this BinaryReader reader, int maxLength = int.MaxValue)
|
||||||
{
|
{
|
||||||
var str = new List<byte>();
|
long start = reader.BaseStream.Position;
|
||||||
byte ch;
|
|
||||||
int size = 0;
|
int size = 0;
|
||||||
while (size < maxLength)
|
|
||||||
|
// Read until we hit the end of the stream (-1) or a zero
|
||||||
|
while (reader.BaseStream.ReadByte() - 1 > 0 && size < maxLength)
|
||||||
{
|
{
|
||||||
size++;
|
size++;
|
||||||
ch = reader.ReadByte();
|
|
||||||
if (ch == 0)
|
|
||||||
break;
|
|
||||||
str.Add(ch);
|
|
||||||
}
|
}
|
||||||
return Encoding.UTF8.GetString(str.ToArray());
|
|
||||||
|
reader.BaseStream.Position = start;
|
||||||
|
string text = reader.ReadUtf8(size);
|
||||||
|
reader.BaseStream.Position++; // Skip the null byte
|
||||||
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void WriteUTF8(this BinaryWriter writer, string value)
|
public static void WriteUTF8(this BinaryWriter writer, string value)
|
||||||
|
|
Loading…
Reference in a new issue