en:code:data:inifile
Differences
This shows you the differences between two versions of the page.
Previous revision | |||
— | en:code:data:inifile [2023/10/14 17:20] (current) – jmgr | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== IniFile ====== | ||
+ | This object allows you to read and write to a INI file. | ||
+ | ===== Quick Use ===== | ||
+ | Usable example: | ||
+ | <code javascript> | ||
+ | var myObject= new IniFile(); | ||
+ | myObject.load(" | ||
+ | myObject.setSection(" | ||
+ | if (myObject.keyExists(" | ||
+ | mytext = myObject.keyValue(" | ||
+ | newtext = mytext + " | ||
+ | myObject.setKeyValue(" | ||
+ | }else{ | ||
+ | myObject.setKeyValue(" | ||
+ | mytext = cfgini.keyValue(" | ||
+ | } | ||
+ | myObject.save(" | ||
+ | </ | ||
+ | Will result in value " | ||
+ | ===== Functions ===== | ||
+ | |||
+ | ==== IniFile ==== | ||
+ | Constructor function. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | var myObject = new IniFile(); | ||
+ | </ | ||
+ | <code javascript> | ||
+ | var myObject = new IniFile(parameters); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - parameters - (object) parameters | ||
+ | * < | ||
+ | * < | ||
+ | * encoding - ([[en: | ||
+ | |||
+ | === Exceptions === | ||
+ | * (ParameterTypeError) incorrect parameter type | ||
+ | * (ParameterCountError) incorrect parameter count | ||
+ | |||
+ | === Example === | ||
+ | Create a IniFile object. | ||
+ | <code javascript> | ||
+ | var myObject = new IniFile(); | ||
+ | </ | ||
+ | Create a IniFile object with parameters. | ||
+ | <code javascript> | ||
+ | var myObject = new IniFile({ | ||
+ | delimiter: " | ||
+ | commentCharacter: | ||
+ | }); | ||
+ | </ | ||
+ | |||
+ | ===== Methods ===== | ||
+ | |||
+ | ==== load ==== | ||
+ | Loads a file. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.load(filename); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - filename - (string) the filename of the file to open | ||
+ | |||
+ | === Returns === | ||
+ | * (IniFile) this IniFile | ||
+ | |||
+ | === Exceptions === | ||
+ | * (LoadFileError) cannot load the file | ||
+ | |||
+ | ==== save ==== | ||
+ | Saves a file. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.save(filename); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - filename - (string) the filename of the file to save | ||
+ | |||
+ | === Returns === | ||
+ | * (IniFile) this IniFile | ||
+ | |||
+ | === Exceptions === | ||
+ | * (SaveFileError) cannot save the file | ||
+ | |||
+ | ==== clear ==== | ||
+ | Clear the file. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.clear(); | ||
+ | </ | ||
+ | |||
+ | === Returns === | ||
+ | * (IniFile) this IniFile | ||
+ | |||
+ | ==== preserveDeletedData ==== | ||
+ | Preserve the deleted data as comments. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.preserveDeletedData(preserve); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - preserve - (boolean) should the deleted data preserved as comments | ||
+ | |||
+ | === Returns === | ||
+ | * (IniFile) this IniFile | ||
+ | |||
+ | ==== setDelimiter ==== | ||
+ | Set the value/data delimiter. Default is =. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.setDelimiter(delimiter); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - delimiter - (char) the delimiter to use | ||
+ | |||
+ | === Returns === | ||
+ | * (IniFile) this IniFile | ||
+ | |||
+ | ==== setCommentCharacter ==== | ||
+ | Set the comment character. Default is #. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.setCommentCharacter(commentchar); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - commentchar - (char) the comment character | ||
+ | |||
+ | === Returns === | ||
+ | * (IniFile) this IniFile | ||
+ | |||
+ | ==== setSection ==== | ||
+ | Sets the current INI section. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.setSection(sectionName); | ||
+ | </ | ||
+ | <code javascript> | ||
+ | myObject.setSection(sectionName, | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - sectionName - (string) the section name | ||
+ | - create - (boolean) create the section if it doesn' | ||
+ | |||
+ | === Returns === | ||
+ | * (IniFile) this IniFile | ||
+ | |||
+ | === Exceptions === | ||
+ | * (FindSectionError) cannot find the section | ||
+ | |||
+ | ==== setEncoding ==== | ||
+ | Sets the encoding to use. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.setEncoding(encoding); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - encoding - ([[en: | ||
+ | |||
+ | === Returns === | ||
+ | * (IniFile) this IniFile | ||
+ | |||
+ | ==== sectionAt ==== | ||
+ | Returns the section name at index **sectionIndex**. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.sectionAt(sectionIndex); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - sectionIndex - (integer) the section index | ||
+ | |||
+ | === Returns === | ||
+ | * (string) the section name | ||
+ | |||
+ | === Exceptions === | ||
+ | * (FindSectionError) cannot find the section | ||
+ | |||
+ | ==== deleteSection ==== | ||
+ | Deletes a section. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.deleteSection(sectionName); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - sectionName - (string) the section name | ||
+ | |||
+ | === Returns === | ||
+ | * (IniFile) this IniFile | ||
+ | |||
+ | === Exceptions === | ||
+ | * (FindSectionError) cannot find the section | ||
+ | |||
+ | ==== sectionCount ==== | ||
+ | Returns the number of sections. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.sectionCount(); | ||
+ | </ | ||
+ | |||
+ | === Returns === | ||
+ | * (integer) the section count | ||
+ | |||
+ | ==== keyExists ==== | ||
+ | Returns true if a key with **keyName** exists. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.keyExists(keyName); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - keyName - (string) the key name | ||
+ | |||
+ | === Returns === | ||
+ | * (boolean) true if a key with **keyName** exists | ||
+ | |||
+ | ==== keyAt ==== | ||
+ | Returns the name of the key at index **keyIndex**. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.keyAt(keyIndex); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - keyIndex - (integer) the key index | ||
+ | |||
+ | === Returns === | ||
+ | * (string) the key name | ||
+ | |||
+ | === Exceptions === | ||
+ | * (KeyError) cannot find the key | ||
+ | |||
+ | ==== keyValue ==== | ||
+ | Returns the value of the key **keyName**. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.keyValue(keyName); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - keyName - (string) the key name | ||
+ | |||
+ | === Returns === | ||
+ | * (string) the key value | ||
+ | |||
+ | === Exceptions === | ||
+ | * (KeyError) cannot find the key | ||
+ | ==== setKeyValue ==== | ||
+ | Sets the value of the key **keyName**. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.setKeyValue(keyName, | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - keyName - (string) the key name | ||
+ | - value - (string) the key value | ||
+ | |||
+ | === Returns === | ||
+ | * (IniFile) this IniFile | ||
+ | |||
+ | ==== deleteKey ==== | ||
+ | Delete the key **keyName**. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.deleteKey(keyName); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - keyName - (string) the key name | ||
+ | |||
+ | === Returns === | ||
+ | * (IniFile) this IniFile | ||
+ | |||
+ | === Exceptions === | ||
+ | * (KeyError) cannot find the key | ||
+ | |||
+ | ==== keyCount ==== | ||
+ | Returns the key count. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.keyCount(); | ||
+ | </ | ||
+ | |||
+ | === Returns === | ||
+ | * (integer) the key count |