8000 GitHub - moonbit-community/sw-ini: High-performance INI parser for MoonBit with nested section support.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

moonbit-community/sw-ini

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📝 sw-ini: A MoonBit INI Parser

English | 简体中文

Build Status License codecov

sw-ini is a high-performance INI parser for MoonBit applications. It provides a simple and efficient way to parse and access INI configuration files with a clean and intuitive API.

🚀 Key Features

  • 🔍 INI Parsing – Parse INI files with comprehensive error handling
  • 🛡️ Type Safety – Strongly typed access to configuration values
  • 🔄 Case Sensitivity Options – Configurable case sensitivity for section and key names
  • 🎯 Simple API – Easy to use with intuitive method names
  • 📦 Zero Dependencies – Pure MoonBit implementation with no external dependencies

📥 Installation

moon add ShellWen/sw_ini

🚀 Usage Guide for sw-ini

sw-ini provides a straightforward way to parse and access INI configuration files in your MoonBit applications.


📝 What is an INI File?

An INI file is a configuration file format that consists of sections and key-value pairs:

config.ini

[server]
host=localhost
port=3000

[database]
url=mysql://user:pass@localhost/dbname
max_connections=100

🔍 Basic Usage

The simplest way to use sw-ini is with the parse function:

fn main {
  let config_str = "[server]\nhost=localhost\nport=3000"
  let ini = @sw_ini.parse!(config_str)
  let host = ini.get(section="server", "host").unwrap()
  println("host=\{host}")
}

⚙️ Configuration Options

sw-ini offers configuration options when parsing:

// Case-sensitive parsing
let ini = @sw_ini.parse!(content, is_case_sensitive=true)

// Create an empty INI file object
let ini = @sw_ini.IniFile::new(is_case_sensitive=true)

🔄 Value Access

After parsing, you can access values using various methods:

let ini = @sw_ini.parse!(content)

// Get string value (with optional section)
let host = ini.get(section="server", "host")

// Get boolean value
let enabled = ini.get_bool(section="feature", "enabled")

// Get with default section (global)
let global_value = ini.get("global_key")

⚠️ Error Handling

sw-ini uses MoonBit's Result type for error handling:

match @sw_ini.parse?(content) {
  Ok(ini) =>
    // Use the INI file
    println("Parsed successfully")
  Err(e) =>
    // Handle parse error
    println("Error parsing INI file")
}

🛠️ Full Example

fn main {
  let content = #|[server]
                #|host=localhost
                #|port=3000
                #|enabled=true
                #|
                #|[database]
                #|url=mysql://localhost/db

  // Parse INI content
  let ini = @sw_ini.parse!(content)

  // Access various values
  let host = ini.get(section="server", "host").unwrap()
  let port = ini.get(section="server", "port").or("8080")
  let enabled = ini.get_bool(section="server", "enabled").unwrap()

  // Use values in your application
  if enabled {
    println("Server running at \{host}:\{port}")
  }
}

📜 License

This project is licensed under the Apache-2.0 License. See LICENSE for details.

📢 Contact & Support

👋 If you like this project, give it a ⭐! Happy coding! 🚀

About

High-performance INI parser for MoonBit with nested section support.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  
0