Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a quoted string in values #4

Closed
lmattcris opened this issue Jun 15, 2022 · 5 comments
Closed

Using a quoted string in values #4

lmattcris opened this issue Jun 15, 2022 · 5 comments

Comments

@lmattcris
Copy link

I see that with a key's value as in

[Section]
Key="My value"

the GetSetting property obtains a string like
"\"My value\""
not interpreting the quotes as... quotes 😄

I also see that quotes aren't necessary for embedded spaces, but is there any option to force using quotes in strings when there are blanks? Hence, automatically removing the quotes

@SoftCircuits
Copy link
Owner

SoftCircuits commented Jun 15, 2022

There is no option for this. I have never seen quotes be part of the INI file standard. Unlike with CSV files, I don't see why they would be necessary. Who is writing INI files that way?

If you can show me where this is standard, I'll consider adding support for it.

Meanwhile, you can remove those quotes using value = value.Trim('"').

@lmattcris
Copy link
Author

Well, the INI files format is indeed a loose one. I've been using for a long time the GetPrivateProfileString API call, from Win32, and I had to replicate it in different environments. It uses both single and double quotes escaping in values.
https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getprivateprofilestringw
It's also mentioned on Wikipedia as well (as shown in an example too)
https://en.wikipedia.org/wiki/INI_file#Comparison_of_INI_parsers

I think that sometimes it can be a help in reading complex assignments, like
MyHideouslyLongNameKey = "= This is going to be cleaner than without blanks around ="

Just a welcome feature, not an issue - sorry if I used the "issue" space on GitHub! 😺

@SoftCircuits
Copy link
Owner

So, your first link talks about supporting quotes around the key.

[Section]
"Key"=My Value

This would actually be necessary if you needed an equal sign in the key. I might consider this. But it's different from what you need.

I couldn't find where the Wikipedia article talked about quoted values.

@lmattcris
Copy link
Author

lmattcris commented Jun 15, 2022

Oh, I think their text is a bit convoluted, but when they write

If the string associated with lpKeyName is enclosed in single or double quotation marks, the marks are discarded when the GetPrivateProfileString function retrieves the string

it refers to the value string to be assigned... I hope - you retrieve the value string, reasonably
I've never seen key names with spaces in between, while I've seen quite often values quoted, as in the Wikipedia example at the link above:

[database]
; use IP address in case network name resolution is not working
server = 192.0.2.62     
port = 143
file = "payroll.dat"

And in text

Quoted values
Some implementations allow values to be quoted, typically using double quotes and/or apostrophes. This allows for explicit declaration of whitespace, and/or for quoting of special characters (equals, semicolon, etc.). The standard Windows function GetPrivateProfileString supports this, and will remove quotation marks that surround the values.

@SoftCircuits
Copy link
Owner

I'm closing this issue for now. I don't see anyone else needing this and removing quotes now could potentially break existing code that expects quotes to be left in.

Feel free to reach out if you can think of any other arguments for making a change here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants