mirror of
https://github.com/PredatH0r/ChanSort.git
synced 2026-03-04 11:10:44 +01:00
- rewrote m3u loader to handle arbitrary lines in the file and preserve encoding and line endings
- support for Hisense channel.db format of the H50B7700UW, which has a different schema in the fav_x tables - added spanish translation to distribution packages
This commit is contained in:
@@ -131,5 +131,51 @@ namespace ChanSort.Api
|
||||
return sb.ToString();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IsUtf8()
|
||||
/// <summary>
|
||||
/// This method tests whether the binary data can be interpreted as valid UTF-8. If not, it might be encoded with a locale specific encoding
|
||||
/// </summary>
|
||||
public static bool IsUtf8(byte[] buffer)
|
||||
{
|
||||
int followBytes = 0;
|
||||
foreach (byte b in buffer)
|
||||
{
|
||||
if (followBytes > 0)
|
||||
{
|
||||
if ((b & 0xC0) != 0x80) // follow-up bytes must be 10xx xxxx
|
||||
return false;
|
||||
--followBytes;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (b < 0x80) // standard ASCII characters
|
||||
continue;
|
||||
|
||||
if (b < 0xC0) // [0x80-0xBF] is only allowed for UTF-8 follow-up bytes
|
||||
return false;
|
||||
|
||||
if (b < 0xE0) // 110x xxxx
|
||||
followBytes = 1;
|
||||
else if (b < 0xF0) // 1110 xxxx
|
||||
followBytes = 2;
|
||||
else if (b < 0xF8) // 1111 0xxx
|
||||
followBytes = 3;
|
||||
else
|
||||
return false; // can't be more than 3 follow-up bytes
|
||||
}
|
||||
|
||||
return followBytes == 0;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region HasUtf8Bom()
|
||||
public static bool HasUtf8Bom(byte[] content)
|
||||
{
|
||||
if (content == null || content.Length < 3)
|
||||
return false;
|
||||
return content[0] == 0xEF && content[1] == 0xBB && content[2] == 0xBF;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user