Fixed Template class to be much nicer and pass all tests
This commit is contained in:
parent
500f45b77a
commit
88477e97c9
4 changed files with 64 additions and 29 deletions
33
src/zutil/net/ssdp/SSDPCustomInfo.java
Normal file
33
src/zutil/net/ssdp/SSDPCustomInfo.java
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014 Ziver
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package zutil.net.ssdp;
|
||||||
|
|
||||||
|
import zutil.net.http.HttpPrintStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Ziver on 2014-11-07.
|
||||||
|
*/
|
||||||
|
public interface SSDPCustomInfo extends SSDPServiceInfo{
|
||||||
|
|
||||||
|
public void setHeaders(HttpPrintStream http);
|
||||||
|
}
|
||||||
|
|
@ -76,12 +76,12 @@ public class MathParser {
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if(c == '('){
|
if(c == '('){
|
||||||
MathNode parantes = new MathNode();
|
MathNode parenteses = new MathNode();
|
||||||
MathOperation previusParantes = previus;
|
MathOperation previousParanteses = previus;
|
||||||
parse(functionString, temp, previus, parantes);
|
parse(functionString, temp, previus, parenteses);
|
||||||
previusParantes.math2 = parantes;
|
previousParanteses.math2 = parenteses;
|
||||||
System.out.println(parantes);
|
System.out.println(parenteses);
|
||||||
container = parantes;
|
container = parenteses;
|
||||||
|
|
||||||
// get the next operation
|
// get the next operation
|
||||||
c = functionString.charAt(0);
|
c = functionString.charAt(0);
|
||||||
|
|
|
||||||
|
|
@ -75,37 +75,39 @@ public class Templator {
|
||||||
}
|
}
|
||||||
private void parseTemplate(TemplateNode root, String tmpl, MutableInt m){
|
private void parseTemplate(TemplateNode root, String tmpl, MutableInt m){
|
||||||
StringBuilder data = new StringBuilder();
|
StringBuilder data = new StringBuilder();
|
||||||
|
StringBuilder tags = new StringBuilder();
|
||||||
boolean tagOpen = false;
|
boolean tagOpen = false;
|
||||||
boolean secondOpenBracet = false;
|
|
||||||
boolean secondCloseBracet = false;
|
|
||||||
|
|
||||||
for(; m.i<tmpl.length(); ++m.i){
|
for(; m.i<tmpl.length(); ++m.i){
|
||||||
char c = tmpl.charAt(m.i);
|
char c = tmpl.charAt(m.i);
|
||||||
switch(c){
|
String d = ""+ c + (m.i+1<tmpl.length() ? tmpl.charAt(m.i+1) : ' ');
|
||||||
case '{':
|
switch( d ){
|
||||||
c = tmpl.charAt(++m.i);
|
case "{{":
|
||||||
switch(c){
|
root.addEntity(new TmplStaticString(data.toString()));
|
||||||
case '{':
|
data.delete(0, data.length());
|
||||||
root.addEntity(new TmplStaticString(data.toString()));
|
tags.delete(0, data.length());
|
||||||
data = new StringBuilder();
|
tags.append("{{");
|
||||||
break;
|
tagOpen = true;
|
||||||
default:
|
++m.i;
|
||||||
data.append('{').append(c);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case '}':
|
case "}}":
|
||||||
c = tmpl.charAt(++m.i);
|
if(!tagOpen){ // Tag not opened, incorrect enclosure
|
||||||
switch(c){
|
data.append(c);
|
||||||
case '}':
|
continue;
|
||||||
break;
|
|
||||||
default:
|
|
||||||
data.append('}').append(c);
|
|
||||||
}
|
}
|
||||||
|
tagOpen = false;
|
||||||
|
++m.i;
|
||||||
|
root.addEntity(new TmplDataAttribute(data.toString()));
|
||||||
|
data.delete(0, data.length());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
data.append(c);
|
data.append(c);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(tagOpen)
|
||||||
|
data.insert(0, tags);
|
||||||
if(data.length() > 0)
|
if(data.length() > 0)
|
||||||
root.addEntity(new TmplStaticString(data.toString()));
|
root.addEntity(new TmplStaticString(data.toString()));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,14 +52,14 @@ public class TemplatorTest {
|
||||||
assertEquals("<HTML>}}</HTML>",
|
assertEquals("<HTML>}}</HTML>",
|
||||||
new Templator("<HTML>}}</HTML>").compile());
|
new Templator("<HTML>}}</HTML>").compile());
|
||||||
assertEquals("<HTML></HTML>}}",
|
assertEquals("<HTML></HTML>}}",
|
||||||
new Templator("<HTML>}}</HTML>}}").compile());
|
new Templator("<HTML></HTML>}}").compile());
|
||||||
assertEquals("<HTML></HTML>{{",
|
assertEquals("<HTML></HTML>{{",
|
||||||
new Templator("<HTML></HTML>{{").compile());
|
new Templator("<HTML></HTML>{{").compile());
|
||||||
assertEquals("<HTML>{</HTML>",
|
assertEquals("<HTML>{</HTML>",
|
||||||
new Templator("<HTML>{</HTML>").compile());
|
new Templator("<HTML>{</HTML>").compile());
|
||||||
assertEquals("<HTML>}</HTML>{{",
|
assertEquals("<HTML>}</HTML>",
|
||||||
new Templator("<HTML>}</HTML>").compile());
|
new Templator("<HTML>}</HTML>").compile());
|
||||||
assertEquals("<HTML>{}</HTML>{{",
|
assertEquals("<HTML>{}</HTML>",
|
||||||
new Templator("<HTML>{}</HTML>").compile());
|
new Templator("<HTML>{}</HTML>").compile());
|
||||||
assertEquals("<HTML>{test}</HTML>",
|
assertEquals("<HTML>{test}</HTML>",
|
||||||
new Templator("<HTML>{test}</HTML>").compile());
|
new Templator("<HTML>{test}</HTML>").compile());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue