Skip to content

Commit 55a7ae6

Browse files
committed
cleanup
1 parent 3a239c1 commit 55a7ae6

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

Diff for: script/config/config.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ local Template = {
152152
"?/init.lua",
153153
},
154154
['Lua.runtime.special'] = Type.Hash(Type.String, Type.String),
155-
['Lua.runtime.meta'] = Type.String >> '${version} ${language}',
155+
['Lua.runtime.meta'] = Type.String >> '${version} ${language} ${encoding}',
156156
['Lua.runtime.unicodeName'] = Type.Boolean,
157157
['Lua.runtime.nonstandardSymbol'] = Type.Hash(Type.String, Type.Boolean, ';'),
158158
['Lua.runtime.plugin'] = Type.String,

Diff for: script/encoding/init.lua

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
local platform = require 'bee.platform'
2+
local unicode
3+
4+
if platform.OS == 'Windows' then
5+
unicode = require 'bee.unicode'
6+
end
7+
8+
local m = {}
9+
10+
function m.ansi2utf8(text)
11+
if not unicode then
12+
return text
13+
end
14+
return unicode.a2u(text)
15+
end
16+
17+
function m.utf82ansi(text)
18+
if not unicode then
19+
return text
20+
end
21+
return unicode.u2a(text)
22+
end
23+
24+
return m

Diff for: script/files.lua

+3-8
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ local util = require 'utility'
1010
local guide = require 'parser.guide'
1111
local smerger = require 'string-merger'
1212
local progress = require "progress"
13-
14-
local unicode
15-
16-
if platform.OS == 'Windows' then
17-
unicode = require 'bee.unicode'
18-
end
13+
local encoding = require 'encoding'
1914

2015
---@class files
2116
local m = {}
@@ -144,9 +139,9 @@ function m.setText(uri, text, isTrust, instance)
144139
if file.trusted and not isTrust then
145140
return
146141
end
147-
if not isTrust and unicode then
142+
if not isTrust then
148143
if config.get 'Lua.runtime.fileEncoding' == 'ansi' then
149-
text = unicode.a2u(text)
144+
text = encoding.ansi2utf8(text)
150145
end
151146
end
152147
if file.originText == text then

Diff for: script/library.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,13 @@ local function initBuiltIn()
200200
if not m.inited then
201201
return
202202
end
203-
local langID = lang.id
204-
local version = config.get 'Lua.runtime.version'
203+
local langID = lang.id
204+
local version = config.get 'Lua.runtime.version'
205+
local encoding = config.get 'Lua.runtime.fileEncoding'
205206
local metaPath = fs.path(METAPATH) / config.get 'Lua.runtime.meta':gsub('%$%{(.-)%}', {
206207
version = version,
207208
language = langID,
209+
encoding = encoding,
208210
})
209211

210212
local metaLang = loadMetaLocale('en-US')

0 commit comments

Comments
 (0)