cache compiled regexps in constants

This commit is contained in:
Alexey Verkhovsky 2005-01-21 21:58:48 +00:00
parent 9242ad045d
commit 259a7028e3
2 changed files with 7 additions and 5 deletions

View file

@ -62,11 +62,12 @@ module WikiChunk
# NOTE: This chunk must be tested before WikiWord since # NOTE: This chunk must be tested before WikiWord since
# a WikiWords can be a substring of a WikiLink. # a WikiWords can be a substring of a WikiLink.
class Link < WikiLink class Link < WikiLink
def self.pattern() /\[\[([^\]]+)\]\]/ end
unless defined? ALIASED_LINK_PATTERN WIKI_LINK = /\[\[([^\]]+)\]\]/ unless defined? WIKI_LINK
ALIASED_LINK_PATTERN = Regexp.new('^(.*)?\|(.*)$', 0, 'utf-8') ALIASED_LINK_PATTERN =
end Regexp.new('^(.*)?\|(.*)$', 0, 'utf-8') unless defined? ALIASED_LINK_PATTERN
def self.pattern() WIKI_LINK end
attr_reader :page_name, :link_text attr_reader :page_name, :link_text

View file

@ -14,12 +14,13 @@ module WikiWords
"աբգդեզէըթժիլխծկհձղճմյնշոչպջռսվտրցւփքօֆև" "աբգդեզէըթժիլխծկհձղճմյնշոչպջռսվտրցւփքօֆև"
WIKI_WORD_PATTERN = '[A-Z' + I18N_HIGHER_CASE_LETTERS + '][a-z' + I18N_LOWER_CASE_LETTERS + ']+[A-Z' + I18N_HIGHER_CASE_LETTERS + ']\w+' WIKI_WORD_PATTERN = '[A-Z' + I18N_HIGHER_CASE_LETTERS + '][a-z' + I18N_LOWER_CASE_LETTERS + ']+[A-Z' + I18N_HIGHER_CASE_LETTERS + ']\w+'
CAMEL_CASED_WORD_BORDER = /([a-z#{I18N_LOWER_CASE_LETTERS}])([A-Z#{I18N_HIGHER_CASE_LETTERS}])/u
def self.separate(wiki_word, ignore_separation = false) def self.separate(wiki_word, ignore_separation = false)
if ignore_separation if ignore_separation
wiki_word wiki_word
else else
wiki_word.gsub(/([a-z#{I18N_LOWER_CASE_LETTERS}])([A-Z#{I18N_HIGHER_CASE_LETTERS}])/u, '\1 \2') wiki_word.gsub(CAMEL_CASED_WORD_BORDER, '\1 \2')
end end
end end
end end