1 /** 2 * Copyright: Copyright (c) 2011 Jacob Carlborg. All rights reserved. 3 * Authors: Jacob Carlborg 4 * Version: Initial created: Aug 6, 2011 5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) 6 */ 7 module spec.serialization.Util; 8 9 import mambo.core..string; 10 11 bool containsDefaultXmlContent (string source) 12 { 13 return source.containsXmlHeader() && 14 source.containsArchive() && 15 source.containsXmlTag("data"); 16 } 17 18 bool containsXmlHeader (string source) 19 { 20 return source.contains(`<?xml version="1.0" encoding="UTF-8"?>`); 21 } 22 23 bool containsArchive (string source) 24 { 25 return source.containsArchiveHeader() && source.contains("</archive>"); 26 } 27 28 bool containsArchiveHeader (string source) 29 { 30 return source.contains(`<archive type="org.dsource.orange.xml" version="1.0.0">`) || 31 source.contains(`<archive version="1.0.0" type="org.dsource.orange.xml">`); 32 } 33 34 bool containsXmlTag (string source, string tag, bool simple = false) 35 { 36 return source.containsXmlTag(tag, null, null, simple); 37 } 38 39 bool containsXmlTag (string source, string tag, string attributes, bool simple = false) 40 { 41 return source.containsXmlTag(tag, attributes, null, simple); 42 } 43 44 bool containsXmlTag (string source, string tag, string attributes, string content, bool simple = false) 45 { 46 string pattern = '<' ~ tag; 47 48 if (attributes.length > 0) 49 pattern ~= ' ' ~ attributes; 50 51 if (simple) 52 return source.contains(pattern ~ "/>"); 53 54 if (content.length > 0) 55 return source.contains(pattern ~ '>' ~ content ~ "</" ~ tag ~ '>'); 56 57 return source.contains(pattern ~ '>') && source.contains("</" ~ tag ~ '>'); 58 }