forked from spullara/mustache.java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriteCode.java
More file actions
41 lines (35 loc) · 1.04 KB
/
WriteCode.java
File metadata and controls
41 lines (35 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.github.mustachejava.codes;
import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.TemplateContext;
import com.github.mustachejava.util.Node;
import java.io.Writer;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Write template text.
*/
public class WriteCode extends DefaultCode {
public WriteCode(TemplateContext tc, DefaultMustacheFactory df, String text) {
super(tc, df, null, null, null);
super.append(text);
}
@Override
public void identity(Writer writer) {
execute(writer, null);
}
private Pattern compiledAppended;
@Override
public Node invert(Node node, String text, AtomicInteger position) {
if (compiledAppended == null) {
compiledAppended = Pattern.compile(appended);
}
Matcher matcher = compiledAppended.matcher(text);
if (matcher.find(position.get())) {
position.set(matcher.start() + matcher.group(0).length());
return node;
} else {
return null;
}
}
}