lib/utopia/extensions.rb in utopia-0.9.26 vs lib/utopia/extensions.rb in utopia-0.9.27

- old
+ new

@@ -1,19 +1,8 @@ -# Copyright (c) 2010 Samuel Williams. Released under the GNU GPLv3. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# This file is part of the "Utopia Framework" project, and is licensed under the GNU AGPLv3. +# Copyright 2010 Samuel Williams. All rights reserved. +# See <utopia.rb> for licensing details. require 'active_support' class Date alias_method :old_cmp, :<=> @@ -26,9 +15,23 @@ return (other <=> self) * -1 else old_cmp(other) end end +end + +class Regexp + def self.starts_with(string) + return /^#{Regexp.escape(string)}/ + end + + def self.ends_with(string) + return /#{Regexp.escape(string)}$/ + end + + def self.contains(string) + return Regexp.new(string) + end end class String HTML_ESCAPE = {"&" => "&amp;", "<" => "&lt;", ">" => "&gt;", "\"" => "&quot;"} HTML_ESCAPE_PATTERN = Regexp.new("[" + Regexp.quote(HTML_ESCAPE.keys.join) + "]")