Develop and Download Open Source Software

Browse Subversion Repository

Diff of /trunk/ktx/Utils/FileEncodingDetector.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 40 by bananajinn, Sun Nov 3 07:30:34 2019 UTC revision 41 by bananajinn, Wed Nov 16 08:29:09 2022 UTC
# Line 37  namespace ktox.Utils Line 37  namespace ktox.Utils
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

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26