1 module deepmagic.dom.xml.processing_instruction; 2 3 import deepmagic.dom; 4 5 class ProcessingInstruction : Item 6 { 7 private string content; 8 9 /** 10 * Construct a Processing Instruction section 11 * 12 * Params: 13 * content = the body of the instruction segment 14 * 15 * Throws: PIException if the segment body is illegal (contains "?>") 16 * 17 * Examples: 18 * -------------- 19 * auto item = new ProcessingInstruction("php"); 20 * // constructs <?php?> 21 * -------------- 22 */ 23 this(string content) 24 { 25 if (content.indexOf("?>") != -1) throw new PIException(content); 26 this.content = content; 27 } 28 29 /** 30 * Compares two processing instructions for equality 31 * 32 * Examples: 33 * -------------- 34 * ProcessingInstruction item1,item2; 35 * if (item1 == item2) { } 36 * -------------- 37 */ 38 override bool opEquals(Object o) 39 { 40 const item = toType!(const Item)(o); 41 const t = cast(ProcessingInstruction)item; 42 return t !is null && content == t.content; 43 } 44 45 /** 46 * Compares two processing instructions 47 * 48 * You should rarely need to call this function. It exists so that 49 * ProcessingInstructions can be used as associative array keys. 50 * 51 * Examples: 52 * -------------- 53 * ProcessingInstruction item1,item2; 54 * if (item1 < item2) { } 55 * -------------- 56 */ 57 override int opCmp(Object o) 58 { 59 const item = toType!(const Item)(o); 60 const t = cast(ProcessingInstruction)item; 61 return t !is null 62 && (content != t.content ? (content < t.content ? -1 : 1 ) : 0 ); 63 } 64 65 /** 66 * Returns the hash of a ProcessingInstruction 67 * 68 * You should rarely need to call this function. It exists so that 69 * ProcessingInstructions can be used as associative array keys. 70 */ 71 override size_t toHash() const { return hash(content); } 72 73 /** 74 * Returns a string representation of this ProcessingInstruction 75 */ 76 override string toString() const { return "<?" ~ content ~ "?>"; } 77 78 override @property bool isEmptyXML() const { return false; } /// Returns false always 79 }