diff options
| author | eltrac <hi@eltr.ac> | 2026-09-23 17:04:00 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-09-23 17:04:00 +0800 |
| commit | 2a00cb08a62514ff00c1a5ce540fd5e24eba027b (patch) | |
| tree | 73d3e083cc78df105346c2252e3be62aca55be2c /src | |
| parent | ab8e9854bbdcda38ad72ba72207f395f5493a18a (diff) | |
clj: add parse-bytes function; check parameter types before parsing
Diffstat (limited to 'src')
| -rw-r--r-- | src/mf2clj/core.clj | 20 |
1 files changed, 13 insertions, 7 deletions
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)))
|
