From 88477e97c9c09ffc1c3717aa4652c719994951a7 Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Tue, 24 Mar 2015 13:56:53 +0000 Subject: [PATCH] Fixed Template class to be much nicer and pass all tests --- src/zutil/net/ssdp/SSDPCustomInfo.java | 33 ++++++++++++++++++++ src/zutil/parser/MathParser.java | 12 ++++---- src/zutil/parser/Templator.java | 42 ++++++++++++++------------ src/zutil/test/TemplatorTest.java | 6 ++-- 4 files changed, 64 insertions(+), 29 deletions(-) create mode 100644 src/zutil/net/ssdp/SSDPCustomInfo.java diff --git a/src/zutil/net/ssdp/SSDPCustomInfo.java b/src/zutil/net/ssdp/SSDPCustomInfo.java new file mode 100644 index 0000000..70c2957 --- /dev/null +++ b/src/zutil/net/ssdp/SSDPCustomInfo.java @@ -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); +} diff --git a/src/zutil/parser/MathParser.java b/src/zutil/parser/MathParser.java index 25a5887..03b32ac 100644 --- a/src/zutil/parser/MathParser.java +++ b/src/zutil/parser/MathParser.java @@ -76,12 +76,12 @@ public class MathParser { } else{ if(c == '('){ - MathNode parantes = new MathNode(); - MathOperation previusParantes = previus; - parse(functionString, temp, previus, parantes); - previusParantes.math2 = parantes; - System.out.println(parantes); - container = parantes; + MathNode parenteses = new MathNode(); + MathOperation previousParanteses = previus; + parse(functionString, temp, previus, parenteses); + previousParanteses.math2 = parenteses; + System.out.println(parenteses); + container = parenteses; // get the next operation c = functionString.charAt(0); diff --git a/src/zutil/parser/Templator.java b/src/zutil/parser/Templator.java index cc4e724..971453a 100644 --- a/src/zutil/parser/Templator.java +++ b/src/zutil/parser/Templator.java @@ -75,37 +75,39 @@ public class Templator { } private void parseTemplate(TemplateNode root, String tmpl, MutableInt m){ StringBuilder data = new StringBuilder(); + StringBuilder tags = new StringBuilder(); boolean tagOpen = false; - boolean secondOpenBracet = false; - boolean secondCloseBracet = false; for(; m.i 0) root.addEntity(new TmplStaticString(data.toString())); } diff --git a/src/zutil/test/TemplatorTest.java b/src/zutil/test/TemplatorTest.java index 9d29052..6c91c72 100644 --- a/src/zutil/test/TemplatorTest.java +++ b/src/zutil/test/TemplatorTest.java @@ -52,14 +52,14 @@ public class TemplatorTest { assertEquals("}}", new Templator("}}").compile()); assertEquals("}}", - new Templator("}}}}").compile()); + new Templator("}}").compile()); assertEquals("{{", new Templator("{{").compile()); assertEquals("{", new Templator("{").compile()); - assertEquals("}{{", + assertEquals("}", new Templator("}").compile()); - assertEquals("{}{{", + assertEquals("{}", new Templator("{}").compile()); assertEquals("{test}", new Templator("{test}").compile());