I've no idea here...
[gtkD.git] / wrap / utils / DefReader.d
blob162cb09552f78d94480d1112b427c6fb461b6889
1 /*
2 * This file is part of duit.
3 *
4 * duit is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
8 *
9 * duit is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with duit; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 module utils.DefReader;
22 //debug=file;
24 /**
25 * Reads and processes the API defintion file
26 * Stores global values:
27 * - license text
28 * -
30 public class DefReader
33 private import std.file;
34 private import std.string;
36 private import std.stdio;
38 private import utils.DuitClass;
40 char[] fileName;
41 char[][] lines;
43 char[] fullLine;
44 char[] key;
45 char[] value;
47 int currLine = 0;
49 /**
50 * Creates a new DegReader.
51 * Reads the entire definition file
52 * Params:
53 * fileName = The file name of the file containing the conversion definition
55 this ( char[] fileName )
57 this.fileName = fileName;
58 debug(file)writefln("DefReader.ctor fileName = %s", fileName);
59 lines = std.string.splitlines(cast(char[]) std.file.read(fileName));
62 public char[] toString()
64 char[] str;
65 str ~= "\n[DefReader]"
66 ~ "\nfileName = "~fileName
67 ~ "\ncurrLine = "~std.string.toString(currLine)
68 ~ "\nfullLine = "~fullLine
69 ~ "\nkey = "~key
70 ~ "\nvalue + "~value
72 return str;
75 char[] getFileName()
77 return fileName;
80 /**
81 * Gets the next key/value pair.
82 * both key and value a stripped of non visible start and ending chars
83 * Returns: The key after read the next key/value pair
85 char[] next(bit skipEmpty = true)
87 key.length = 0;
88 value.length = 0;
89 char[] line;
90 if ( currLine < lines.length )
92 fullLine = lines[currLine++];
93 line = std.string.strip(fullLine.dup);
94 int commentCount = 0;
95 while ( skipEmpty
96 && (commentCount > 0 || line.length ==0 || line[0] == '#' || DuitClass.startsWith(line, "#*") )
97 && currLine < lines.length
100 if ( DuitClass.startsWith(line, "#*") )
102 ++commentCount;
104 else if ( DuitClass.startsWith(line, "*#") )
106 --commentCount;
109 fullLine = lines[currLine++];
110 line = std.string.strip(fullLine.dup);
114 if ( line.length > 0 )
116 int pos = std.string.find(line, ':');
117 if ( pos > 0 )
119 key = std.string.strip(line[0 .. pos]);
120 value = std.string.strip(line[pos+1 .. line.length]);
123 else
125 key.length = 0;
126 value.length = 0;
129 //writefln("key=%s value=%s",key,value);
131 return key;
135 * Gets the key of the current key/value pair
136 * Returns: The current key
138 char[] getKey()
140 return key;
144 * Gets the value of the current key/value pair
145 * Returns: The current value
147 char[] getValue()
149 return value;
153 bit getValueBit()
155 return std.string.find(" 1 ok OK Ok true TRUE True Y y yes YES Yes ", value) > 0;
158 char[] getFullLine()
160 return fullLine;
163 * Gets the current line number
164 * Returns: The current line number
166 int getLineNumber()
168 return currLine;