Improve encoding declaration detecion (close #698)

This commit is contained in:
1024jp 2017-05-06 09:52:47 +09:00
parent f5f04469f8
commit a0bff9ca5d
2 changed files with 5 additions and 0 deletions

View File

@ -32,6 +32,7 @@ develop
- Improve auto-brackets/quotes insertion behavior with multiple selections. - 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 the setting file naming rule for when the name overwraps with an existing setting.
- Improve condition to insert a closing quote automatically. - Improve condition to insert a closing quote automatically.
- Improve the encoding declaration detection.
- Update “Ruby” syntax style to fix commands highlight. - Update “Ruby” syntax style to fix commands highlight.
- Update “MATLAB” syntax style to fix strings highlight. - Update “MATLAB” syntax style to fix strings highlight.
- Remove less useful “Inline script menu items into contextual menu” option. - Remove less useful “Inline script menu items into contextual menu” option.

View File

@ -223,6 +223,7 @@ extension String {
let stringToScan = self.substring(to: scanIndex) let stringToScan = self.substring(to: scanIndex)
let scanner = Scanner(string: stringToScan) // scan only the beginning of string let scanner = Scanner(string: stringToScan) // scan only the beginning of string
let stopSet = CharacterSet(charactersIn: "\"\' </>\n\r") let stopSet = CharacterSet(charactersIn: "\"\' </>\n\r")
let invalidDelimiterSet = CharacterSet.alphanumerics.subtracting(CharacterSet(charactersIn: "\"\' ")).inverted
var scannedString: NSString? var scannedString: NSString?
scanner.charactersToBeSkipped = CharacterSet(charactersIn: "\"\' ") scanner.charactersToBeSkipped = CharacterSet(charactersIn: "\"\' ")
@ -234,15 +235,18 @@ extension String {
while !scanner.isAtEnd { while !scanner.isAtEnd {
scanner.scanUpTo(tag, into: nil) scanner.scanUpTo(tag, into: nil)
if scanner.scanString(tag, into: nil), if scanner.scanString(tag, into: nil),
!scanner.scanCharacters(from: invalidDelimiterSet, into: nil),
scanner.scanUpToCharacters(from: stopSet, into: &scannedString) { scanner.scanUpToCharacters(from: stopSet, into: &scannedString) {
break break
} }
} }
if scannedString != nil { break } if scannedString != nil { break }
} }
guard let ianaCharSetName = scannedString else { return nil } guard let ianaCharSetName = scannedString else { return nil }
// convert IANA CharSet name to CFStringEncoding // convert IANA CharSet name to CFStringEncoding
guard let cfEncoding: CFStringEncoding = { guard let cfEncoding: CFStringEncoding = {
// simply convert expect for "Shift_JIS" // simply convert expect for "Shift_JIS"