-
Notifications
You must be signed in to change notification settings - Fork 6
Home
Detects the character encoding of a sequence of bytes.
public final class CharacterEncodingDetector
public init()
Detects the character encoding of a file.
@discardableResult public static func detectCharacterEncoding(ofFileAt fileURL: URL, on queue: DispatchQueue, completionQueue: DispatchQueue, completionHandler: @escaping (_ characterEncoding: String?) -> Void) throws -> () -> Void
- fileURL: The URL of the target file. The file does not need to be seekable.
- queue: The dispatch queue on which to perform the analysis.
- completionQueue: The dispatch queue on which to call the completion handler.
- completionHandler: The closure to call after the potentially-asynchronous operation is finished.
- characterEncoding: The
iconv
-compatible identifier of the detected character encoding, ornil
if detection failed.
An error if the file could not be opened.
A closure to cancel the operation. The completion handler will still be called even if the operation is canceled.
Detects the character encoding of a file.
@discardableResult public static func detectCharacterEncoding(ofDataFromFileDescriptor fileDescriptor: Int32, on queue: DispatchQueue, completionQueue: DispatchQueue, completionHandler: @escaping (_ characterEncoding: String?) -> Void) -> () -> Void
Attention: This method may modify the file offset of the file descriptor.
- fileDescriptor: The file descriptor of the target file. The file descriptor does not need to be seekable.
- queue: The dispatch queue on which to perform the analysis.
- completionQueue: The dispatch queue on which to call the completion handler.
- completionHandler: The closure to call after the potentially-asynchronous operation is finished.
- characterEncoding: The
iconv
-compatible identifier of the detected character encoding, ornil
if detection failed.
A closure to cancel the operation. The completion handler will still be called even if the operation is canceled.
Resets the detector so that it can analyze a new sequence of bytes.
public func reset()
Analyzes the next chunk of bytes in the sequence.
public func analyzeNextChunk<T: DataProtocol>(_ data: T) -> Bool
If the operation fails, you may call finish()
to get a best-effort detection result.
Precondition: After
finish()
is called,reset()
must be called before a new analysis can performed.
- data: The next chunk of bytes in the sequence.
Whether the operation was successful. The operation may fail, for example, if there is no more available memory.
Finishes the analysis and returns the detection result.
public func finish() -> String?
In order to get the most accurate result, call this method only after feeding all the bytes in the sequence to the detector.
Precondition: After this method is called,
reset()
must be called before a new analysis can performed.
The iconv
-compatible identifier of the detected character encoding, or nil
if detection failed.
Generated at 2020-02-28T07:40:16+0000 using swift-doc.