| Revision | 41 (tree) |
|---|---|
| Time | 2022-11-16 17:29:09 |
| Author | |
文字コード判別処理でBOMの判定が間違えていたのを修正
| @@ -37,6 +37,8 @@ | ||
| 37 | 37 | { |
| 38 | 38 | var bytes = new byte[length]; |
| 39 | 39 | Array.Copy(buffer, bytes, length); |
| 40 | + if (EqualsBytes(bytes, 0xff, 0xfe, 0x00, 0x00)) | |
| 41 | + return Encoding.UTF32; | |
| 40 | 42 | if (EqualsBytes(bytes, 0xfe, 0xff)) |
| 41 | 43 | return Encoding.BigEndianUnicode; |
| 42 | 44 | if (EqualsBytes(bytes, 0xff, 0xfe)) |
| @@ -43,15 +45,13 @@ | ||
| 43 | 45 | return Encoding.Unicode; |
| 44 | 46 | if (EqualsBytes(bytes, 0xef, 0xbb, 0xbf)) |
| 45 | 47 | return Encoding.UTF8; |
| 46 | - if (EqualsBytes(bytes, 0xff, 0xfe, 0x00, 0x00)) | |
| 47 | - return Encoding.UTF32; | |
| 48 | 48 | return null; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | private static bool EqualsBytes(byte[] a, params byte[] b) |
| 52 | 52 | { |
| 53 | - if (a.Length == b.Length) { | |
| 54 | - for (int i = 0; i < a.Length; i++) { | |
| 53 | + if (a.Length >= b.Length) { | |
| 54 | + for (int i = 0; i < b.Length; i++) { | |
| 55 | 55 | if (a[i] != b[i]) |
| 56 | 56 | return false; |
| 57 | 57 | } |