Created
June 11, 2010 00:25
-
-
Save osima/433858 to your computer and use it in GitHub Desktop.
MacroProcessor.groovyの利用例その1
This file contains 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の利用例 | |
// | |
// マクロをどう処理するかを記述 | |
def proc( macroText ){ | |
def mp = new MacroProcessor( macroText ) | |
'<span aid:cstyle="' + mp.key + '">' + mp.value + '</span>' | |
} | |
// | |
// テスト用本文 | |
// | |
def text = """ | |
これは{bold:本体のみ}の | |
提供になります。 | |
""" | |
// | |
// マクロ部分を置き換えるためのコード | |
// | |
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 << proc( macroText ) | |
pointer = m.end() | |
result = m.find() | |
} | |
sb << text.substring(pointer) | |
println sb.toString() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment