comparison src/luan/modules/parsers/BBCode.java @ 1335:e0cf0d108a77

major cleanup
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 14 Feb 2019 03:10:45 -0700
parents 25746915a241
children 27efb1fcbcb5
comparison
equal deleted inserted replaced
1334:c88b486a9511 1335:e0cf0d108a77
10 import luan.lib.parser.Parser; 10 import luan.lib.parser.Parser;
11 11
12 12
13 public final class BBCode { 13 public final class BBCode {
14 14
15 public static String toHtml(Luan luan,String bbcode,LuanFunction quoter) throws LuanException { 15 public static String toHtml(String bbcode,LuanFunction quoter) throws LuanException {
16 return new BBCode(luan,bbcode,quoter,true).parse(); 16 return new BBCode(bbcode,quoter,true).parse();
17 } 17 }
18 18
19 public static String toText(Luan luan,String bbcode,LuanFunction quoter) throws LuanException { 19 public static String toText(String bbcode,LuanFunction quoter) throws LuanException {
20 return new BBCode(luan,bbcode,quoter,false).parse(); 20 return new BBCode(bbcode,quoter,false).parse();
21 } 21 }
22 22
23 private final Luan luan;
24 private final Parser parser; 23 private final Parser parser;
25 private final LuanFunction quoter; 24 private final LuanFunction quoter;
26 private final boolean toHtml; 25 private final boolean toHtml;
27 26
28 private BBCode(Luan luan,String text,LuanFunction quoter,boolean toHtml) throws LuanException { 27 private BBCode(String text,LuanFunction quoter,boolean toHtml) throws LuanException {
29 Utils.checkNotNull(text,1); 28 Utils.checkNotNull(text,1);
30 // Utils.checkNotNull(quoter,2); 29 // Utils.checkNotNull(quoter,2);
31 this.luan = luan;
32 this.parser = new Parser(text); 30 this.parser = new Parser(text);
33 this.quoter = quoter; 31 this.quoter = quoter;
34 this.toHtml = toHtml; 32 this.toHtml = toHtml;
35 } 33 }
36 34
283 if( toHtml ) 281 if( toHtml )
284 throw new LuanException("BBCode quoter function not defined"); 282 throw new LuanException("BBCode quoter function not defined");
285 else 283 else
286 return ""; 284 return "";
287 } 285 }
288 Object obj = quoter.call(luan,args); 286 Object obj = quoter.call(args);
289 if( !(obj instanceof String) ) 287 if( !(obj instanceof String) )
290 throw new LuanException("BBCode quoter function returned "+Luan.type(obj)+" but string required"); 288 throw new LuanException("BBCode quoter function returned "+Luan.type(obj)+" but string required");
291 return (String)obj; 289 return (String)obj;
292 } 290 }
293 291