Welcome to Web-News
A Web-based News Reader
Subject Re: Has anyone written an INI parser in tango?
From Janderson <ask@me.com>
Date Sat, 13 Sep 2008 12:37:16 -0700
Newsgroups digitalmars.D

Rayne wrote:
> Walter Bright Wrote:
>
>> Rayne wrote:
>>> Just wondering if anyone had because it doesnt seen that the creators
>>> of Tango have, and their crappy properties stuff doesnt appeal to me
>>> in the least bit.
>> Here's a simple one I wrote a while back. A description of the file
>> format is here: http://openrj.sourceforge.net/
>>
>> // Written in the D programming language
>> // placed into Public Domain
>> // Written by Walter Bright
>>
>> module std.openrj;
>>
>> import std.string;
>>
>> alias char[][] [char[]] [] openrj_t;
>>
>> class OpenrjException : Exception
>> {
>>      uint linnum;
>>
>>      this(uint linnum, char[] msg)
>>      {
>>         this.linnum = linnum;
>>         super(std.string.format("OpenrjException line %s: %s", linnum, msg));
>>      }
>> }
>>
>> openrj_t parse(char[] db)
>> {
>>      openrj_t rj;
>>      char[][] lines;
>>      char[][] [char[]] record;
>>
>>      lines = std.string.splitlines(db);
>>
>>      for (uint linnum = 0; linnum < lines.length; linnum++)
>>      {
>>         char[] line = lines[linnum];
>>
>>         // Splice lines ending with backslash
>>         while (line.length && line[length - 1] == '\\')
>>         {
>>             if (++linnum == lines.length)
>>                 throw new OpenrjException(linnum, "no line after \\ line");
>>             line = line[0 .. length - 1] ~ lines[linnum];
>>         }
>>
>>         if (line[0 .. 2] == "%%")
>>         {
>>             // Comment lines separate records
>>             if (record)
>>                 rj ~= record;
>>             record = null;
>>             line = null;
>>             continue;
>>         }
>>
>>         int colon = std.string.find(line, ':');
>>         if (colon == -1)
>>             throw new OpenrjException(linnum, "'key : value' expected");
>>
>>         char[] key = std.string.strip(line[0 .. colon]);
>>         char[] value = std.string.strip(line[colon + 1 .. length]);
>>
>>         char[][] fields = record[key];
>>         fields ~= value;
>>         record[key] = fields;
>>      }
>>      if (record)
>>         rj ~= record;
>>      return rj;
>> }
>
> Thanks for the effort, however as it turns out I was being an idiot, I figured out how the properties work in Tango, its basicly an INI file. At least it works almost the same.

I know this has been solved but I'd like to point out that windows
offers GetPrivateProfileString.  Its not portable and not that efficient
(although that would only be a concern if your reading 10000's of entries).

http://msdn.microsoft.com/en-us/library/ms724353(VS.85).aspx

-Koel

Recent messages in this thread
 
-# Has anyone written an INI parser in tango? Rayne 11-Sep-2008 08:38 pm
.-# Re: Has anyone written an INI parser in tango? Anyone 12-Sep-2008 12:11 am
.|-# Re: Has anyone written an INI parser in tango? Jarrett Billingsley 12-Sep-2008 12:17 am
.|.\# Re: Has anyone written an INI parser in tango? Manfred_Nowak 12-Sep-2008 01:14 am
.-# Re: Has anyone written an INI parser in tango? Chris R. Miller 12-Sep-2008 01:56 am
.|\# Re: Has anyone written an INI parser in tango? Rayne 12-Sep-2008 02:30 am
.-# Re: Has anyone written an INI parser in tango? Bill Baxter 12-Sep-2008 02:16 am
.||# Re: Has anyone written an INI parser in tango? Rayne 12-Sep-2008 02:28 am
.|-# Re: Has anyone written an INI parser in tango? Chris R. Miller 12-Sep-2008 02:43 am
.|.-# Re: Has anyone written an INI parser in tango? Bill Baxter 12-Sep-2008 04:17 am
.|.||# Re: Has anyone written an INI parser in tango? Chris R. Miller 12-Sep-2008 04:40 pm
.|.|-# Re: Has anyone written an INI parser in tango? Jesse Phillips 12-Sep-2008 10:46 pm
.|.|.\# Re: Has anyone written an INI parser in tango? Bill Baxter 12-Sep-2008 11:02 pm
.|.\# Re: Has anyone written an INI parser in tango? David Wilson 12-Sep-2008 01:10 pm
.-# Re: Has anyone written an INI parser in tango? Walter Bright 13-Sep-2008 12:13 am
..-# Re: Has anyone written an INI parser in tango? Rayne 13-Sep-2008 02:28 am
...\# Re: Has anyone written an INI parser in tango? (Current message) Janderson 13-Sep-2008 03:37 pm