treemap倒叙_lua 模拟Treemap 排序

因为项目需要请求参数进行treemap自然排序进行参数校验,前端很好搞 我这做在openresty上的lua校验就比较麻烦了,也没搜到解决方案,就自己尝试弄了下

-- 类Treemap自然排序函数

local function list_sort(a, b)

local a_len = string.len(a)

local b_len = string.len(b)

local max_len = a_len

if b_len > a_len then

max_len = b_len

end

for i = 1, max_len do

if string.len(a) < i then

if a_len > b_len then

return false

else

return true

end

end

if string.len(b) < i then

if a_len > b_len then

return false

else

return true

end

end

local a_byte = string.byte(a, i)

local b_byte = string.byte(b, i)

if a_byte == b_byte then

end

if a_byte > b_byte then

return false

end

if a_byte < b_byte then

return true

end

end

end

param_key_list = { "province","city","provinceCode","areaCode", "integrateStoreId", "detailAddress", "appKey", "cityCode","receiveName", "area", "subShopName" }

table.sort(param_key_list, list_sort)

for i, k in ipairs(param_key_list) do

print(k)

end

目前在项目使用没遇到问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值