Explorar el Código

restore old detect

Marino Faggiana hace 7 años
padre
commit
9a8fd6e788

+ 0 - 4
Nextcloud.xcodeproj/project.pbxproj

@@ -195,7 +195,6 @@
 		F73B4F131F470D9100BBEE4B /* nsUniversalDetector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F73B4EE51F470D9100BBEE4B /* nsUniversalDetector.cpp */; };
 		F73B4F141F470D9100BBEE4B /* nsUTF8Prober.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F73B4EE71F470D9100BBEE4B /* nsUTF8Prober.cpp */; };
 		F73B4F151F470D9100BBEE4B /* symbols.cmake in Resources */ = {isa = PBXBuildFile; fileRef = F73B4EEA1F470D9100BBEE4B /* symbols.cmake */; };
-		F73B4F161F470D9100BBEE4B /* test in Resources */ = {isa = PBXBuildFile; fileRef = F73B4EEB1F470D9100BBEE4B /* test */; };
 		F73B4F171F470D9100BBEE4B /* uchardet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F73B4EEC1F470D9100BBEE4B /* uchardet.cpp */; };
 		F73B4F791E8D3BF800A97F07 /* CCMainTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F73B4F781E8D3BF800A97F07 /* CCMainTabBarController.swift */; };
 		F73C002F1E55D7DF00EEEFA7 /* CCManageCryptoCloudSecurity.m in Sources */ = {isa = PBXBuildFile; fileRef = F73C002E1E55D7DF00EEEFA7 /* CCManageCryptoCloudSecurity.m */; };
@@ -1179,7 +1178,6 @@
 		F73B4EE81F470D9100BBEE4B /* nsUTF8Prober.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nsUTF8Prober.h; sourceTree = "<group>"; };
 		F73B4EE91F470D9100BBEE4B /* prmem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = prmem.h; sourceTree = "<group>"; };
 		F73B4EEA1F470D9100BBEE4B /* symbols.cmake */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = symbols.cmake; sourceTree = "<group>"; };
-		F73B4EEB1F470D9100BBEE4B /* test */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = test; sourceTree = "<group>"; };
 		F73B4EEC1F470D9100BBEE4B /* uchardet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = uchardet.cpp; sourceTree = "<group>"; };
 		F73B4EED1F470D9100BBEE4B /* uchardet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = uchardet.h; sourceTree = "<group>"; };
 		F73B4F781E8D3BF800A97F07 /* CCMainTabBarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CCMainTabBarController.swift; sourceTree = "<group>"; };
@@ -2519,7 +2517,6 @@
 				F73B4EE81F470D9100BBEE4B /* nsUTF8Prober.h */,
 				F73B4EE91F470D9100BBEE4B /* prmem.h */,
 				F73B4EEA1F470D9100BBEE4B /* symbols.cmake */,
-				F73B4EEB1F470D9100BBEE4B /* test */,
 				F73B4EEC1F470D9100BBEE4B /* uchardet.cpp */,
 				F73B4EED1F470D9100BBEE4B /* uchardet.h */,
 			);
@@ -4357,7 +4354,6 @@
 				F76F23341ED4603700C40023 /* LaunchScreen.xib in Resources */,
 				F7D4247B1F063B82009C9782 /* ZSScenterjustify@2x.png in Resources */,
 				F7D424871F063B82009C9782 /* ZSSh4@2x.png in Resources */,
-				F73B4F161F470D9100BBEE4B /* test in Resources */,
 				F7D4249B1F063B82009C9782 /* ZSSlink@2x.png in Resources */,
 				F77B0F671D118A16002130FE /* InfoPlist.strings in Resources */,
 				F7C525A21E3B6DA800FFE02C /* CCNotification.storyboard in Resources */,

+ 2 - 0
iOSClient/Library/NCUchardet/NCUchardet.h

@@ -27,6 +27,8 @@
 
 @interface NCUchardet : NSObject
 
++ (NCUchardet *)sharedNUCharDet;
+
 - (NSString *)encodingStringDetectWithData:(NSData *)data;
 - (CFStringEncoding)encodingCFStringDetectWithData:(NSData *)data;
 

+ 15 - 0
iOSClient/Library/NCUchardet/NCUchardet.m

@@ -32,6 +32,16 @@
 
 @implementation NCUchardet
 
++ (NCUchardet *)sharedNUCharDet {
+    static NCUchardet *nuCharDet;
+    @synchronized(self) {
+        if (!nuCharDet) {
+            nuCharDet = [NCUchardet new];
+        }
+        return nuCharDet;
+    }
+}
+
 - (id)init
 {
     self = [super init];
@@ -43,6 +53,11 @@
     return self;
 }
 
+- (void)dealloc
+{
+    uchardet_delete(_detector);
+}
+
 - (NSString *)encodingStringDetectWithData:(NSData *)data
 {
     uchardet_handle_data(_detector, [data bytes], [data length]);

+ 1 - 2
iOSClient/Main/CCDetail.m

@@ -389,8 +389,7 @@
         [headRequest setHTTPMethod:@"HEAD"];
         
         NSURLSessionDataTask *task = [session dataTaskWithRequest:headRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
-            NCUchardet *nsuCharDet = [NCUchardet new];
-            NSString *encodingName = [nsuCharDet encodingStringDetectWithData:data];
+            NSString *encodingName = [[NCUchardet sharedNUCharDet] encodingStringDetectWithData:data];
             [self.webView loadData:[NSData dataWithContentsOfURL: url] MIMEType:response.MIMEType characterEncodingName:encodingName baseURL:url];
         }];
         

+ 0 - 4
iOSClient/Text/NCText.swift

@@ -64,13 +64,9 @@ class NCText: UIViewController, UITextViewDelegate {
             
             if let data = data {
             
-                /*
                 let encodingCFName = NCUchardet.sharedNUCharDet().encodingCFStringDetect(with: data as Data)
                 let se = CFStringConvertEncodingToNSStringEncoding(encodingCFName)
                 let encoding = String.Encoding(rawValue: se)
-                */
-                
-                let encoding = String.Encoding.utf8
                 
                 loadText = try? String(contentsOfFile: path, encoding: encoding)
                 textView.text = loadText