Skip to content

Instantly share code, notes, and snippets.

@osima
Created June 11, 2010 00:53
Show Gist options
  • Save osima/433881 to your computer and use it in GitHub Desktop.
Save osima/433881 to your computer and use it in GitHub Desktop.
MacroProcessor.groovyを利用例その2
//
// 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