annotate src/goodjava/bbcode/BBCode.java @ 1710:fc224a1bb6ea

add blog/serve_and_backup.luan
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 10 Jul 2022 17:52:19 -0600
parents a6e27c8e7ef4
children 05d14db623b6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1702
8ad468cc88d4 add goodjava/bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1563
diff changeset
1 package goodjava.bbcode;
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2
637
6ea90dc10375 bbcode parser now takes a quoter function
Franklin Schmidt <fschmidt@gmail.com>
parents: 588
diff changeset
3 import java.util.List;
6ea90dc10375 bbcode parser now takes a quoter function
Franklin Schmidt <fschmidt@gmail.com>
parents: 588
diff changeset
4 import java.util.ArrayList;
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
5 import java.util.Map;
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
6 import java.util.LinkedHashMap;
1703
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
7 import java.util.regex.Matcher;
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
8 import java.util.regex.Pattern;
1402
27efb1fcbcb5 move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents: 1335
diff changeset
9 import goodjava.parser.Parser;
637
6ea90dc10375 bbcode parser now takes a quoter function
Franklin Schmidt <fschmidt@gmail.com>
parents: 588
diff changeset
10
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 public final class BBCode {
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
14 public final class Element {
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
15 public final String name;
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
16 public final String param;
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
17 public final Object contents; // String, Element, or List
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
18 public final Map<String,String> extra;
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
19
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
20 private Element(String name,Object contents) {
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
21 this(name,null,contents);
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
22 }
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
24 private Element(String name,String param,Object contents) {
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
25 this(name,param,contents,null);
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
26 }
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
27
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
28 private Element(String name,String param,Object contents,Map<String,String> extra) {
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
29 this.name = name.toLowerCase();
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
30 this.param = param;
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
31 this.contents = contents;
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
32 this.extra = extra;
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
33 }
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
36 public static Object parse(String text) {
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
37 if( text.indexOf('[') == -1 )
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
38 return text;
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
39 return new BBCode(text).parse();
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
40 }
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41
1702
8ad468cc88d4 add goodjava/bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1563
diff changeset
42 private final Parser parser;
8ad468cc88d4 add goodjava/bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1563
diff changeset
43
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
44 private BBCode(String text) {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 this.parser = new Parser(text);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
48 private Object parse() {
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
49 List list = new ArrayList();
1247
728d8e75f476 html encode bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
50 StringBuilder text = new StringBuilder();
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 while( !parser.endOfInput() ) {
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
52 Element block = parseBlock();
1247
728d8e75f476 html encode bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
53 if( block != null ) {
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
54 add(list,text);
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
55 list.add( block );
1247
728d8e75f476 html encode bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
56 } else {
728d8e75f476 html encode bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
57 text.append( parser.currentChar() );
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58 parser.anyChar();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 }
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
61 add(list,text);
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
62 return list.size()==1 ? list.get(0) : list;
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
64
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
65 private Object parseWellFormed() {
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
66 List list = new ArrayList();
1247
728d8e75f476 html encode bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
67 StringBuilder text = new StringBuilder();
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
68 while( !parser.endOfInput() ) {
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
69 Element block = parseBlock();
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
70 if( block != null ) {
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
71 add(list,text);
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
72 list.add( block );
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
73 continue;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
74 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
75 if( couldBeTag() )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
76 break;
1247
728d8e75f476 html encode bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
77 text.append( parser.currentChar() );
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
78 parser.anyChar();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
79 }
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
80 add(list,text);
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
81 return list.size()==1 ? list.get(0) : list;
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
82 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
83
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
84 private void add(List list,StringBuilder text) {
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
85 if( text.length() > 0 ) {
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
86 list.add( text.toString() );
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
87 text.setLength(0);
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
88 }
1247
728d8e75f476 html encode bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
89 }
728d8e75f476 html encode bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
90
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
91 private boolean couldBeTag() {
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
92 if( parser.currentChar() != '[' )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
93 return false;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
94 return parser.testIgnoreCase("[b]")
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
95 || parser.testIgnoreCase("[/b]")
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
96 || parser.testIgnoreCase("[i]")
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
97 || parser.testIgnoreCase("[/i]")
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
98 || parser.testIgnoreCase("[u]")
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
99 || parser.testIgnoreCase("[/u]")
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
100 || parser.testIgnoreCase("[url]")
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
101 || parser.testIgnoreCase("[url=")
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
102 || parser.testIgnoreCase("[/url]")
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
103 || parser.testIgnoreCase("[code]")
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
104 || parser.testIgnoreCase("[/code]")
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
105 || parser.testIgnoreCase("[img]")
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
106 || parser.testIgnoreCase("[/img]")
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
107 || parser.testIgnoreCase("[color=")
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
108 || parser.testIgnoreCase("[/color]")
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
109 || parser.testIgnoreCase("[size=")
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
110 || parser.testIgnoreCase("[/size]")
1703
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
111 || parser.testIgnoreCase("[video]")
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
112 || parser.testIgnoreCase("[/video]")
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
113 || parser.testIgnoreCase("[quote]")
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
114 || parser.testIgnoreCase("[quote=")
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
115 || parser.testIgnoreCase("[/quote]")
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
116 ;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
117 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
118
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
119 private Element parseBlock() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
120 if( parser.currentChar() != '[' )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
121 return null;
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
122 Element s;
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
123 s = parseB(); if(s!=null) return s;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
124 s = parseI(); if(s!=null) return s;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
125 s = parseU(); if(s!=null) return s;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
126 s = parseUrl1(); if(s!=null) return s;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
127 s = parseUrl2(); if(s!=null) return s;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
128 s = parseCode(); if(s!=null) return s;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
129 s = parseImg(); if(s!=null) return s;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
130 s = parseColor(); if(s!=null) return s;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
131 s = parseSize(); if(s!=null) return s;
1703
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
132 s = parseVideo(); if(s!=null) return s;
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
133 s = parseQuote1(); if(s!=null) return s;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
134 s = parseQuote2(); if(s!=null) return s;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
135 return null;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
136 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
137
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
138 private Element parseB() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
139 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
140 if( !parser.matchIgnoreCase("[b]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
141 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
142 Object content = parseWellFormed();
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
143 if( !parser.matchIgnoreCase("[/b]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
144 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
145 Element rtn = new Element("b",content);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
146 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
147 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
148
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
149 private Element parseI() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
150 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
151 if( !parser.matchIgnoreCase("[i]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
152 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
153 Object content = parseWellFormed();
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
154 if( !parser.matchIgnoreCase("[/i]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
155 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
156 Element rtn = new Element("i",content);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
157 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
158 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
159
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
160 private Element parseU() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
161 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
162 if( !parser.matchIgnoreCase("[u]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
163 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
164 Object content = parseWellFormed();
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
165 if( !parser.matchIgnoreCase("[/u]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
166 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
167 Element rtn = new Element("u",content);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
168 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
169 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
170
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
171 private Element parseUrl1() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
172 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
173 if( !parser.matchIgnoreCase("[url]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
174 return parser.failure(null);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
175 String url = parseRealUrl();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
176 if( !parser.matchIgnoreCase("[/url]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
177 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
178 Element rtn = new Element("url",url);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
179 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
180 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
181
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
182 private Element parseUrl2() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
183 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
184 if( !parser.matchIgnoreCase("[url=") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
185 return parser.failure(null);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
186 String url = parseRealUrl();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
187 if( !parser.match(']') )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
188 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
189 Object content = parseWellFormed();
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
190 if( !parser.matchIgnoreCase("[/url]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
191 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
192 Element rtn = new Element("url",url,content);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
193 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
194 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
195
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
196 private String parseRealUrl() {
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
197 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
198 while( parser.match(' ') );
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
199 int start = parser.currentIndex();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
200 if( !parser.matchIgnoreCase("http") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
201 return parser.failure(null);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
202 parser.matchIgnoreCase("s");
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
203 if( !parser.matchIgnoreCase("://") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
204 return parser.failure(null);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
205 while( parser.noneOf(" []'") );
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
206 String url = parser.textFrom(start);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
207 while( parser.match(' ') );
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
208 return parser.success(url);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
209 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
210
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
211 private Element parseCode() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
212 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
213 if( !parser.matchIgnoreCase("[code]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
214 return parser.failure(null);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
215 int start = parser.currentIndex();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
216 while( !parser.testIgnoreCase("[/code]") ) {
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
217 if( !parser.anyChar() )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
218 return parser.failure(null);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
219 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
220 String content = parser.textFrom(start);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
221 if( !parser.matchIgnoreCase("[/code]") ) throw new RuntimeException();
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
222 Element rtn = new Element("code",content);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
223 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
224 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
225
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
226 private Element parseImg() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
227 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
228 if( !parser.matchIgnoreCase("[img]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
229 return parser.failure(null);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
230 String url = parseRealUrl();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
231 if( !parser.matchIgnoreCase("[/img]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
232 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
233 Element rtn = new Element("img",url);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
234 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
235 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
236
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
237 private Element parseColor() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
238 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
239 if( !parser.matchIgnoreCase("[color=") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
240 return parser.failure(null);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
241 int start = parser.currentIndex();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
242 parser.match('#');
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
243 while( parser.inCharRange('0','9')
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
244 || parser.inCharRange('a','z')
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
245 || parser.inCharRange('A','Z')
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
246 );
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
247 String color = parser.textFrom(start);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
248 if( !parser.match(']') )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
249 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
250 Object content = parseWellFormed();
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
251 if( !parser.matchIgnoreCase("[/color]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
252 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
253 Element rtn = new Element("color",color,content);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
254 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
255 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
256
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
257 private Element parseSize() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
258 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
259 if( !parser.matchIgnoreCase("[size=") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
260 return parser.failure(null);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
261 int start = parser.currentIndex();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
262 while( parser.match('.') || parser.inCharRange('0','9') );
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
263 String size = parser.textFrom(start);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
264 if( !parser.match(']') )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
265 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
266 Object content = parseWellFormed();
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
267 if( !parser.matchIgnoreCase("[/size]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
268 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
269 Element rtn = new Element("size",size,content);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
270 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
271 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
272
1703
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
273 private static final Pattern youtubePtn1 = Pattern.compile("https://youtu.be/([a-zA-Z0-9_-]+)(?:\\?t=([0-9]+))?");
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
274 private static final Pattern youtubePtn2 = Pattern.compile("https://www.youtube.com/watch?v=([a-zA-Z0-9_-]+)(?:\\?t=([0-9]+)s)?");
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
275 private static final Pattern bitchutePtn = Pattern.compile("https://www.bitchute.com/video/([a-zA-Z0-9]+)/");
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
276
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
277 private static Matcher find(Pattern ptn,String s) {
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
278 Matcher m = ptn.matcher(s);
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
279 return m.find() ? m : null;
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
280 }
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
281
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
282 private Element parseVideo() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
283 parser.begin();
1703
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
284 if( !parser.matchIgnoreCase("[video]") )
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
285 return parser.failure(null);
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
286 String url = parseRealUrl();
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
287 if( !parser.matchIgnoreCase("[/video]") )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
288 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
289 Map<String,String> extra = new LinkedHashMap<String,String>();
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
290 Element rtn = new Element("video",null,url,extra);
1703
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
291 Matcher m;
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
292 m = find(youtubePtn1,url);
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
293 if( m == null )
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
294 m = find(youtubePtn2,url);
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
295 if( m != null ) {
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
296 extra.put( "site", "youtube" );
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
297 extra.put( "id", m.group(1) );
1703
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
298 String t = m.group(2);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
299 if( t != null )
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
300 extra.put( "start", t );
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
301 return parser.success(rtn);
1703
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
302 }
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
303 m = find(bitchutePtn,url);
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
304 if( m != null ) {
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
305 extra.put( "site", "bitchute" );
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
306 extra.put( "id", m.group(1) );
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
307 return parser.success(rtn);
1703
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
308 }
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
309 return parser.success(rtn);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
310 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
311
1703
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
312
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
313 private Element parseQuote1() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
314 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
315 if( !parser.matchIgnoreCase("[quote]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
316 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
317 Object content = parseWellFormed();
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
318 if( !parser.matchIgnoreCase("[/quote]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
319 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
320 Element rtn = new Element("quote",content);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
321 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
322 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
323
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
324 private Element parseQuote2() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
325 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
326 if( !parser.matchIgnoreCase("[quote=") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
327 return parser.failure(null);
637
6ea90dc10375 bbcode parser now takes a quoter function
Franklin Schmidt <fschmidt@gmail.com>
parents: 588
diff changeset
328 List args = new ArrayList();
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
329 int start = parser.currentIndex();
1702
8ad468cc88d4 add goodjava/bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1563
diff changeset
330 while( parser.noneOf("[]") );
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
331 String name = parser.textFrom(start).trim();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
332 if( !parser.match(']') )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
333 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
334 Object content = parseWellFormed();
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
335 if( !parser.matchIgnoreCase("[/quote]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
336 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
337 Element rtn = new Element("quote",name,content);
637
6ea90dc10375 bbcode parser now takes a quoter function
Franklin Schmidt <fschmidt@gmail.com>
parents: 588
diff changeset
338 return parser.success(rtn);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
339 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
340
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
341 }