Mercurial Hosting > luan
comparison src/luan/modules/parsers/BBCode.java @ 1247:728d8e75f476
html encode bbcode
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 17 Jul 2018 22:17:01 -0600 |
parents | 88b5b81cad4a |
children | 475905984870 |
comparison
equal
deleted
inserted
replaced
1246:299996e03876 | 1247:728d8e75f476 |
---|---|
5 import luan.Luan; | 5 import luan.Luan; |
6 import luan.LuanState; | 6 import luan.LuanState; |
7 import luan.LuanFunction; | 7 import luan.LuanFunction; |
8 import luan.LuanException; | 8 import luan.LuanException; |
9 import luan.modules.Utils; | 9 import luan.modules.Utils; |
10 import luan.modules.HtmlLuan; | |
10 import luan.lib.parser.Parser; | 11 import luan.lib.parser.Parser; |
11 | 12 |
12 | 13 |
13 public final class BBCode { | 14 public final class BBCode { |
14 | 15 |
34 this.toHtml = toHtml; | 35 this.toHtml = toHtml; |
35 } | 36 } |
36 | 37 |
37 private String parse() throws LuanException { | 38 private String parse() throws LuanException { |
38 StringBuilder sb = new StringBuilder(); | 39 StringBuilder sb = new StringBuilder(); |
40 StringBuilder text = new StringBuilder(); | |
39 while( !parser.endOfInput() ) { | 41 while( !parser.endOfInput() ) { |
40 String block = parseBlock(); | 42 String block = parseBlock(); |
41 if( block != null ) | 43 if( block != null ) { |
44 sb.append( textToString(text) ); | |
42 sb.append(block); | 45 sb.append(block); |
43 else { | 46 } else { |
44 sb.append( parser.currentChar() ); | 47 text.append( parser.currentChar() ); |
45 parser.anyChar(); | 48 parser.anyChar(); |
46 } | 49 } |
47 } | 50 } |
51 sb.append( textToString(text) ); | |
48 return sb.toString(); | 52 return sb.toString(); |
49 } | 53 } |
50 | 54 |
51 private String parseWellFormed() throws LuanException { | 55 private String parseWellFormed() throws LuanException { |
52 StringBuilder sb = new StringBuilder(); | 56 StringBuilder sb = new StringBuilder(); |
57 StringBuilder text = new StringBuilder(); | |
53 while( !parser.endOfInput() ) { | 58 while( !parser.endOfInput() ) { |
54 String block = parseBlock(); | 59 String block = parseBlock(); |
55 if( block != null ) { | 60 if( block != null ) { |
61 sb.append( textToString(text) ); | |
56 sb.append(block); | 62 sb.append(block); |
57 continue; | 63 continue; |
58 } | 64 } |
59 if( couldBeTag() ) | 65 if( couldBeTag() ) |
60 break; | 66 break; |
61 sb.append( parser.currentChar() ); | 67 text.append( parser.currentChar() ); |
62 parser.anyChar(); | 68 parser.anyChar(); |
63 } | 69 } |
70 sb.append( textToString(text) ); | |
64 return sb.toString(); | 71 return sb.toString(); |
72 } | |
73 | |
74 private String textToString(StringBuilder text) throws LuanException { | |
75 String s = text.toString(); | |
76 text.setLength(0); | |
77 if( toHtml ) | |
78 s = HtmlLuan.encode(s); | |
79 return s; | |
65 } | 80 } |
66 | 81 |
67 private boolean couldBeTag() { | 82 private boolean couldBeTag() { |
68 if( parser.currentChar() != '[' ) | 83 if( parser.currentChar() != '[' ) |
69 return false; | 84 return false; |