浏览代码

Added text.ini to sidebar.

Brucey 2 年之前
父节点
当前提交
e7007e660b

+ 98 - 0
docs/api/text/text.ini/tini.md

@@ -0,0 +1,98 @@
+---
+id: tini
+title: TIni
+sidebar_label: TIni
+---
+
+Represents the contents of an ini file.
+
+
+The global section index is defined by [INI_GLOBAL_SECTION](../../../text/text.ini/#const-iniglobalsectionint-0).
+You should call [Free](../../../text/text.ini/tini/#method-free)() when you are finished working with it, to allow it to clean up any resources it is using.
+
+
+## Constructors
+
+### `Method New()`
+
+Creates a new empty [TIni](../../../text/text.ini/tini) instance.
+
+<br/>
+
+## Methods
+
+### `Method Save(path:String)`
+
+Saves the ini file to the specified <b>path</b>.
+
+<br/>
+
+### `Method Save(stream:TStream)`
+
+Saves the ini file to the specified <b>stream</b>.
+
+Does not close the [TStream](../../../brl/brl.stream/tstream).
+
+
+<br/>
+
+### `Method CountSections:Int()`
+
+Returns the number of sections.
+
+<br/>
+
+### `Method GetSection:TIniSection(index:Int)`
+
+Returns the section at the given <b>index</b>, or [Null](../../../brl/brl.blitz/#null) if the index is out of bounds.
+
+<br/>
+
+### `Method FindSection:TIniSection(name:String)`
+
+Finds a section by <b>name</b>.
+
+#### Returns
+The named section, or Null if not found.
+
+
+<br/>
+
+### `Method AddSection:TIniSection(name:String)`
+
+Adds a section with the specified <b>name</b>.
+
+There is no check done to see if a section with the specified name already exists - multiple sections of the same name are allowed.
+
+
+<br/>
+
+### `Method RemoveSection(index:Int)`
+
+Removes a section at the given <b>index</b>.
+
+<br/>
+
+### `Method Free()`
+
+Frees instance and associated data.
+
+<br/>
+
+## Functions
+
+### `Function Load:TIni(path:String)`
+
+Loads an ini file at the given <b>path</b>.
+
+<br/>
+
+### `Function Load:TIni(stream:TStream)`
+
+Loads an ini file from the given <b>stream</b>.
+
+Does not close the [TStream](../../../brl/brl.stream/tstream).
+
+
+<br/>
+

+ 41 - 0
docs/api/text/text.ini/tiniproperty.md

@@ -0,0 +1,41 @@
+---
+id: tiniproperty
+title: TIniProperty
+sidebar_label: TIniProperty
+---
+
+An ini property, with a name and value.
+
+
+## Methods
+
+### `Method GetName:String()`
+
+Returns the name of the property.
+
+<br/>
+
+### `Method SetName(name:String)`
+
+Sets the name the property.
+
+<br/>
+
+### `Method GetValue:String()`
+
+Returns the value for the property
+
+<br/>
+
+### `Method SetValue(value:String)`
+
+Sets the value for the property
+
+<br/>
+
+### `Method Remove()`
+
+Removes the property from its section.
+
+<br/>
+

+ 53 - 0
docs/api/text/text.ini/tinisection.md

@@ -0,0 +1,53 @@
+---
+id: tinisection
+title: TIniSection
+sidebar_label: TIniSection
+---
+
+An ini section.
+
+
+## Methods
+
+### `Method GetName:String()`
+
+Returns the name of the section, or Null if it is the global section.
+
+<br/>
+
+### `Method SetName(name:String)`
+
+Sets the name of the section.
+
+<br/>
+
+### `Method CountProperties:Int()`
+
+Returns the number of properties in the section.
+
+<br/>
+
+### `Method GetProperty:TIniProperty(index:Int)`
+
+Returns a property at the given <b>index</b> position, or Null if the <b>index</b> is out of range.
+
+<br/>
+
+### `Method FindProperty:TIniProperty(name:String)`
+
+Finds the property with the given <b>name</b>, or [Null](../../../brl/brl.blitz/#null) if not found.
+
+<br/>
+
+### `Method AddProperty:TIniProperty(name:String, value:String)`
+
+Adds a new property to the section using the specified <b>name</b> and <b>value</b>
+
+<br/>
+
+### `Method RemoveProperty(index:Int)`
+
+Removes the property with the given <b>index</b> from the section.
+
+<br/>
+

+ 173 - 0
docs/api/text/text_ini.md

@@ -0,0 +1,173 @@
+---
+id: text.ini
+title: Text.Ini
+sidebar_label: Introduction
+---
+
+
+Ini files (short for initialization files) are simple text files used to store settings and configurations
+for applications. They are organized into sections, each containing key-value pairs known as properties. Ini
+files are a popular choice for storing settings because they are easy to read and modify by both humans and programs.
+
+In this introduction, we will discuss the Ini file format in detail, covering its typical use cases,
+properties and sections, and how to use the module in BlitzMax to load, save, and edit Ini files.
+By the end of this guide, you will have the knowledge to create your own Ini files, either with a separate editor or
+using the `text.ini` module in BlitzMax.
+
+## Understanding the Ini File Format
+
+An Ini file is composed of sections, where each section starts with a section name enclosed in square brackets
+(e.g., [SectionName]). Underneath each section are properties, which are key-value pairs separated by an equals
+sign (=). For example:
+
+```ini
+[Settings]
+Volume=80
+FullScreen=False
+Resolution=1920x1080
+
+[UserProfile]
+Username=JohnDoe
[email protected]
+```
+
+In this example, there are two sections, "Settings" and "UserProfile". The "Settings" section contains three
+properties: Volume, FullScreen, and Resolution.
+
+## Using the module
+
+The `text.ini` module provides a simple and efficient way to work with Ini files in BlitzMax.
+The following subsections will guide you through loading, saving, and editing Ini files using the module.
+
+### Loading an Ini File
+
+To load an Ini file from disk, use the `Load` function, providing the file path:
+
+```blitzmax
+Local iniFile:TIni = TIni.Load("config.ini")
+```
+
+Alternatively, to load an Ini file from a [TStream](../../brl/brl.stream/tstream), use the Load function with the stream as the argument:
+
+```blitzmax
+Local stream:TStream = ReadFile("config.ini")
+Local iniFile:TIni = TIni.Load(stream)
+```
+
+### Saving an Ini File
+
+To save an Ini file to disk, use the `Save` method and provide the file path:
+
+```blitzmax
+iniFile.Save("config.ini")
+```
+
+To save an Ini file to a [TStream](../../brl/brl.stream/tstream), use the `Save` method with the stream as the argument:
+
+```blitzmax
+Local stream:TStream = WriteFile("config.ini")
+iniFile.Save(stream)
+```
+
+### Working with Sections and Properties
+
+To create a new section, use the `AddSection` method:
+
+```blitzmax
+Local section:TIniSection = iniFile.AddSection("Settings")
+```
+
+To find a section by its name, use the `FindSection` method:
+
+```blitzmax
+Local section:TIniSection = iniFile.FindSection("Settings")
+```
+
+To add a new property to a section, use the `AddProperty` method:
+
+```blitzmax
+section.AddProperty("Volume", "80")
+```
+
+To find a property by its name, use the `FindProperty` method:
+
+```blitzmax
+Local property:TIniProperty = section.FindProperty("Volume")
+```
+
+To get or set a property's value, use the `GetValue` and `SetValue` methods:
+
+```blitzmax
+Local volume:Int = Int(property.GetValue())
+property.SetValue("85")
+```
+
+### Cleaning Up
+
+When you are done working with an Ini file, call the Free method to release any resources used by the [TIni](../../text/text.ini/tini) instance:
+
+```blitzmax
+iniFile.Free()
+```
+
+Here is a complete example that demonstrates how to create, edit, and save an Ini file using the text.ini module:
+
+```blitzmax
+SuperStrict
+
+Framework Text.Ini
+
+' Create a new empty TIni instance
+Local iniFile:TIni = New TIni
+
+' Add sections and properties
+Local settingsSection:TIniSection = iniFile.AddSection("Settings")
+settingsSection.AddProperty("Volume", "80")
+settingsSection.AddProperty("FullScreen", "False")
+settingsSection.AddProperty("Resolution", "1920x1080")
+
+Local userProfileSection:TIniSection = iniFile.AddSection("UserProfile")
+userProfileSection.AddProperty("Username", "JohnDoe")
+userProfileSection.AddProperty("Email", "[email protected]")
+
+' Save the Ini file to disk
+iniFile.Save("config.ini")
+
+' Load the Ini file from disk
+Local loadedIniFile:TIni = TIni.Load("config.ini")
+
+' Retrieve and modify a property
+Local section:TIniSection = loadedIniFile.FindSection("Settings")
+Local property:TIniProperty = section.FindProperty("Volume")
+Local volume:Int = Int(property.GetValue())
+property.SetValue(String(volume + 5))
+
+' Save the modified Ini file to disk
+loadedIniFile.Save("config_modified.ini")
+
+' Clean up
+iniFile.Free()
+loadedIniFile.Free()
+```
+
+This example creates a new Ini file with two sections and several properties, saves it to disk, loads it back,
+modifies a property, and then saves the modified Ini file to a new file. The result is two Ini files: "config.ini"
+containing the original settings, and "config_modified.ini" containing the modified settings.
+
+
+
+## Types
+| Type | Description |
+|---|---|
+| [TIni](../../text/text.ini/tini) | Represents the contents of an ini file. |
+| [TIniSection](../../text/text.ini/tinisection) | An ini section. |
+| [TIniProperty](../../text/text.ini/tiniproperty) | An ini property, with a name and value. |
+
+## Consts
+
+### `Const INI_GLOBAL_SECTION:Int = 0`
+
+The index that indicates the global section.
+
+<br/>
+

+ 10 - 0
website/sidebars.json

@@ -412,6 +412,16 @@
           "api/text/text.format/tformatter"
         ]
       },
+      {
+        "type": "subcategory",
+        "label": "Ini",
+        "ids": [
+          "api/text/text.ini",
+          "api/text/text.ini/tini",
+          "api/text/text.ini/tiniproperty",
+          "api/text/text.ini/tinisection"
+        ]
+      },
       {
         "type": "subcategory",
         "label": "JConv",