From 6ac71810842be3cb8845d8e8230d22300c32bc22 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Tue, 10 Mar 2015 12:40:47 -0400 Subject: Made `io.boms` private, as there are few BOMs in existence; core/file_io.lua --- core/file_io.lua | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/core/file_io.lua b/core/file_io.lua index 563e0b1e..d175bd7d 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -50,16 +50,6 @@ io.SNAPOPEN_MAX = 1000 -- @name recent_files io.recent_files = {} ---- --- List of byte-order marks (BOMs) for identifying unicode file encodings. --- @class table --- @name boms -io.boms = { - ['UTF-8'] = '\239\187\191', - ['UTF-16BE'] = '\254\255', ['UTF-16LE'] = '\255\254', - ['UTF-32BE'] = '\0\0\254\255', ['UTF-32LE'] = '\255\254\0\0' -} - --- -- List of encodings to attempt to decode files as. -- You should add to this list if you get a "Conversion failed" error when @@ -93,6 +83,11 @@ io.boms = { -- @name encodings io.encodings = {'UTF-8', 'ASCII', 'ISO-8859-1', 'MacRoman'} +local BOMs = { + ['UTF-8'] = '\239\187\191', + ['UTF-16BE'] = '\254\255', ['UTF-16LE'] = '\255\254', + ['UTF-32BE'] = '\0\0\254\255', ['UTF-32LE'] = '\255\254\0\0' +} local c = _SCINTILLA.constants local EOLs = {['\r\n'] = c.EOL_CRLF, ['\r'] = c.EOL_CR, ['\n'] = c.EOL_LF} --- @@ -130,7 +125,7 @@ function io.open_file(filenames) local buffer = buffer.new() buffer.encoding, buffer.encoding_bom = nil, nil -- Try to detect character encoding and convert to UTF-8. - for encoding, bom in pairs(io.boms) do + for encoding, bom in pairs(BOMs) do if text:sub(1, #bom) == bom then buffer.encoding, buffer.encoding_bom = encoding, bom text = text:sub(#bom + 1, -1):iconv('UTF-8', encoding) @@ -197,7 +192,7 @@ local function set_encoding(buffer, encoding) buffer:add_text(text, #text) buffer:line_scroll(0, first_visible_line) buffer:goto_pos(pos) - buffer.encoding, buffer.encoding_bom = encoding, io.boms[encoding] + buffer.encoding, buffer.encoding_bom = encoding, BOMs[encoding] end -- Sets the default buffer encoding. events_connect(events.BUFFER_NEW, function() -- cgit v1.2.3