comparison trunk/src/dil/SourceText.d @ 798:c24be8d4f6ab

Added documentation comments.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sat, 01 Mar 2008 02:53:06 +0100
parents 90668b83ae5e
children
comparison
equal deleted inserted replaced
797:cf2ad5df025c 798:c24be8d4f6ab
16 final class SourceText 16 final class SourceText
17 { 17 {
18 string filePath; /// The file path to the source text. Mainly used for error messages. 18 string filePath; /// The file path to the source text. Mainly used for error messages.
19 char[] data; /// The UTF-8, zero-terminated source text. 19 char[] data; /// The UTF-8, zero-terminated source text.
20 20
21 /// Constructs a SourceText object.
21 /// Params: 22 /// Params:
22 /// filePath = file path to the source file. 23 /// filePath = file path to the source file.
23 /// loadFile = whether to load the file in the constructor. 24 /// loadFile = whether to load the file in the constructor.
24 this(string filePath, bool loadFile = false) 25 this(string filePath, bool loadFile = false)
25 { 26 {
26 this.filePath = filePath; 27 this.filePath = filePath;
27 loadFile && load(); 28 loadFile && load();
28 } 29 }
29 30
31 /// Constructs a SourceText object.
30 /// Params: 32 /// Params:
31 /// filePath = file path for error messages. 33 /// filePath = file path for error messages.
32 /// data = memory buffer. 34 /// data = memory buffer.
33 this(string filePath, char[] data) 35 this(string filePath, char[] data)
34 { 36 {
35 this(filePath); 37 this(filePath);
36 this.data = data; 38 this.data = data;
37 addSentinelCharacter(); 39 addSentinelCharacter();
38 } 40 }
39 41
42 /// Loads the source text from a file.
40 void load(InfoManager infoMan = null) 43 void load(InfoManager infoMan = null)
41 { 44 {
42 if (!infoMan) 45 if (!infoMan)
43 infoMan = new InfoManager; 46 infoMan = new InfoManager;
44 assert(filePath.length); 47 assert(filePath.length);
48 auto converter = Converter(filePath, infoMan); 51 auto converter = Converter(filePath, infoMan);
49 data = converter.data2UTF8(rawdata); 52 data = converter.data2UTF8(rawdata);
50 addSentinelCharacter(); 53 addSentinelCharacter();
51 } 54 }
52 55
56 /// Adds '\0' to the text (if not already there.)
53 private void addSentinelCharacter() 57 private void addSentinelCharacter()
54 { 58 {
55 if (data.length == 0 || data[$-1] != 0) 59 if (data.length == 0 || data[$-1] != 0)
56 data ~= 0; 60 data ~= 0;
57 } 61 }