comparison core/src/luan/modules/HtmlLuan.java @ 427:dae264ad6a7b

fix LuanTable.put() to use metatables
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 01 May 2015 19:29:07 -0600
parents 23a93c118042
children d9df6d6cb927
comparison
equal deleted inserted replaced
426:23a93c118042 427:dae264ad6a7b
139 return new LuanTable(html); 139 return new LuanTable(html);
140 } 140 }
141 141
142 static LuanTable comment(String text) { 142 static LuanTable comment(String text) {
143 LuanTable tbl = new LuanTable(); 143 LuanTable tbl = new LuanTable();
144 tbl.put("type","comment"); 144 tbl.rawPut("type","comment");
145 tbl.put("text",text); 145 tbl.rawPut("text",text);
146 return tbl; 146 return tbl;
147 } 147 }
148 148
149 static LuanTable cdata(String text) { 149 static LuanTable cdata(String text) {
150 LuanTable tbl = new LuanTable(); 150 LuanTable tbl = new LuanTable();
151 tbl.put("type","cdata"); 151 tbl.rawPut("type","cdata");
152 tbl.put("text",text); 152 tbl.rawPut("text",text);
153 return tbl; 153 return tbl;
154 } 154 }
155 155
156 static LuanTable textContainer(LuanTable tag,String text) { 156 static LuanTable textContainer(LuanTable tag,String text) {
157 LuanTable tbl = new LuanTable(); 157 LuanTable tbl = new LuanTable();
158 tbl.put("type","container"); 158 tbl.rawPut("type","container");
159 tbl.put("tag",tag); 159 tbl.rawPut("tag",tag);
160 tbl.put("text",text); 160 tbl.rawPut("text",text);
161 return tbl; 161 return tbl;
162 } 162 }
163 163
164 164
165 165
169 } 169 }
170 } 170 }
171 171
172 static LuanTable parseTag(String text) { 172 static LuanTable parseTag(String text) {
173 LuanTable tbl = new LuanTable(); 173 LuanTable tbl = new LuanTable();
174 tbl.put("type","tag"); 174 tbl.rawPut("type","tag");
175 if( text.endsWith("/") ) { 175 if( text.endsWith("/") ) {
176 text = text.substring(0,text.length()-1); 176 text = text.substring(0,text.length()-1);
177 tbl.put("is_empty",true); 177 tbl.rawPut("is_empty",true);
178 } else { 178 } else {
179 tbl.put("is_empty",false); 179 tbl.rawPut("is_empty",false);
180 } 180 }
181 int len = text.length(); 181 int len = text.length();
182 int i = 0; 182 int i = 0;
183 int i2 = i; 183 int i2 = i;
184 if( i2<len && text.charAt(i2)=='/' ) 184 if( i2<len && text.charAt(i2)=='/' )
190 if( !( Character.isLetterOrDigit(c) || c=='_' || c=='.' || c=='-' || c==':' ) ) 190 if( !( Character.isLetterOrDigit(c) || c=='_' || c=='.' || c=='-' || c==':' ) )
191 throw new BadTag("invalid tag name for <"+text+">"); 191 throw new BadTag("invalid tag name for <"+text+">");
192 i2++; 192 i2++;
193 } 193 }
194 String name = text.substring(i,i2).toLowerCase(); 194 String name = text.substring(i,i2).toLowerCase();
195 tbl.put("name",name); 195 tbl.rawPut("name",name);
196 LuanTable attributes = new LuanTable(); 196 LuanTable attributes = new LuanTable();
197 tbl.put("attributes",attributes); 197 tbl.rawPut("attributes",attributes);
198 i = i2; 198 i = i2;
199 while( i<len && Character.isWhitespace(text.charAt(i)) ) i++; 199 while( i<len && Character.isWhitespace(text.charAt(i)) ) i++;
200 while( i<len ) { 200 while( i<len ) {
201 i2 = toEndName(text,i,len); 201 i2 = toEndName(text,i,len);
202 String attrName = unquote(text.substring(i,i2).toLowerCase()); 202 String attrName = unquote(text.substring(i,i2).toLowerCase());
211 i2 = toEndValue(text,i,len); 211 i2 = toEndValue(text,i,len);
212 String attrValue = text.substring(i,i2); 212 String attrValue = text.substring(i,i2);
213 if( attrValue.indexOf('<') != -1 || attrValue.indexOf('>') != -1 ) 213 if( attrValue.indexOf('<') != -1 || attrValue.indexOf('>') != -1 )
214 throw new BadTag("invalid attribute value: "+attrValue); 214 throw new BadTag("invalid attribute value: "+attrValue);
215 attrValue = unquote(attrValue); 215 attrValue = unquote(attrValue);
216 attributes.put(attrName,attrValue); 216 attributes.rawPut(attrName,attrValue);
217 i = i2; 217 i = i2;
218 while( i<len && Character.isWhitespace(text.charAt(i)) ) i++; 218 while( i<len && Character.isWhitespace(text.charAt(i)) ) i++;
219 } else { 219 } else {
220 attributes.put(attrName,true); 220 attributes.rawPut(attrName,true);
221 } 221 }
222 } 222 }
223 return tbl; 223 return tbl;
224 } 224 }
225 225