mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-14 19:30:57 +00:00
0a8757baba
This is a reimplementation of Lua's string library with support for UTF-8. The entire ustring library is implemented in pure Lua. PHP callbacks are also available for overrides: in LuaSandbox these are used for almost all functions, while in LuaStandalone they are used only for the pattern matching. Also, ustring.upper and ustring.lower are overridden using mw.language's .uc and .lc if available. It also includes a bunch of unit tests. Note that if you download the normalization tests, they may fail under LuaSandbox if you have PHP's intl extension installed and libicu on your system is too old. Change-Id: Ie76fdf8d3a85d0a3d2a41b0d3b7afe433f247af0
24 lines
587 B
Lua
24 lines
587 B
Lua
local function tohex( s )
|
|
local t = { s }
|
|
for c in mw.ustring.gcodepoint( s ) do
|
|
t[#t + 1] = string.format( "%x", c )
|
|
end
|
|
return table.concat( t, '\t' )
|
|
end
|
|
|
|
return {
|
|
run = function ( c1, c2, c3, c4, c5 )
|
|
return
|
|
tohex( mw.ustring.toNFC( c1 ) ),
|
|
tohex( mw.ustring.toNFC( c2 ) ),
|
|
tohex( mw.ustring.toNFC( c3 ) ),
|
|
tohex( mw.ustring.toNFC( c4 ) ),
|
|
tohex( mw.ustring.toNFC( c5 ) ),
|
|
tohex( mw.ustring.toNFD( c1 ) ),
|
|
tohex( mw.ustring.toNFD( c2 ) ),
|
|
tohex( mw.ustring.toNFD( c3 ) ),
|
|
tohex( mw.ustring.toNFD( c4 ) ),
|
|
tohex( mw.ustring.toNFD( c5 ) )
|
|
end
|
|
}
|