mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-10-26 10:58:05 +03:00
Improve encoding declaration detecion (close #698)
This commit is contained in:
parent
f5f04469f8
commit
a0bff9ca5d
@ -32,6 +32,7 @@ develop
|
||||
- Improve auto-brackets/quotes insertion behavior with multiple selections.
|
||||
- Improve the setting file naming rule for when the name overwraps with an existing setting.
|
||||
- Improve condition to insert a closing quote automatically.
|
||||
- Improve the encoding declaration detection.
|
||||
- Update “Ruby” syntax style to fix commands highlight.
|
||||
- Update “MATLAB” syntax style to fix strings highlight.
|
||||
- Remove less useful “Inline script menu items into contextual menu” option.
|
||||
|
@ -223,6 +223,7 @@ extension String {
|
||||
let stringToScan = self.substring(to: scanIndex)
|
||||
let scanner = Scanner(string: stringToScan) // scan only the beginning of string
|
||||
let stopSet = CharacterSet(charactersIn: "\"\' </>\n\r")
|
||||
let invalidDelimiterSet = CharacterSet.alphanumerics.subtracting(CharacterSet(charactersIn: "\"\' ")).inverted
|
||||
var scannedString: NSString?
|
||||
|
||||
scanner.charactersToBeSkipped = CharacterSet(charactersIn: "\"\' ")
|
||||
@ -234,15 +235,18 @@ extension String {
|
||||
while !scanner.isAtEnd {
|
||||
scanner.scanUpTo(tag, into: nil)
|
||||
if scanner.scanString(tag, into: nil),
|
||||
!scanner.scanCharacters(from: invalidDelimiterSet, into: nil),
|
||||
scanner.scanUpToCharacters(from: stopSet, into: &scannedString) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if scannedString != nil { break }
|
||||
}
|
||||
|
||||
guard let ianaCharSetName = scannedString else { return nil }
|
||||
|
||||
|
||||
// convert IANA CharSet name to CFStringEncoding
|
||||
guard let cfEncoding: CFStringEncoding = {
|
||||
// simply convert expect for "Shift_JIS"
|
||||
|
Loading…
Reference in New Issue
Block a user