2 * This file is part of gtkD.
4 * gtkD 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.
9 * gtkD 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 gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 module utils
.DefReader
;
25 * Reads and processes the API defintion file
26 * Stores global values:
30 public class DefReader
33 private import std
.file
;
34 private import std
.string
;
36 private import std
.stdio
;
38 private import utils
.GtkDClass
;
50 * Creates a new DegReader.
51 * Reads the entire definition file
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()
65 str ~= "\n[DefReader]"
66 ~ "\nfileName = "~fileName
67 ~ "\ncurrLine = "~std
.string
.toString(currLine
)
68 ~ "\nfullLine = "~fullLine
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(bool skipEmpty
= true)
90 if ( currLine
< lines
.length
)
92 fullLine
= lines
[currLine
++];
93 line
= std
.string
.strip(fullLine
.dup
);
96 && (commentCount
> 0 || line
.length
==0 || line
[0] == '#' || GtkDClass
.startsWith(line
, "#*") )
97 && currLine
< lines
.length
100 if ( GtkDClass
.startsWith(line
, "#*") )
104 else if ( GtkDClass
.startsWith(line
, "*#") )
109 fullLine
= lines
[currLine
++];
110 line
= std
.string
.strip(fullLine
.dup
);
114 if ( line
.length
> 0 )
116 int pos
= std
.string
.find(line
, ':');
119 key
= std
.string
.strip(line
[0 .. pos
]);
120 value
= std
.string
.strip(line
[pos
+1 .. line
.length
]);
129 //writefln("key=%s value=%s",key,value);
135 * Gets the key of the current key/value pair
136 * Returns: The current key
144 * Gets the value of the current key/value pair
145 * Returns: The current value
155 return std
.string
.find(" 1 ok OK Ok true TRUE True Y y yes YES Yes ", value
) > 0;
163 * Gets the current line number
164 * Returns: The current line number