Mercurial Hosting > luan
annotate src/goodjava/bbcode/BBCode.java @ 1708:8d257d56dc42
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 04 Jul 2022 14:06:59 -0600 |
parents | a6e27c8e7ef4 |
children | 05d14db623b6 |
rev | line source |
---|---|
1702 | 1 package goodjava.bbcode; |
585 | 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 | 7 import java.util.regex.Matcher; |
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 | 11 |
12 public final class BBCode { | |
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 | 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 | 34 } |
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 | 41 |
1702 | 42 private final Parser parser; |
43 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
44 private BBCode(String text) { |
585 | 45 this.parser = new Parser(text); |
46 } | |
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 | 50 StringBuilder text = new StringBuilder(); |
585 | 51 while( !parser.endOfInput() ) { |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
52 Element block = parseBlock(); |
1247 | 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 | 56 } else { |
57 text.append( parser.currentChar() ); | |
585 | 58 parser.anyChar(); |
59 } | |
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 | 63 } |
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 | 67 StringBuilder text = new StringBuilder(); |
585 | 68 while( !parser.endOfInput() ) { |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
69 Element block = parseBlock(); |
585 | 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 | 73 continue; |
74 } | |
75 if( couldBeTag() ) | |
76 break; | |
1247 | 77 text.append( parser.currentChar() ); |
585 | 78 parser.anyChar(); |
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 | 82 } |
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 | 89 } |
90 | |
585 | 91 private boolean couldBeTag() { |
92 if( parser.currentChar() != '[' ) | |
93 return false; | |
94 return parser.testIgnoreCase("[b]") | |
95 || parser.testIgnoreCase("[/b]") | |
96 || parser.testIgnoreCase("[i]") | |
97 || parser.testIgnoreCase("[/i]") | |
98 || parser.testIgnoreCase("[u]") | |
99 || parser.testIgnoreCase("[/u]") | |
100 || parser.testIgnoreCase("[url]") | |
101 || parser.testIgnoreCase("[url=") | |
102 || parser.testIgnoreCase("[/url]") | |
103 || parser.testIgnoreCase("[code]") | |
104 || parser.testIgnoreCase("[/code]") | |
105 || parser.testIgnoreCase("[img]") | |
106 || parser.testIgnoreCase("[/img]") | |
107 || parser.testIgnoreCase("[color=") | |
108 || parser.testIgnoreCase("[/color]") | |
109 || parser.testIgnoreCase("[size=") | |
110 || parser.testIgnoreCase("[/size]") | |
1703 | 111 || parser.testIgnoreCase("[video]") |
112 || parser.testIgnoreCase("[/video]") | |
585 | 113 || parser.testIgnoreCase("[quote]") |
114 || parser.testIgnoreCase("[quote=") | |
115 || parser.testIgnoreCase("[/quote]") | |
116 ; | |
117 } | |
118 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
119 private Element parseBlock() { |
585 | 120 if( parser.currentChar() != '[' ) |
121 return null; | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
122 Element s; |
585 | 123 s = parseB(); if(s!=null) return s; |
124 s = parseI(); if(s!=null) return s; | |
125 s = parseU(); if(s!=null) return s; | |
126 s = parseUrl1(); if(s!=null) return s; | |
127 s = parseUrl2(); if(s!=null) return s; | |
128 s = parseCode(); if(s!=null) return s; | |
129 s = parseImg(); if(s!=null) return s; | |
130 s = parseColor(); if(s!=null) return s; | |
131 s = parseSize(); if(s!=null) return s; | |
1703 | 132 s = parseVideo(); if(s!=null) return s; |
585 | 133 s = parseQuote1(); if(s!=null) return s; |
134 s = parseQuote2(); if(s!=null) return s; | |
135 return null; | |
136 } | |
137 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
138 private Element parseB() { |
585 | 139 parser.begin(); |
140 if( !parser.matchIgnoreCase("[b]") ) | |
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 | 143 if( !parser.matchIgnoreCase("[/b]") ) |
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 | 146 return parser.success(rtn); |
147 } | |
148 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
149 private Element parseI() { |
585 | 150 parser.begin(); |
151 if( !parser.matchIgnoreCase("[i]") ) | |
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 | 154 if( !parser.matchIgnoreCase("[/i]") ) |
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 | 157 return parser.success(rtn); |
158 } | |
159 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
160 private Element parseU() { |
585 | 161 parser.begin(); |
162 if( !parser.matchIgnoreCase("[u]") ) | |
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 | 165 if( !parser.matchIgnoreCase("[/u]") ) |
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 | 168 return parser.success(rtn); |
169 } | |
170 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
171 private Element parseUrl1() { |
585 | 172 parser.begin(); |
173 if( !parser.matchIgnoreCase("[url]") ) | |
174 return parser.failure(null); | |
175 String url = parseRealUrl(); | |
176 if( !parser.matchIgnoreCase("[/url]") ) | |
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 | 179 return parser.success(rtn); |
180 } | |
181 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
182 private Element parseUrl2() { |
585 | 183 parser.begin(); |
184 if( !parser.matchIgnoreCase("[url=") ) | |
185 return parser.failure(null); | |
186 String url = parseRealUrl(); | |
187 if( !parser.match(']') ) | |
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 | 190 if( !parser.matchIgnoreCase("[/url]") ) |
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 | 193 return parser.success(rtn); |
194 } | |
195 | |
196 private String parseRealUrl() { | |
197 parser.begin(); | |
198 while( parser.match(' ') ); | |
199 int start = parser.currentIndex(); | |
200 if( !parser.matchIgnoreCase("http") ) | |
201 return parser.failure(null); | |
202 parser.matchIgnoreCase("s"); | |
203 if( !parser.matchIgnoreCase("://") ) | |
204 return parser.failure(null); | |
205 while( parser.noneOf(" []'") ); | |
206 String url = parser.textFrom(start); | |
207 while( parser.match(' ') ); | |
208 return parser.success(url); | |
209 } | |
210 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
211 private Element parseCode() { |
585 | 212 parser.begin(); |
213 if( !parser.matchIgnoreCase("[code]") ) | |
214 return parser.failure(null); | |
215 int start = parser.currentIndex(); | |
216 while( !parser.testIgnoreCase("[/code]") ) { | |
217 if( !parser.anyChar() ) | |
218 return parser.failure(null); | |
219 } | |
220 String content = parser.textFrom(start); | |
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 | 223 return parser.success(rtn); |
224 } | |
225 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
226 private Element parseImg() { |
585 | 227 parser.begin(); |
228 if( !parser.matchIgnoreCase("[img]") ) | |
229 return parser.failure(null); | |
230 String url = parseRealUrl(); | |
231 if( !parser.matchIgnoreCase("[/img]") ) | |
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 | 234 return parser.success(rtn); |
235 } | |
236 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
237 private Element parseColor() { |
585 | 238 parser.begin(); |
239 if( !parser.matchIgnoreCase("[color=") ) | |
240 return parser.failure(null); | |
241 int start = parser.currentIndex(); | |
242 parser.match('#'); | |
243 while( parser.inCharRange('0','9') | |
244 || parser.inCharRange('a','z') | |
245 || parser.inCharRange('A','Z') | |
246 ); | |
247 String color = parser.textFrom(start); | |
248 if( !parser.match(']') ) | |
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 | 251 if( !parser.matchIgnoreCase("[/color]") ) |
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 | 254 return parser.success(rtn); |
255 } | |
256 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
257 private Element parseSize() { |
585 | 258 parser.begin(); |
259 if( !parser.matchIgnoreCase("[size=") ) | |
260 return parser.failure(null); | |
261 int start = parser.currentIndex(); | |
262 while( parser.match('.') || parser.inCharRange('0','9') ); | |
263 String size = parser.textFrom(start); | |
264 if( !parser.match(']') ) | |
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 | 267 if( !parser.matchIgnoreCase("[/size]") ) |
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 | 270 return parser.success(rtn); |
271 } | |
272 | |
1703 | 273 private static final Pattern youtubePtn1 = Pattern.compile("https://youtu.be/([a-zA-Z0-9_-]+)(?:\\?t=([0-9]+))?"); |
274 private static final Pattern youtubePtn2 = Pattern.compile("https://www.youtube.com/watch?v=([a-zA-Z0-9_-]+)(?:\\?t=([0-9]+)s)?"); | |
275 private static final Pattern bitchutePtn = Pattern.compile("https://www.bitchute.com/video/([a-zA-Z0-9]+)/"); | |
276 | |
277 private static Matcher find(Pattern ptn,String s) { | |
278 Matcher m = ptn.matcher(s); | |
279 return m.find() ? m : null; | |
280 } | |
281 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
282 private Element parseVideo() { |
585 | 283 parser.begin(); |
1703 | 284 if( !parser.matchIgnoreCase("[video]") ) |
285 return parser.failure(null); | |
286 String url = parseRealUrl(); | |
287 if( !parser.matchIgnoreCase("[/video]") ) | |
585 | 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 | 291 Matcher m; |
292 m = find(youtubePtn1,url); | |
293 if( m == null ) | |
294 m = find(youtubePtn2,url); | |
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 | 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 | 302 } |
303 m = find(bitchutePtn,url); | |
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 | 308 } |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
309 return parser.success(rtn); |
585 | 310 } |
311 | |
1703 | 312 |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
313 private Element parseQuote1() { |
585 | 314 parser.begin(); |
315 if( !parser.matchIgnoreCase("[quote]") ) | |
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 | 318 if( !parser.matchIgnoreCase("[/quote]") ) |
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 | 321 return parser.success(rtn); |
322 } | |
323 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
324 private Element parseQuote2() { |
585 | 325 parser.begin(); |
326 if( !parser.matchIgnoreCase("[quote=") ) | |
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 | 329 int start = parser.currentIndex(); |
1702 | 330 while( parser.noneOf("[]") ); |
585 | 331 String name = parser.textFrom(start).trim(); |
332 if( !parser.match(']') ) | |
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 | 335 if( !parser.matchIgnoreCase("[/quote]") ) |
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 | 339 } |
340 | |
341 } |