Modul:JSONutil: Unterschied zwischen den Versionen

2019-07-11
(2019-05-29)
(2019-07-11)
Zeile 1: Zeile 1:
local JSONutil = { suite  = "JSONutil",
local JSONutil = { suite  = "JSONutil",
                   serial = "2019-05-29",
                   serial = "2019-07-11",
                   item  = 63869449 }
                   item  = 63869449 }
--[=[
--[=[
Zeile 69: Zeile 69:
     local s  = mw.text.trim( apply )
     local s  = mw.text.trim( apply )
     local sep = string.char( 10 )
     local sep = string.char( 10 )
     local i, j, r, scan, sep0, sep1, stab, start, stub, suffix
     local i, j, last, r, scan, sep0, sep1, stab, start, stub, suffix
     local framework = function ( a )
     local framework = function ( a )
                               -- syntax analysis outside strings
                               -- syntax analysis outside strings
Zeile 96: Zeile 96:
                 :gsub( string.char( 13 ),  sep )
                 :gsub( string.char( 13 ),  sep )
         stub = s:gsub( sep, "" ):gsub( stab, "" )
         stub = s:gsub( sep, "" ):gsub( stab, "" )
         scan = string.char( 0x5B, 0x01, 0x2D, 0x1F, 0x5D )
         scan = string.char( 0x5B, 0x01, 0x2D, 0x1F, 0x5D )   -- [ \-\ ]
         j    = stub:find( scan )
         j    = stub:find( scan )
         if j then
         if j then
             r = "ControlChar"
             r = "ControlChar"
             s = s:sub( j + 1, j + JSONutil.more )
             s = mw.text.trim( s:sub( j + 1 ) )
            s = mw.ustring.sub( s, 1, JSONutil.more )
         else
         else
             i    = true
             i    = true
             j    = 1
             j    = 1
            last = ( stub:sub( -1 ) == "}" )
             sep0 = string.char( 0x5B, 0x22, 0x27, 0x5D )    -- [ " ' ]
             sep0 = string.char( 0x5B, 0x22, 0x27, 0x5D )    -- [ " ' ]
             sep1 = string.char( 0x5B, 0x5C, 0x22, 0x5D )    -- [ \ " ]
             sep1 = string.char( 0x5B, 0x5C, 0x22, 0x5D )    -- [ \ " ]
Zeile 109: Zeile 111:
     else
     else
         r = "Bracket0"
         r = "Bracket0"
         s = s:sub( 1, JSONutil.more )
         s = mw.ustring.sub( s, 1, JSONutil.more )
     end
     end
     while i do
     while i do
Zeile 121: Zeile 123:
                 if stub:find( '[^"]*,%s*[%]}]' ) then
                 if stub:find( '[^"]*,%s*[%]}]' ) then
                     r = "CommaEnd"
                     r = "CommaEnd"
                     s = stub:sub( 1, JSONutil.more )
                     s = mw.text.trim( stub )
                    s = mw.ustring.sub( s, 1, JSONutil.more )
                     i = false
                     i = false
                     j = false
                     j = false
Zeile 154: Zeile 157:
                     else
                     else
                         r = "QouteEnd"
                         r = "QouteEnd"
                         s = s:sub( i, i + JSONutil.more )
                         s = mw.text.trim( s:sub( i ) )
                        s = mw.ustring.sub( s, 1, JSONutil.more )
                         i = false
                         i = false
                     end
                     end
Zeile 160: Zeile 164:
             else
             else
                 r = "Qoute"
                 r = "Qoute"
                 s = s:sub( i, i + JSONutil.more )
                 s = mw.text.trim( s:sub( i ) )
                s = mw.ustring.sub( s, 1, JSONutil.more )
                 i = false
                 i = false
             end
             end
Zeile 167: Zeile 172:
             if stub:find( '[^"]*,%s*[%]}]' ) then
             if stub:find( '[^"]*,%s*[%]}]' ) then
                 r = "CommaEnd"
                 r = "CommaEnd"
                 s = stub:sub( 1, JSONutil.more )
                 s = mw.text.trim( stub )
                s = mw.ustring.sub( s, 1, JSONutil.more )
             else
             else
                 framework( stub )
                 framework( stub )
Zeile 195: Zeile 201:
         if j > 1 then
         if j > 1 then
             s =  string.format( "%d %s", j, s )
             s =  string.format( "%d %s", j, s )
        end
    elseif not ( r or last ) then
        r    = "Trailing"
        stub = suffix or apply or ""
        s    = stub:match( "%}%s*(%S[^%}]*)$" )
        if s then
            s = mw.ustring.sub( s, 1, JSONutil.more )
        else
            s = mw.ustring.sub( stub,  - JSONutil.more )
         end
         end
     end
     end
Anonymer Benutzer