Mercurial Hosting > luan
comparison src/luan/modules/parsers/BBCode.java @ 1563:8fbcc4747091
remove LuanFunction.luan
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 09 Nov 2020 01:37:57 -0700 |
parents | 27efb1fcbcb5 |
children |
comparison
equal
deleted
inserted
replaced
1562:b89212fd04b5 | 1563:8fbcc4747091 |
---|---|
10 import goodjava.parser.Parser; | 10 import goodjava.parser.Parser; |
11 | 11 |
12 | 12 |
13 public final class BBCode { | 13 public final class BBCode { |
14 | 14 |
15 public static String toHtml(String bbcode,LuanFunction quoter) throws LuanException { | 15 public static String toHtml(Luan luan,String bbcode,LuanFunction quoter) throws LuanException { |
16 return new BBCode(bbcode,quoter,true).parse(); | 16 return new BBCode(luan,bbcode,quoter,true).parse(); |
17 } | 17 } |
18 | 18 |
19 public static String toText(String bbcode,LuanFunction quoter) throws LuanException { | 19 public static String toText(Luan luan,String bbcode,LuanFunction quoter) throws LuanException { |
20 return new BBCode(bbcode,quoter,false).parse(); | 20 return new BBCode(luan,bbcode,quoter,false).parse(); |
21 } | 21 } |
22 | 22 |
23 private final Luan luan; | |
23 private final Parser parser; | 24 private final Parser parser; |
24 private final LuanFunction quoter; | 25 private final LuanFunction quoter; |
25 private final boolean toHtml; | 26 private final boolean toHtml; |
26 | 27 |
27 private BBCode(String text,LuanFunction quoter,boolean toHtml) throws LuanException { | 28 private BBCode(Luan luan,String text,LuanFunction quoter,boolean toHtml) throws LuanException { |
28 Utils.checkNotNull(text,1); | 29 Utils.checkNotNull(text,1); |
29 // Utils.checkNotNull(quoter,2); | 30 // Utils.checkNotNull(quoter,2); |
31 this.luan = luan; | |
30 this.parser = new Parser(text); | 32 this.parser = new Parser(text); |
31 this.quoter = quoter; | 33 this.quoter = quoter; |
32 this.toHtml = toHtml; | 34 this.toHtml = toHtml; |
33 } | 35 } |
34 | 36 |
281 if( toHtml ) | 283 if( toHtml ) |
282 throw new LuanException("BBCode quoter function not defined"); | 284 throw new LuanException("BBCode quoter function not defined"); |
283 else | 285 else |
284 return ""; | 286 return ""; |
285 } | 287 } |
286 Object obj = quoter.call(args); | 288 Object obj = quoter.call(luan,args); |
287 if( !(obj instanceof String) ) | 289 if( !(obj instanceof String) ) |
288 throw new LuanException("BBCode quoter function returned "+Luan.type(obj)+" but string required"); | 290 throw new LuanException("BBCode quoter function returned "+Luan.type(obj)+" but string required"); |
289 return (String)obj; | 291 return (String)obj; |
290 } | 292 } |
291 | 293 |