Browse Subversion Repository
Diff of /trunk/ktx/Utils/FileEncodingDetector.cs
Parent Directory
| Revision Log
| Patch
| 37 |
{ |
{ |
| 38 |
var bytes = new byte[length]; |
var bytes = new byte[length]; |
| 39 |
Array.Copy(buffer, bytes, length); |
Array.Copy(buffer, bytes, length); |
| 40 |
|
if (EqualsBytes(bytes, 0xff, 0xfe, 0x00, 0x00)) |
| 41 |
|
return Encoding.UTF32; |
| 42 |
if (EqualsBytes(bytes, 0xfe, 0xff)) |
if (EqualsBytes(bytes, 0xfe, 0xff)) |
| 43 |
return Encoding.BigEndianUnicode; |
return Encoding.BigEndianUnicode; |
| 44 |
if (EqualsBytes(bytes, 0xff, 0xfe)) |
if (EqualsBytes(bytes, 0xff, 0xfe)) |
| 45 |
return Encoding.Unicode; |
return Encoding.Unicode; |
| 46 |
if (EqualsBytes(bytes, 0xef, 0xbb, 0xbf)) |
if (EqualsBytes(bytes, 0xef, 0xbb, 0xbf)) |
| 47 |
return Encoding.UTF8; |
return Encoding.UTF8; |
|
if (EqualsBytes(bytes, 0xff, 0xfe, 0x00, 0x00)) |
|
|
return Encoding.UTF32; |
|
| 48 |
return null; |
return null; |
| 49 |
} |
} |
| 50 |
|
|
| 51 |
private static bool EqualsBytes(byte[] a, params byte[] b) |
private static bool EqualsBytes(byte[] a, params byte[] b) |
| 52 |
{ |
{ |
| 53 |
if (a.Length == b.Length) { |
if (a.Length >= b.Length) { |
| 54 |
for (int i = 0; i < a.Length; i++) { |
for (int i = 0; i < b.Length; i++) { |
| 55 |
if (a[i] != b[i]) |
if (a[i] != b[i]) |
| 56 |
return false; |
return false; |
| 57 |
} |
} |
|
|
Legend:
| Removed from v.40 |
|
| changed lines |
| |
Added in v.41 |
|
|
| |