Created
June 11, 2010 00:53
-
-
Save osima/433881 to your computer and use it in GitHub Desktop.
MacroProcessor.groovyを利用例その2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// MacroProcessor.groovyを利用する便利クラス | |
// | |
class TextProcessor { | |
def 変換処理のClosure | |
def TextProcessor(Closure 変換処理のClosure){ | |
this.変換処理のClosure = 変換処理のClosure | |
} | |
String process(String text){ | |
def sb = ''<<'' | |
def m = MacroProcessor.PAT.matcher(text); | |
def pointer = 0 | |
def result = m.find() | |
while( result ){ | |
sb << text.substring( pointer, m.start() ) | |
def macroText = text.substring( m.start(),m.end() ) | |
sb << 変換処理のClosure.call( macroText ) | |
pointer = m.end() | |
result = m.find() | |
} | |
sb << text.substring(pointer) | |
sb.toString() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment