Mercurial > projects > dil
comparison trunk/src/dil/HtmlEntities.d @ 786:3b34f6a95a27
Added and revised documenation comments.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sun, 24 Feb 2008 02:41:11 +0100 |
parents | 0c10255d8009 |
children |
comparison
equal
deleted
inserted
replaced
785:57ef69eced96 | 786:3b34f6a95a27 |
---|---|
4 +/ | 4 +/ |
5 module dil.HtmlEntities; | 5 module dil.HtmlEntities; |
6 | 6 |
7 import common; | 7 import common; |
8 | 8 |
9 /// A named HTML entity. | |
9 struct Entity | 10 struct Entity |
10 { | 11 { |
11 char[] name; | 12 char[] name; |
12 uint value; | 13 dchar value; |
13 } | 14 } |
14 | 15 |
16 /// The table of named HTML entities. | |
15 static const Entity[] namedEntities = [ | 17 static const Entity[] namedEntities = [ |
16 {"Aacute", '\u00C1'}, | 18 {"Aacute", '\u00C1'}, |
17 {"aacute", '\u00E1'}, | 19 {"aacute", '\u00E1'}, |
18 {"Acirc", '\u00C2'}, | 20 {"Acirc", '\u00C2'}, |
19 {"acirc", '\u00E2'}, | 21 {"acirc", '\u00E2'}, |
287 } | 289 } |
288 | 290 |
289 char[] generateHashAndValueArrays() | 291 char[] generateHashAndValueArrays() |
290 { | 292 { |
291 uint[] hashes; // String hashes. | 293 uint[] hashes; // String hashes. |
292 uint[] values; // Unicode codepoints. | 294 dchar[] values; // Unicode codepoints. |
293 // Build arrays: | 295 // Build arrays: |
294 foreach (entity; namedEntities) | 296 foreach (entity; namedEntities) |
295 { | 297 { |
296 auto hash = stringToHash(entity.name); | 298 auto hash = stringToHash(entity.name); |
297 auto value = entity.value; | 299 auto value = entity.value; |
328 hashesText ~= "];"; | 330 hashesText ~= "];"; |
329 valuesText ~= "];"; | 331 valuesText ~= "];"; |
330 return hashesText ~"\n"~ valuesText; | 332 return hashesText ~"\n"~ valuesText; |
331 } | 333 } |
332 | 334 |
333 // Mixin: | 335 version(DDoc) |
334 // private static const uint[] hashes; | 336 { |
335 // private static const dchar[] values; | 337 /// Table of hash values of the entities' names. |
336 mixin(generateHashAndValueArrays); | 338 private static const uint[] hashes; |
339 /// Table of Unicode codepoints. | |
340 private static const dchar[] values; | |
341 } | |
342 else | |
343 mixin(generateHashAndValueArrays); | |
337 // pragma(msg, generateHashAndValueArrays()); | 344 // pragma(msg, generateHashAndValueArrays()); |
338 | 345 |
339 /++ | 346 /// Converts a named HTML entity into its equivalent Unicode codepoint. |
340 Converts a named HTML entity into its equivalent Unicode codepoint. | 347 /// Returns: the entity's value or 0xFFFF if it doesn't exist. |
341 Returns 0xFFFF if entity doesn't exist. | |
342 +/ | |
343 dchar entity2Unicode(char[] entity) | 348 dchar entity2Unicode(char[] entity) |
344 { | 349 { |
345 auto hash = stringToHash(entity); | 350 auto hash = stringToHash(entity); |
346 // Binary search: | 351 // Binary search: |
347 size_t lower = void, index = void, upper = void; | 352 size_t lower = void, index = void, upper = void; |