1 /*******************************************************************************
2 
3     Xml entities.
4 
5     Copyright:
6         Copyright (c) 2009-2016 dunnhumby Germany GmbH.
7         All rights reserved.
8 
9     License:
10         Boost Software License Version 1.0. See LICENSE_BOOST.txt for details.
11         Alternatively, this file may be distributed under the terms of the Tango
12         3-Clause BSD License (see LICENSE_BSD.txt for details).
13 
14 *******************************************************************************/
15 
16 module ocean.text.entities.XmlEntitySet;
17 
18 
19 
20 import ocean.core.Array;
21 
22 import ocean.text.entities.model.IEntitySet;
23 
24 import ocean.meta.types.Qualifiers;
25 
26 /*******************************************************************************
27 
28     Xml entity set class.
29 
30 *******************************************************************************/
31 
32 public class XmlEntitySet : IEntitySet
33 {
34     /***************************************************************************
35 
36         This alias.
37 
38     ***************************************************************************/
39 
40     public alias typeof(this) This;
41 
42 
43     /***************************************************************************
44 
45         Xml character entities
46 
47     ***************************************************************************/
48 
49     public static immutable Entity[] xml_entities =
50     [
51         {"amp",    0x0026}, // '&'
52         {"quot",   0x0022}, // '"'
53         {"lt",     0x003C}, // '<'
54         {"gt",     0x003E}, // '>'
55         {"apos",   0x0027}, // '''
56     ];
57 
58 
59     /***************************************************************************
60 
61         Returns the list of entities.
62 
63     ***************************************************************************/
64 
65     public override const(Entity)[] entities ( )
66     {
67         return This.xml_entities;
68     }
69 
70 
71     /***************************************************************************
72 
73         Gets the fully encoded form of an entity.
74 
75         Params:
76             unicode = unicode of entity to encode
77             output = output buffer
78 
79         Returns:
80             the fully encoded form of the entity, or "" if the unicode value
81             passed is not an encodable entity
82 
83     ***************************************************************************/
84 
85     public override char[] getEncodedEntity ( dchar unicode, ref char[] output )
86     {
87         auto name = this.getName(unicode);
88         if ( name.length )
89         {
90             output.concat("&"[], name, ";"[]);
91         }
92         else
93         {
94             output.length = 0;
95         }
96 
97         return output;
98     }
99 }
100