Software /
code /
prosody
Changeset
13866:7f6916088278
util.jsonschema: Simplify retrieval of UTF-8 length function
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 05 May 2025 17:14:57 +0200 |
parents | 13865:f489738a713c |
children | 13872:76582d10bc09 |
files | teal-src/prosody/util/jsonschema.tl util/jsonschema.lua |
diffstat | 2 files changed, 3 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/teal-src/prosody/util/jsonschema.tl Sun Mar 30 16:47:13 2025 +0200 +++ b/teal-src/prosody/util/jsonschema.tl Mon May 05 17:14:57 2025 +0200 @@ -10,12 +10,8 @@ if not math.type then require "prosody.util.mathcompat" end - -local utf8_enc = rawget(_G, "utf8") or require"prosody.util.encodings".utf8; -local utf8_len = utf8_enc.len or function(s : string) : integer - local _, count = s:gsub("[%z\001-\127\194-\253][\128-\191]*", ""); - return count -end; +-- XXX util.encodings seems to count differently from the Lua builtin +local utf8_len = rawget(_G, "utf8") and utf8.len or require"prosody.util.encodings".utf8.length; local json = require "prosody.util.json" local null = json.null;
--- a/util/jsonschema.lua Sun Mar 30 16:47:13 2025 +0200 +++ b/util/jsonschema.lua Mon May 05 17:14:57 2025 +0200 @@ -4,11 +4,7 @@ require("prosody.util.mathcompat") end -local utf8_enc = rawget(_G, "utf8") or require("prosody.util.encodings").utf8; -local utf8_len = utf8_enc.len or function(s) - local _, count = s:gsub("[%z\001-\127\194-\253][\128-\191]*", ""); - return count -end; +local utf8_len = rawget(_G, "utf8") and utf8.len or require("prosody.util.encodings").utf8.length; local json = require("prosody.util.json") local null = json.null;