Изменения

+ функция сравнения двух UTF-8 строк
Строка 381: Строка 381:     
     return result;
 
     return result;
 +
end
 +
 +
--[[
 +
  Internal compare string function
 +
]]
 +
function str._strcmp(a , b)
 +
    local s1c = mw.ustring.gcodepoint( a );
 +
    local s2c = mw.ustring.gcodepoint( b );
 +
    while true do
 +
        local c1 = s1c();
 +
        local c2 = s2c();
 +
        if c1 == nil then
 +
            if c2 == nil then
 +
                return 0
 +
            else
 +
                return -1
 +
            end
 +
        else
 +
            if c2 ~= nil then
 +
                if c1 ~= c2 then
 +
                  return c1 < c2 and -1 or 1
 +
              end
 +
            else
 +
                return 1
 +
            end
 +
        end
 +
    end
 +
    return 0
 +
end
 +
 +
--[[
 +
compare
 +
 +
This function compare two UTF-8 strings
 +
 +
Usage:
 +
{{#invoke:String|compare|str1|str2}}
 +
 +
Returns:
 +
0 - if strings are equal
 +
1 - if st1 > str2
 +
-1 - if str1 < str2
 +
]]
 +
function str.compare(frame)
 +
    local str1 = frame.args[1] or '';
 +
    local str2 = frame.args[2] or '';
 +
    return str._strcmp(str1 , str2)
 
end
 
end
  
Анонимный участник