mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Added support for UTF-16 and other two-byte encodings.
This commit is contained in:
@@ -53,7 +53,7 @@ namespace DiscImageChef
|
|||||||
/// <returns>The corresponding C# string</returns>
|
/// <returns>The corresponding C# string</returns>
|
||||||
/// <param name="CString">A null-terminated (aka C string) byte array in the specified encoding</param>
|
/// <param name="CString">A null-terminated (aka C string) byte array in the specified encoding</param>
|
||||||
/// <param name="encoding">Encoding.</param>
|
/// <param name="encoding">Encoding.</param>
|
||||||
public static string CToString(byte[] CString, Encoding encoding)
|
public static string CToString(byte[] CString, Encoding encoding, bool twoBytes = false)
|
||||||
{
|
{
|
||||||
if(CString == null)
|
if(CString == null)
|
||||||
return null;
|
return null;
|
||||||
@@ -63,7 +63,20 @@ namespace DiscImageChef
|
|||||||
for(int i = 0; i < CString.Length; i++)
|
for(int i = 0; i < CString.Length; i++)
|
||||||
{
|
{
|
||||||
if(CString[i] == 0)
|
if(CString[i] == 0)
|
||||||
break;
|
{
|
||||||
|
if(twoBytes)
|
||||||
|
{
|
||||||
|
if((i + 1) < CString.Length && CString[i + 1] == 0)
|
||||||
|
{
|
||||||
|
len++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// if((i + 1) == CString.Length)
|
||||||
|
// break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
len++;
|
len++;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user