FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
librime-lua-script/lua/tools/string.lua at main · shewer/librime-lua-script · GitHub
shewer
librime-lua-script
Repository navigation
Code
Issues
4
(4)
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
librime-lua-script
/
lua
/
tools
/
string.lua
Copy path
More file actions
More file actions
Latest commit
History
History
History
55 lines (48 loc) · 1.31 KB
Breadcrumbs
librime-lua-script
/
lua
/
tools
/
string.lua
Copy path
File metadata and controls
55 lines (48 loc) · 1.31 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
--
wrap utf8.sub(str,head_index, tail_index)
--
wrap string.split(str,sp,sp1)
--
string.utf8_len = utf8.len
--
string.utf8_offset= utf8.offset
--
string.utf8_sub= utf8.sub
local
List
=
require
'
tools/list
'
function
string
.
split
(
str
,
sp
,
sp1
)
sp
=
type
(
sp
)
==
"
string
"
and
sp
or
"
"
if
#
sp
==
0
then
sp
=
"
([%z
\1
-
\127\194
-
\244
][
\128
-
\191
]*)
"
elseif
#
sp
==
1
then
sp
=
"
[^
"
..
(
sp
==
"
%
"
and
"
%%
"
or
sp
)
..
"
]*
"
else
sp1
=
sp1
or
"
^
"
str
=
str
:
gsub
(
sp
,
sp1
)
sp
=
"
[^
"
..
sp1
..
"
]*
"
end
local
tab
=
List
()
for
v
in
str
:
gmatch
(
sp
)
do
table.insert
(
tab
,
v
)
end
return
tab
end
function
utf8
.
sub
(
str
,
si
,
ei
)
local
si_type
=
type
(
si
)
if
si_type
~=
"
number
"
then
local
info
=
debug.getinfo
(
2
,
'
Sln
'
)
local
error_msg
=
string.format
(
"
%s:%s bad argument #1 (number expected, get %s)
"
,
info
.
short_src
,
info
.
currentline
,
si_type
)
assert
(
nil
,
error_msg
)
end
local
len
=
utf8.len
(
str
)
if
si
<
0
then
si
=
si
<
-
len
and
1
or
len
+
si
+
1
end
ei
=
(
not
ei
or
ei
>
len
)
and
len
or
ei
if
ei
<
0
then
ei
=
ei
<
-
len
and
0
or
len
+
ei
+
1
end
if
si
>
ei
then
return
"
"
end
local
u_si
=
utf8.offset
(
str
,
si
)
local
u_ei
=
utf8.offset
(
str
,
ei
+
1
)
-
1
return
str
:
sub
(
u_si
,
u_ei
)
end
string
.
utf8_len
=
utf8.len
string
.
utf8_offset
=
utf8.offset
string
.
utf8_sub
=
utf8
.
sub
return
true
Back
|
FazBrowse Home
|
New Git URL