From 2a00cb08a62514ff00c1a5ce540fd5e24eba027b Mon Sep 17 00:00:00 2001 From: eltrac Date: Wed, 23 Sep 2026 17:04:00 +0800 Subject: clj: add parse-bytes function; check parameter types before parsing --- src/mf2clj/core.clj | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/mf2clj') diff --git a/src/mf2clj/core.clj b/src/mf2clj/core.clj index fd26203..f049222 100644 --- a/src/mf2clj/core.clj +++ b/src/mf2clj/core.clj @@ -14,11 +14,17 @@ manifest-from-wasm .build Plugin/ofManifest .build)) -(defn parse [html-string] - (let [charset StandardCharsets/UTF_8 - html-bytes (.getBytes html-string charset)] - (-> (.call plugin "parse" html-bytes) - (String. charset) - json/parse-string - keywordize-keys))) +(def charset StandardCharsets/UTF_8) + +(defn parse-bytes [html-bytes] + {:pre [(bytes? html-bytes)]} + (-> (.call plugin "parse" html-bytes) + (String. charset) + json/parse-string + keywordize-keys)) + +(defn parse [^String html-string] + {:pre [(string? html-string)]} + (let [html-bytes (.getBytes html-string charset)] + (parse-bytes html-bytes))) -- cgit v1.2.3