1 Commits

Author SHA1 Message Date
Jonathan Bernard f366c3e1ce Migrate from std/nre -> nitely/regex
std/nre depends on PCRE v1 which is being deprecated by a number of
major distributions (Debian specifically). The core Nim team does not
have a plan currently to migrate it to PCRE v2. nitely/regex is a
Nim-native PCRE-compatible replacement.

AI-Assisted: yes
AI-Tool: codex gpt-5.4 xhigh
2026-03-19 10:52:31 -05:00
2 changed files with 9 additions and 9 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
# Package # Package
version = "1.0.0" version = "1.0.1"
author = "Jonathan Bernard" author = "Jonathan Bernard"
description = "URL shortener/expander for Probatem at https://pbtm.us" description = "URL shortener/expander for Probatem at https://pbtm.us"
license = "GPL3" license = "GPL3"
@@ -11,7 +11,7 @@ bin = @["short_url"]
# Dependencies # Dependencies
requires "nim >= 2.2.4" requires "nim >= 2.2.4"
requires @["cliutils", "mummy", "namespaced_logging >= 2.1.2", "webby"] requires @["cliutils", "mummy", "namespaced_logging >= 2.1.2", "regex", "webby"]
task updateVersion, "Update the version of this package.": task updateVersion, "Update the version of this package.":
exec "update_version interactive src/short_url.nim" exec "update_version interactive src/short_url.nim"
+7 -7
View File
@@ -1,5 +1,5 @@
import std/[json, nre, posix, sequtils, strutils] import std/[json, posix, sequtils, strutils]
import cliutils, docopt, mummy, namespaced_logging import cliutils, docopt, mummy, namespaced_logging, regex
import webby/httpheaders import webby/httpheaders
const USAGE = """ const USAGE = """
@@ -14,7 +14,7 @@ Options:
--trace Enable trace-level logging (takes precedence over --debug). --trace Enable trace-level logging (takes precedence over --debug).
""" """
const VERSION = "1.0.0" const VERSION = "1.0.1"
const CT_TXT = "text/plain" const CT_TXT = "text/plain"
type type
@@ -24,7 +24,7 @@ type
cfg: CombinedConfig cfg: CombinedConfig
Context = object Context = object
mappings: seq[tuple[src:string, regex: Regex, tmpl: string]] mappings: seq[tuple[src:string, regex: Regex2, tmpl: string]]
logger: Logger logger: Logger
proc loadConfig(args: Table[string, Value]): ShortUrlsConfig = proc loadConfig(args: Table[string, Value]): ShortUrlsConfig =
@@ -40,8 +40,8 @@ proc loadConfig(args: Table[string, Value]): ShortUrlsConfig =
result.mappings.add((k, v.getStr)) result.mappings.add((k, v.getStr))
proc initMappings(m: seq[tuple[src, dst: string]]): proc initMappings(m: seq[tuple[src, dst: string]]):
seq[tuple[src: string, regex: Regex, tmpl: string]] = seq[tuple[src: string, regex: Regex2, tmpl: string]] =
result = m.mapIt((it.src, re(it.src), it.dst)) result = m.mapIt((it.src, re2(it.src), it.dst))
proc makeHandler(mappings: seq[tuple[src,dst: string]], logSvc: LogService): RequestHandler = proc makeHandler(mappings: seq[tuple[src,dst: string]], logSvc: LogService): RequestHandler =
let ctx = Context( let ctx = Context(
@@ -56,7 +56,7 @@ proc makeHandler(mappings: seq[tuple[src,dst: string]], logSvc: LogService): Req
return return
for (src, regex, tmpl) in ctx.mappings: for (src, regex, tmpl) in ctx.mappings:
if match(req.uri, regex).isSome: if req.uri.startsWith(regex):
ctx.logger.debug(%*{ ctx.logger.debug(%*{
"msg": "found match", "msg": "found match",
"matching_pattern": %src, "matching_pattern": %src,