Mercurial Hosting > luan
diff src/luan/modules/Boot.luan @ 1716:b82767112d8e
add String.regex
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 24 Jul 2022 23:43:03 -0600 |
parents | 46cf5137cb6b |
children | 2f3a8f16f583 |
line wrap: on
line diff
--- a/src/luan/modules/Boot.luan Sat Jul 23 21:53:04 2022 -0600 +++ b/src/luan/modules/Boot.luan Sun Jul 24 23:43:03 2022 -0600 @@ -8,8 +8,8 @@ local load = BasicLuan.load local type = BasicLuan.type local StringLuan = require "java:luan.modules.StringLuan" -local match = StringLuan.match -- String.match -local matches = StringLuan.matches -- String.matches +local contains = StringLuan.contains -- String.contains +local RegexLuan = require "java:luan.modules.RegexLuan" local IoLuan = require "java:luan.modules.IoLuan" local LuanUrl = require "java:luan.modules.url.LuanUrl" local LuanJava = require "java:luan.Luan" @@ -49,6 +49,21 @@ Boot.local_metatable = local_metatable +local function regex(pattern) + local regex = RegexLuan.new(pattern) + return { + java = regex + find = regex.find + gmatch = regex.gmatch + gsub = regex.gsub + match = regex.match + matches = regex.matches + set = regex.set + } +end +Boot.regex = regex + + local function new_LuanIn(io) local this = {} this.java = io @@ -230,8 +245,10 @@ Boot.schemes = schemes +local uri_regex = regex("(?s)^([^:]+):(.*)$") + local function uri(name,options) - local scheme, location = match( name, "(?s)^([^:]+):(.*)$" ) + local scheme, location = uri_regex.match(name) scheme or error( "invalid Io.uri name '"..name.."', missing scheme" ) local opener = schemes[scheme] or error( "invalid scheme '"..scheme.."' in '"..name.."'" ) return opener(location,options) @@ -249,7 +266,7 @@ function Boot.load_file(file) if type(file) == "string" then - if not matches(file,":") then + if not contains(file,":") then file = "file:"..file end local u = uri(file)