Mercurial Hosting > luan
view src/luan/modules/parsers/BBCodeLuan.java @ 1737:6c9aea554691
generalize bbcode
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 18 Oct 2022 22:08:29 -0600 |
parents | a6e27c8e7ef4 |
children |
line wrap: on
line source
package luan.modules.parsers; import java.util.List; import java.util.Map; import luan.LuanTable; import luan.LuanException; import luan.modules.Utils; import goodjava.bbcode.BBCode; public final class BBCodeLuan { public static Object parse(String text) throws LuanException { Utils.checkNotNull(text,1); Object obj = BBCode.parse(text); return convert(obj); } private static Object convert(Object obj) throws LuanException { if( obj instanceof String ) return obj; if( obj instanceof BBCode.Element ) return convert((BBCode.Element)obj); if( obj instanceof List ) return convert((List)obj); throw new RuntimeException("invalid obj: "+obj); } private static LuanTable convert(List list) throws LuanException { LuanTable t = new LuanTable(); for( Object obj : list ) { t.rawAdd( convert(obj) ); } return t; } private static LuanTable convert(BBCode.Element el) throws LuanException { LuanTable t = new LuanTable(); t.rawPut( "name", el.name ); Object param = el.param; Object contents = el.contents; if( param != null ) t.rawPut( "param", param ); t.rawPut( "contents", convert(contents) ); return t; } }