Mercurial Hosting > luan
changeset 629:35dde32c02ab 0.15
change String.matches()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 18 Jan 2016 23:07:52 -0700 |
parents | 6510de302f95 |
children | 8d83b53b7a7b |
files | blog/src/lib/test.luan core/src/luan/modules/Io.luan core/src/luan/modules/StringLuan.java core/src/luan/modules/Which_mod.luan core/src/luan/modules/mmake.luan http/src/luan/modules/http/Http.luan http/src/luan/modules/http/Http_test.luan http/src/luan/modules/http/Server.luan lucene/src/luan/modules/lucene/Versioning.luan website/src/manual.html.luan |
diffstat | 10 files changed, 18 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/blog/src/lib/test.luan Mon Jan 18 06:42:50 2016 -0700 +++ b/blog/src/lib/test.luan Mon Jan 18 23:07:52 2016 -0700 @@ -8,7 +8,7 @@ local Io = require "luan:Io" local print = Io.print or error() local String = require "luan:String" -local match = String.match or error() +local matches = String.matches or error() Http.uncache_site() @@ -57,6 +57,6 @@ init() print '/ again' page = get_page '/' -match(page,'this is an edit') or error() +matches(page,'this is an edit') or error() print 'done'
--- a/core/src/luan/modules/Io.luan Mon Jan 18 06:42:50 2016 -0700 +++ b/core/src/luan/modules/Io.luan Mon Jan 18 23:07:52 2016 -0700 @@ -92,7 +92,7 @@ for key, value in pairs(obj) do if in_list[key] ~= true then if is_first then is_first = false else %>, <% end - if type(key) == "string" and matches(key,"[a-zA-Z_][a-zA-Z_0-9]*") ~= nil then + if type(key) == "string" and matches(key,"^[a-zA-Z_][a-zA-Z_0-9]*$") ~= nil then %><%=key%><% elseif type(key) == "table" then %>[<<%=key%>>]<%
--- a/core/src/luan/modules/StringLuan.java Mon Jan 18 06:42:50 2016 -0700 +++ b/core/src/luan/modules/StringLuan.java Mon Jan 18 23:07:52 2016 -0700 @@ -236,7 +236,7 @@ } public static boolean matches(String s,String pattern) { - return s.matches(pattern); + return Pattern.compile(pattern).matcher(s).find(); } }
--- a/core/src/luan/modules/Which_mod.luan Mon Jan 18 06:42:50 2016 -0700 +++ b/core/src/luan/modules/Which_mod.luan Mon Jan 18 23:07:52 2016 -0700 @@ -5,7 +5,7 @@ local type = Luan.type or error() local String = require "luan:String" local literal = String.literal or error() -local match = String.match or error() +local matches = String.matches or error() local Io = require "luan:Io" local print = Io.print or error() @@ -37,7 +37,7 @@ local ptn = "[:./]"..literal(name).."$" for _, uri in ipairs(M.uris) do local mod = require(uri) - if match(uri,ptn) ~= nil then + if matches(uri,ptn) then print(uri) end if type(mod) == "table" then
--- a/core/src/luan/modules/mmake.luan Mon Jan 18 06:42:50 2016 -0700 +++ b/core/src/luan/modules/mmake.luan Mon Jan 18 23:07:52 2016 -0700 @@ -28,7 +28,7 @@ local dirs = {} for _, file in ipairs(dir.children()) do local name = file.name() - if String.matches(name,[[.*\.java]]) then + if String.matches(name,[[\.java$]]) then javas[#javas+1] = String.sub(name,1,-6) end if file.is_directory() and mmake(file) then
--- a/http/src/luan/modules/http/Http.luan Mon Jan 18 06:42:50 2016 -0700 +++ b/http/src/luan/modules/http/Http.luan Mon Jan 18 23:07:52 2016 -0700 @@ -158,7 +158,7 @@ function M.uncache_site() for k in pairs(Table.copy(Package.loaded)) do - if matches(k,"site:.*") then + if matches(k,"^site:") then Package.loaded[k] = nil end end
--- a/http/src/luan/modules/http/Http_test.luan Mon Jan 18 06:42:50 2016 -0700 +++ b/http/src/luan/modules/http/Http_test.luan Mon Jan 18 23:07:52 2016 -0700 @@ -13,7 +13,7 @@ M.cookie = {} function M.get_page(path) - if M.welcome_file ~= nil and matches(path,".*/") then + if M.welcome_file ~= nil and matches(path,"/$") then path = path .. M.welcome_file end local old_out = Io.stdout
--- a/http/src/luan/modules/http/Server.luan Mon Jan 18 06:42:50 2016 -0700 +++ b/http/src/luan/modules/http/Server.luan Mon Jan 18 23:07:52 2016 -0700 @@ -1,6 +1,6 @@ local String = require "luan:String" local gsub = String.gsub -local match = String.match +local matches = String.matches local Io = require "luan:Io" local Package = require "luan:Package" local Http = require "luan:http/Http" @@ -81,7 +81,7 @@ end M.authentication_handler.setPassword(M.private_password) local base = dir - if match(base,"^classpath:") ~= nil then + if matches(base,"^classpath:") then base = dir.."#"..M.welcome_file.."#"..M.welcome_file..".luan" end M.resource_handler.setResourceBase(Io.uri(base).to_string())
--- a/lucene/src/luan/modules/lucene/Versioning.luan Mon Jan 18 06:42:50 2016 -0700 +++ b/lucene/src/luan/modules/lucene/Versioning.luan Mon Jan 18 23:07:52 2016 -0700 @@ -39,7 +39,7 @@ db.advanced_search( Lucene.literal"id index" .. ":*", function(_,doc_fn) local doc = doc_fn() for field, value in pairs(copy(doc)) do - if matches(field,".* index") then + if matches(field," index$") then local new_field = sub(field,1,-7) db.indexed_fields[new_field] or error("field '"..new_field.."' not indexed") doc[new_field] = value
--- a/website/src/manual.html.luan Mon Jan 18 06:42:50 2016 -0700 +++ b/website/src/manual.html.luan Mon Jan 18 23:07:52 2016 -0700 @@ -2550,8 +2550,12 @@ <h4 heading><a name="String.matches"><code>String.matches (s, pattern)</code></a></h4> <p> -Returns a boolean indicating whether the entire string <code>s</code> matches <code>pattern</code>. - +Returns a boolean indicating whether the <code>pattern</code> can be found in string <code>s</code>. +This function is equivalent to + +<pre> + return String.match(s,pattern) ~= nil +</pre> <h4 heading><a name="String.rep"><code>String.rep (s, n [, sep])</code></a></h4>