rickyah / ini-parser Goto Github PK
View Code? Open in Web Editor NEWRead/Write an INI file the easy way!
License: MIT License
Read/Write an INI file the easy way!
License: MIT License
I might be doing something incorrect here, but I had issues when trying to look through all of the individual keys in the individual section.
IniData parsedData = fileIniData.ReadFile(file);
SectionDataCollection sections = new SectionDataCollection();
SectionDataCollection saved_sections new SectionDataCollection()
foreach (SectionData section in parsedData.Sections)
{
if (section.SectionName.Contains("some_text"))
sections.AddSection(section.SectionName);
}
foreach(SectionData section in sections)
{
foreach (KeyData key in section.Keys)
{
if (sections.ContainsSection(key.Value) == false)
saved_sections.AddSection(key.Value);
}
}
However, key.Count above was always 0. I would expect it to have all of the keys already. The way around it for me at least was to add a line to call GetSectionData to actually get all of the keys.
foreach(SectionData section in sections)
{
SectionData section_data = parsedData.Sections.GetSectionData(section.SectionName);
foreach (KeyData key in section_data.Keys)
{
if (sections.ContainsSection(key.Value) == false)
saved_sections.AddSection(key.Value);
}
}
Is this the way the library was designed? Seems less than ideal, but still works. Thanks for the library made my life a lot easier.
Original author: [email protected] (February 27, 2012 00:41:10)
What steps will reproduce the problem?
What is the expected output? What do you see instead?
Microsoft Windows driver installation .INF files often have duplicate key names in a section. For example:
[Foo_Inst]
CopyFiles=Entry1CopyFiles
CopyFiles=Entry2CopyFiles
What version of the product are you using? On what operating system?
1.7.1 patched with Issue 20 fixes.
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=26
In commit 726b46a made some breaking changes with API that need to be fixed before releasing 2.0.4
IIniDataFormatter
interface and default implementation. That way an IniData file that was read with a configuration can be converted to an string with another configuration, allowing the user to convert an ini file between formats.IniData.Configuration
property and use that configuration by default in IniData.ToString()
to keep the backward compatibility: IniData
read with a configuration is converted to an string with the same configuration using the ToString()
method. Currently ToString()
always uses the DefaultIniDataFormatter
with a default configuration when writing to a string and not the Configuration used to read the ini file!Original author: [email protected] (May 10, 2011 07:41:49)
What steps will reproduce the problem?
What is the expected output? What do you see instead?
Reading the value should read
What version of the product are you using? On what operating system?
Latest trunk, Windows 7, Visual Studio 2010, C# 4
Please provide any additional information below.
Patch attached, it's just a matter of adding a few more characters to the regexp
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=10
Original author: [email protected] (February 20, 2012 17:14:14)
What steps will reproduce the problem?
What is the expected output? What do you see instead?
I expect that the parser can handle white-space in sections since they are fully escaped.
What version of the product are you using? On what operating system?
Latest download.
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=20
Original author: rickyAH (October 10, 2008 08:33:02)
This INI generates a ParsingException when reading the 'key' value
[ExampleSection]
key = value;value
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=2
The particular ini files have certain sections where there are duplicate keys. I understand that is not standard for ini files, but the ones I am working with allow duplicate keys.
Original author: [email protected] (November 03, 2009 15:32:57)
Using the following code to add a new key with comments:
KeyData key = new KeyData("TestKey");
key.Value = "TestValue";
key.Comments.Add("This is a comment");
inidata["TestSection"].SetKeyData(key);
Looking through the inidata-structures show that the key exists and the
value is correctly set, but the comments collection is empty.
Checked the source code and found this for SetKeyData:
public void SetKeyData(KeyData data)
{
if (data != null)
{
if (_keyData.ContainsKey(data.KeyName))
RemoveKey(data.KeyName);
AddKey(data.KeyName, data.Value);
}
}
Compared to SetSectionData:
public void SetSectionData( string sectionName, SectionData data)
{
if ( data != null )
_sectionData[sectionName] = data;
}
SetKeyData only saves the key name and value.
Perhaps store the KeyData-object directly to the collection like is done
with the SectionData or add another method of storing comments to keys?
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=5
Original author: [email protected] (June 28, 2011 10:44:48)
What steps will reproduce the problem?
What is the expected output? What do you see instead?
What version of the product are you using? On what operating system?
v1.7
Please provide any additional information below.
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=11
How can I parse value that is written in the following way:
(I get only SET because the rest of the string is interpreted as a comment)
TurnMachine = "SET;H 500;1"
Original author: [email protected] (December 16, 2011 12:57:27)
What steps will reproduce the problem?
What is the expected output? What do you see instead?
Expected output is the content of the ini-file, instead this happens :
IniParser.ParsingException: Parsing error: Couldn't parse string: [{E3729302-74D1-11D3-B43A-00AA00CAD128}]. Unknown file format. ---> IniParser.ParsingException: Couldn't parse string: [{E3729302-74D1-11D3-B43A-00AA00CAD128}]. Unknown file format.
What version of the product are you using? On what operating system?
Windows 7 / Ini File Parser v 1.7
Please provide any additional information below.
The INI is generated by InstallShield.
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=17
Original author: [email protected] (February 23, 2012 09:37:16)
What steps will reproduce the problem?
What is the expected output? What do you see instead?
Ability to specify more than 1 comment character.
What version of the product are you using? On what operating system?
1.7.1.0
Please provide any additional information below.
This issue is part of a series to provide similar behavior as Win32 API's GetPrivateProfileString function. (See the full list of tasks in first comment of Issue 20)
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=22
I need option that write an ini file like :
[SEC1]
KEY2=VALUE3
while I open a ini file with section name as [Way-Keyword-##9710880] will get this Exception Unknown file format. Couldn't parse the line: '[2Way-Keyword-##13559710880]'.
how can i handle this error?
You talk explicitly about those methods being overridden in child class to implement more advanced algorithms, but non-virtual methods in C# can not be overridden.
Original author: [email protected] (February 23, 2012 09:34:12)
What steps will reproduce the problem?
What is the expected output? What do you see instead?
val1 read as it would have been done if iniData["section1"]["nkey1"] was specified.
What version of the product are you using? On what operating system?
1.7.1.0
Please provide any additional information below.
This should be driven by a mode, and case sensitivity should remain for backwards compatibility.
This issue is part of a series to provide similar behavior as Win32 API's GetPrivateProfileString function. (See the full list of tasks in first comment of Issue 20)
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=21
Original author: [email protected] (September 05, 2011 05:44:40)
Try to ready the next data, for example:
key1=value1
key2=value2
key3=value3
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=14
Create a rakefile using albacore. The automation will allow to
Original author: [email protected] (February 03, 2012 07:00:27)
What steps will reproduce the problem?
What is the expected output? What do you see instead?
The restriction stated is that
"Sections are declared as a unique word enclosed in square brackets. Spaces enclosed into the square bracktes are ignored, but the section must be defined with an unique word( sampleSection )"
It does not say that the section names cannot have spaces in them. You have an assertion
if ( !Assert.StringHasNoBlankSpaces(keyName) )
which is causing problems. The comment in your method xxx says
"A valid section name is a string with NO blank spaces"
So I think that either spaces should be allowed (mixed in with words) the documentation should say unique word (containing no spaces). I know it says unique word, but with no spaces would be clearer.
(I think spaces should be allowed).
What version of the product are you using? On what operating system?
Please provide any additional information below.
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=19
Original author: [email protected] (March 27, 2012 10:47:23)
What steps will reproduce the problem?
Please provide any additional information below.
Fixing in http://www.assembla.com/spaces/ini-parser/tickets/1
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=28
Original author: aion.cat (July 20, 2010 13:38:19)
Greetings. During the tests found that the method .AddKey(name,value) works by adding sections are not as described in the wiki. For example, using the syntax
newData.Sections.AddSection("newSection");
newData["newSection"].AddKey("newKey1", "value1");
I got only
[newSection]
value1 =
Desired result has turned to a division of adding the key and assigning it a value:
newData.Sections.AddSection("newSection");
newData["newSection"].AddKey("newKey1");
newdata["newSection"]["newKey1"] = "value1";
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=7
Original author: rickyAH (November 18, 2009 19:16:36)
Given an IniFile:
[aSection]
aKey = aValue;
The string value for key 'aKey' is stored as 'aValue;' including the ';'
character, instead of 'aValue'
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=6
Hi,
I'm merging 2 files with a common part. Comments are duplicated. I assume it's not easy to remove duplicate.
But how can I remove all comments of an InitData ?
foreach (var section in conf.Sections) {
section.LeadingComments.Clear();
section.TrailingComments.Clear();
}
Config.Merge(conf); // merge with master
This code seems to clear all comments of section but while writing Config to a file I still see comments :-/
According to source code I can't see where arrays are duplicated. Any Idea ?
Original author: [email protected] (February 23, 2012 13:04:28)
What steps will reproduce the problem?
!comment B
[section1]
;comment B
key1 = testvalue
2. Write the ini data
What is the expected output? What do you see instead?
Comment characters '!' and ';' should be preserved., but instead only '#' was used even for 'comment B'
What version of the product are you using? On what operating system?
1.7.1.0
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=25
Original author: [email protected] (September 28, 2012 13:27:06)
One thing I can't see a way to do is to remove all keys in a section without removing the section itself.
I tried the following, using a foreach as recommended, but Visual Studio doesn't seem to like it.
foreach (KeyData key in parsedData.Sections["TABS"]) {
parsedData["TABS"].RemoveKey(key.KeyName);
}
It throws
System.InvalidOperationException was unhandled
Message=Collection was modified; enumeration operation may not execute.
Is there a way to do this already that I'm missing? If not, I'd like to throw this in as a feature request.
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=29
Original author: [email protected] (July 14, 2011 10:09:26)
Sometimes it throws cannt parse the section, because of there is a problem with encoding.
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=12
The NuGet package for ini-parser v2.1.0 is incorrect and nothing gets installed after installing this NuGet package.
version 2.0 of nuget package won't add dll reference and download source files
Original author: [email protected] (September 07, 2010 12:52:35)
What steps will reproduce the problem?
What is the expected output?
For the relaxed override to allow the code to load the sections
What do you see instead?
An exception stating that the first line that it isn't a comment throwing an ParsingException
What version of the product are you using?
1.5.5
On what operating system?
XPSP3 and Win 7
Please provide any additional information below.
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=8
Original author: [email protected] (July 21, 2011 23:58:39)
The MatchKeyValuePair() looks like this:
private bool MatchKeyValuePair(string s)
{
if (string.IsNullOrEmpty(s))
return false;
return s.Contains("=");
return _keyValuePairRegex.Match(s).Success;
}
Before 1.7, the second return statement was used. Since 1.7, a simpler check is used (the first return). In any case, one or the other should be removed.
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=13
Original author: [email protected] (February 23, 2012 10:06:02)
What steps will reproduce the problem?
What is the expected output? What do you see instead?
the line 'win]' is ignored and any parameters below are treated as part if the previous seciton. This is the same behaviour as GetPrivateProfileString(..) in the Win32 API
What version of the product are you using? On what operating system?
1.7.1.0
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=24
Original author: [email protected] (February 23, 2012 09:43:22)
What steps will reproduce the problem?
What is the expected output? What do you see instead?
The same ini configuration written as it was read
What version of the product are you using? On what operating system?
1.7.1.0
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=23
Original author: [email protected] (September 25, 2011 12:54:31)
What steps will reproduce the problem?
What is the expected output? What do you see instead?
The program just crash because can't handle 2 sections with the same name.
What version of the product are you using? On what operating system?
1.7 on windows 7
Please provide any additional information below.
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=15
Original author: [email protected] (December 27, 2011 14:14:22)
What steps will reproduce the problem?
What is the expected output? What do you see instead?
If I have an ini file showing an ä in the editor I expect to read än ä with the library too.
eg. "Identität" changes to "Identit�t"
What version of the product are you using? On what operating system?
1.7.1.0
Please provide any additional information below.
Sample ini file content:
[Test]
English=Identity
German=Identität
French=Identité
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=18
Original author: [email protected] (December 07, 2011 08:10:26)
What steps will reproduce the problem?
If the ini file includes sections or keys written with Chinese characters, it cannot parse the file.
What is the expected output? What do you see instead?
Add international support please.
What version of the product are you using? On what operating system?
ver 1.7, on windows 7
Please provide any additional information below.
Please reach me if you interested.
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=16
Original author: [email protected] (December 27, 2010 18:00:34)
What steps will reproduce the problem?
What is the expected output?
iniData["connectionString"] should yield the string "Server=sqlserver.domain.com;Database=main;User ID=user;Password=password".
What do you see instead?
Only the first part of the value, up until the first semicolon, ("Server=sqlserver.domain.com") is returned because it treats each semicolon in the line as the start of a comment.
What version of the product are you using? On what operating system?
INIFileParser.dll version 1.5.5.0
Visual Studio 2010
Windows 7
Please provide any additional information below.
The INI file article on Wikipedia (http://en.wikipedia.org/wiki/Ini_file) gives some possible solutions, including support for quoted values (surrounding them with double quotes) and escape values. (use ';' for a semicolon in a value) Any of the solutions there would be acceptable, as long as it allowed SQL connection strings to be loaded and saved correctly.
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=9
Add method to delete all comments from a inidata, a section or keyvalue structures.
Original author: [email protected] (October 05, 2008 13:59:13)
This Code creates a ParsingError
IniParser.FileIniDataParser parser = new IniParser.FileIniDataParser();
parser.LoadFile(file.FullName);
with a ini like this:
[.ShellClassInfo]
IconFile=icon.ico
IconIndex=0
IconResource=icon.ico,0
It would be great if this could be fixed
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=1
Original author: [email protected] (March 16, 2012 23:19:00)
What steps will reproduce the problem?
Loading a following ini file:
[Sessions\[email protected]]
HostName=ftp.scene.org
PortNumber=21
UserName=anonymous
FSProtocol=5
What is the expected output? What do you see instead?
IniParser.ParsingException was unhandled
Message=Parsing error: Couldn't parse string: [Sessions\anonymous@ftp.scene.org]. Unknown file format.
Source=INIFileParser
StackTrace:
at IniParser.StreamIniDataParser.ReadData(StreamReader reader, Boolean relaxedIniFormat)
at IniParser.FileIniDataParser.LoadFile(String fileName, Boolean relaxedIniRead)
at Uploader.Uploader.Main(String[] args) in D:\Programming\uploader2\uploader2\Uploader.cs:line 39
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: IniParser.ParsingException
Message=Couldn't parse string: [Sessions\anonymous@ftp.scene.org]. Unknown file format.
Source=INIFileParser
StackTrace:
at IniParser.StreamIniDataParser.ProcessLine(String currentLine)
at IniParser.StreamIniDataParser.ReadData(StreamReader reader, Boolean relaxedIniFormat)
InnerException:
What version of the product are you using? On what operating system?
1.7.1.0
Please provide any additional information below.
Does not work even with relaxed mode
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=27
I've come across an INI with C++ style single-line comments, like this:
// This is a comment
Yes it appears ini-parser doesn't have a simple way of dealing with this.
If CommentChar
was CommentString
(or even CommentStrings
) this would be trivial. I imagine implementation would look something like:
config.CommentStrings = new string[] {"//", "#"};
Original author: rickyAH (October 31, 2008 20:24:11)
pigrew :
I think that this is related to a bug that I just ran into:
key.contains.periods = value
It fails because the keys and values can only contain alphanumeric
character (plus _).
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=3
Original author: rickyAH (September 21, 2009 09:31:41)
It would be desireable to allow loading partially invalid INI files:
Ini files with duplicated sections
Sections with duplicated keys
The files could be loaded just discarding the repeated elements
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=4
while I open a ini file with section name as [Way-Keyword-##9710880] will get this Exception Unknown file format. Couldn't parse the line: '[Way-Keyword-##59710880]'.
how can i handle this error?
The IniData class does not need a IIniParserConfiguration
reference. Separating the code that holds the INI data from the code that formats that ini data to a string will reduce the coupling.
Right now comments in the same line like this:
key1 = value ; this is an important configuration setting
are not parsed as comment, but as part of the value (i.e. the value for key key1
is value ; this is an important configuration setting
)
The library also need some way to preserve those kind of "same line comments" so they are persisted correctly if we convert the IniData back to a string
Original author: [email protected] (October 03, 2012 18:16:56)
What steps will reproduce the problem?
Create a test INI file with the following content:
[section]
key=value1;value2
What is the expected output? What do you see instead?
Was expecting data["section"]["key"] to be "value1;value2"
instead ";value2" is parsed as a comment.
What version of the product are you using? On what operating system?
Please provide any additional information below.
I was able to modify "StreamIniDataParser.cs", line 162:
FROM:
_commentRegex = new Regex(value + strCommentRegex);
TO:
_commentRegex = new Regex("^" + value + strCommentRegex);
to make sure the a only comment delimiter appearing in front of a line is matched as a comment delimiter.
Original issue: http://code.google.com/p/ini-parser/issues/detail?id=30
Try to build the NuGet package using albacore or other automated system, as it is usually time-consume and error prone.
Work Branch: https://github.com/rickyah/ini-parser/tree/feature/albacore_nuget_package_generation
Things to automate:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.