INIs parsen, erstellen und modifizieren
Übersicht

![]() |
JolinahBetreff: INIs parsen, erstellen und modifizieren |
![]() Antworten mit Zitat ![]() |
---|---|---|
Ich weiss, es gibt schon einen (bzw. viele) INI-Parser, aber ich hatte gerade nichts besseres zu tun ![]() Vorteile: ![]() ![]() Nachteile: ![]() ![]() Alles in einer Datei, zum einfachen Importieren mit Import "dateiname.bmx": BlitzMax: [AUSKLAPPEN] Rem Und ein kleines Beispiel: BlitzMax: [AUSKLAPPEN] 'Ini Datei erstellen Edit: Ich habe die Klasse noch etwas erweitert und ein Modul daraus gemacht. Wer also lieber das Modul haben möchte: https://https://github.com/Jolinah/mzehr.ini (Quellcode) https://github.com/Jolinah/mzehr.ini/releases (Download-Pakete, vorkompiliert für Win32) |
||
- Zuletzt bearbeitet von Jolinah am Do, März 22, 2018 16:09, insgesamt einmal bearbeitet
#ReaperNewsposter |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Der Thread ist zwar nun schon etwas älter, aber ich hoffe das macht nun nichts.. ![]() Ich habe mal deinen tollen Ini-Parser zu einem "vollwertigem" Modul mit ein wenig schlechter Dokumentation "erweitert". Da ich euch das nun nicht vorenthalten wollte, hier mal der Code: Code: [AUSKLAPPEN] SuperStrict
Rem bbdoc: Ini-Parser by Jolinah. about: For more information visit http://www.blitzforum.de/forum/viewtopic.php?t=16991 End Rem Module Jolinah.IniParser ModuleInfo "Version: 1.00" ModuleInfo "Author: Jolinah" ModuleInfo "License: Public Domain" ModuleInfo "History: 1.00 Converted into a module" Import BRL.FileSystem Import BRL.Retro Rem bbdoc: Ini-File about: Load, create, change and save a Ini-File End Rem Type TIniFile Field Path:String Field Groups:TList Rem bbdoc: Creates a Ini-File returns: Returns a handler to modify the Ini-File End Rem Function Create:TIniFile(Path:String) Local f:TIniFile = New TIniFile f.Path = Path f.Groups = New TList Return f End Function Rem bbdoc: Loads a Ini-File returns: Returns a handler to modify the Ini-File End Rem Function Load:TIniFile(Path:String) Local s:TStream = ReadFile(Path) If s = Null Then Return Null Local f:TIniFile = TIniFile.Create(Path) Local line:String Local variable:String[] Local group:TIniGroup While Not Eof(s) line = ReadLine(s) line = line.Trim() If Left(line, 1) = "[" line = Mid(line, 2) line = Left(line, line.Length - 1) group = f.AddGroup(line) Else If group <> Null variable = Split(line, "=") If variable.Length > 1 group.AddVar(variable[0].Trim(), variable[1].Trim()) EndIf EndIf Wend CloseFile(s) Return f End Function Rem bbdoc: Adds a group to a Ini-File returns: Returns a handler of a group in the Ini-File End Rem Method AddGroup:TIniGroup(Name:String) Local g:TIniGroup = TIniGroup.Create(Name) Groups.AddLast(g) Return g End Method Rem bbdoc: Gets a group of a Ini-File returns: Returns a handler of a group in the Ini-File End Rem Method GetGroup:TIniGroup(Name:String) For Local g:TIniGroup = EachIn Groups If g.Name = Name Then Return g Next Return Null End Method Rem bbdoc: Gets a variable of a group returns: Returns a handler of a variable in a group End Rem Method GetVar:TIniVar(GroupName:String, VarName:String) Local g:TIniGroup = GetGroup(GroupName) If g = Null Then Return Null Return g.GetVar(VarName) End Method Rem bbdoc: Saves a created or changed Ini-File End Rem Method Save() Local s:TStream = WriteFile(Path) If s = Null Then Return For Local g:TIniGroup = EachIn Groups WriteLine(s, "[" + g.Name + "]") For Local v:TIniVar = EachIn g.Vars WriteLine(s, v.Name + "=" + v.Value) Next WriteLine(s, "") Next CloseFile(s) End Method End Type Rem bbdoc: Ini-Group about: Creates or change a group of a Ini-File End Rem Type TIniGroup Rem bbdoc: Change or get the name of a group End Rem Field Name:String Field Vars:TList Rem bbdoc: Creates a group in a Ini-File returns: Returns a handler of a group End Rem Function Create:TIniGroup(Name:String) Local g:TIniGroup = New TIniGroup g.Name = Name g.Vars = New TList Return g End Function Rem bbdoc: Adds a variable to a group returns: Returns a handler of a variable in a group End Rem Method AddVar:TIniVar(Name:String, Value:String) Local v:TIniVar = TIniVar.Create(Name, Value) Vars.AddLast(v) Return v End Method Rem bbdoc: Gets a variable of a group returns: Returns a handler of a variable in a group End Rem Method GetVar:TIniVar(Name:String) For Local v:TIniVar = EachIn Vars If v.Name = Name Then Return v Next Return Null End Method End Type Rem bbdoc: Ini-Variable about: Creates or change a variable of a group End Rem Type TIniVar Rem bbdoc: Change or get the name of a variable End Rem Field Name:String Rem bbdoc: Change or get the value of a variable End Rem Field Value:String Rem bbdoc: Creates a variable in a group returns: Returns a handler of a variable in a group End Rem Function Create:TIniVar(Name:String, Value:String) Local v:TIniVar = New TIniVar v.Name = Name v.Value = Value Return v End Function End Type Function Split:String[](str:String, separator:String) Local ret:String[] Local pos:Int = 0 Local old_pos:Int = 0 pos = Instr(str, separator) old_pos = 1 - separator.Length While pos > 0 ret = ret[..ret.Length+1] ret[ret.Length-1] = Mid(str, old_pos + separator.Length, pos - (old_pos + separator.Length)) old_pos = pos pos = Instr(str, separator, old_pos + separator.Length) Wend ret = ret[..ret.Length+1] ret[ret.Length-1] = Mid(str, old_pos + separator.Length) Return ret End Function Ich hoffe du hast nichts dagegen ![]() Allerdings weiß ich nun nicht genau, unter welcher Lizenz das Modul-Board nun eigentlich läuft. Ich hoffe es kann wer so gebrauchen. MfG #Reaper PS: Mein Englisch ist ja nicht sonderlich toll, wenn jemand einen Fehler findet... darf er ihn behalten oder ihn mir per PN zusenden. ;D |
||
AMD Athlon 64 3500+, ATI AX800 Pro/TD, 2048 MB DRR 400 von Infineon, ♥RIP♥ (2005 - Juli 2015 -> sic!)
Blitz3D, BlitzMax, MaxGUI, Monkey X; Win7 |
- Zuletzt bearbeitet von #Reaper am Sa, Apr 05, 2008 15:22, insgesamt 3-mal bearbeitet
![]() |
Jolinah |
![]() Antworten mit Zitat ![]() |
---|---|---|
Danke, habe nichts dagegen ![]() Wers brauchen kann, der darf. Wenn was schlimmes mit dem System passiert, bin ich nicht schuld ![]() |
||
![]() |
BtbN |
![]() Antworten mit Zitat ![]() |
---|---|---|
Wenn du schon nicht gut Englisch kannst("...of Jolinah"), dann schreib doch wenigstens die Doku-Einträge auf Deutsch.
Ist der Verständlichkeit extremst zuträglich. |
||
#ReaperNewsposter |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
BORNtobeNAMELESS hat Folgendes geschrieben: Wenn du schon nicht gut Englisch kannst("...of Jolinah"), dann schreib doch wenigstens die Doku-Einträge auf Deutsch.
Ist der Verständlichkeit extremst zuträglich. ![]() Nja ![]() Habe vergessen das zu erwähnen, wollte ich eigentlich machen ^^° Sorry ![]() Naja, war auch hauptsächlich nur gedacht für's Highlighten... |
||
AMD Athlon 64 3500+, ATI AX800 Pro/TD, 2048 MB DRR 400 von Infineon, ♥RIP♥ (2005 - Juli 2015 -> sic!)
Blitz3D, BlitzMax, MaxGUI, Monkey X; Win7 |
![]() |
d-bug |
![]() Antworten mit Zitat ![]() |
---|---|---|
Heißt es nicht "...by Jolinah"? ![]() |
||
#ReaperNewsposter |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
d-bug hat Folgendes geschrieben: Heißt es nicht "...by Jolinah"?
![]() ![]() Langsam tue ich mich hier echt mehr als nur blamieren ![]() ![]() |
||
AMD Athlon 64 3500+, ATI AX800 Pro/TD, 2048 MB DRR 400 von Infineon, ♥RIP♥ (2005 - Juli 2015 -> sic!)
Blitz3D, BlitzMax, MaxGUI, Monkey X; Win7 |
![]() |
Jolinah |
![]() Antworten mit Zitat ![]() |
---|---|---|
Und Modul heisst module, weiterhin wird in Englisch nicht jedes Nomen gross geschrieben. Ist mir nur so aufgefallen, jetzt wo ich es auch kurz überflogen habe ![]() |
||
#ReaperNewsposter |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Ubs, schusselfehler. Eigentlich weiß ich ja, das man Modul im englischem module schreibt ![]() Naja, habs so an mir, auch im englischem Nomen groß zu schreiben. ![]() ![]() Btw: Habs jetzt mal die Lizenz "Public Domain" genommen. (Btw @Admins und Mods: Ihr habt für das Modul-Board keine Lizenz gesetzt. ![]() |
||
AMD Athlon 64 3500+, ATI AX800 Pro/TD, 2048 MB DRR 400 von Infineon, ♥RIP♥ (2005 - Juli 2015 -> sic!)
Blitz3D, BlitzMax, MaxGUI, Monkey X; Win7 |
![]() |
Markus2 |
![]() Antworten mit Zitat ![]() |
---|---|---|
@Jolinah
dein INI Kram kann ich gerade gebrauchen , Danke dafür ![]() |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group