iniparser

package module
v0.0.0-...-54566c5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2022 License: MIT Imports: 6 Imported by: 0

README

iniparser

A simple parser for ini files made for personal use.

WARNING

I do not consider this stable to use in any kind of serious/production project, use it at your own risk.

TODO
  • Expose an easier way to access single block data from a INI object
  • Add support for raw string parsing along side files
  • Add tests
  • Create instructions

Documentation

Index

Constants

View Source
const (
	WindowsLineEnd = "\r\n"
	LineEnd        = '\n'
	CommentStart   = ';'
	KeyValSep      = "="
)

Constants for file parsing

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	Content []byte
	Data    map[string]string
}

Block type contains all the data that describes a block with comments omitted. Content variable represents the raw data inside a ini file block including the header. Data variable stores string key-value pairs for easy access.

func (*Block) AddData

func (b *Block) AddData(kv []string)

func (*Block) AppendContent

func (b *Block) AppendContent(c []byte)

type INI

type INI struct {
	Blocks     map[string]Block
	Raw        []byte
	RawTrimmed []byte
}

INI type contains a map of blocks, raw data as a slice of bytes and data with comments trimmed as a slice of bytes

func NewINI

func NewINI(pathToIni string) *INI

Returns a pointer to unparsed INI struct Raw attribute should contain all the file contents as a byte slice once the INI is loaded call its Parse method to parse all the data in Raw attribute

func (*INI) GetBlockData

func (i *INI) GetBlockData(name string) map[string]string

func (*INI) Lines

func (c *INI) Lines(trimmed bool) [][]byte

Lines Method is used to return a slice of all lines in the config file if trimmed flag is false comments will be included otherwise the comments are excluded from the result

func (*INI) Parse

func (c *INI) Parse()

Parses all the data in the INI file which includes Removing comments Check if all keys have valid names Creation of blocks and parsing of block data

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL