SharpConfig icon indicating copy to clipboard operation
SharpConfig copied to clipboard

Parsing of (previously saved) multi-line strings

Open CSLVRlab-PW opened this issue 2 years ago • 4 comments

Hi,

thanks for your very helpful piece of software. I run into an issue with saving and parsing of multi-line strings or text.

SharpConfig is part of an Unity3D project. The code checks if a configuration file exists. If not it is created based on the default settings in the code. A text field from an UI element is saved correctly and looks like the following in the config file. The line-breaks are correctly placed and everything seams fine.

IntroText="Line 1 Line 2

Line 4 Line 5"

But parsing of this config file entry fails on the first line-break within the multi-line string. I get the following error:

ParserException: Line 2: setting assignment expected.

ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

If I remove the line-breaks form the previously saved configuration file, the parsing does work again. Apparently the parser looks for the next config file entry on the next line and ignores the quotations marks.

Is there a trick how to work with "text" or strings with line breaks? I already tried "RawValue" but it is the same issue.

Or maybe I do something wrong? Here is a short code snippet of the saving and loading of the text. cfg["UI"]["IntroText"].StringValue = introText.GetComponent<TMPro.TextMeshProUGUI>().text; introText.GetComponent<TMPro.TextMeshProUGUI>().text = cfg["UI"]["IntroText"].StringValue;

For the meantime I can use Richtext tags to have my line breaks. Still it seams odd to me, that SharpConfig creates a config file that it cannot parse afterwards.

Many thanks! Peter

CSLVRlab-PW avatar Sep 24 '21 08:09 CSLVRlab-PW

Hi @CSLVRlab-PW / Peter,

this is unfortunately a feature that's missing in SharpConfig. It can be fixed by improving the parser to correctly read quoted strings across multiple lines. The parser will soon be reimplemented entirely anyway, so that this too is possible. My question: Do you have to have the config file in text form? If not, you may load/save it in binary form by using the appropriate overloads. This will fix your problem for now.

Cheers!

cemdervis avatar Sep 24 '21 08:09 cemdervis

Thanks. That was an fast answer! I was just wondering if I am doing something wrong :)

Yes. I want to use the config file to tweak the applications setup. I will have a look on the Parser but probably I will simply store the various intro texts in separate files and then use the config file to reference them.

Thanks again!

CSLVRlab-PW avatar Sep 24 '21 08:09 CSLVRlab-PW

You're welcome. Referencing the text sounds like a good idea. By the looks of it, your config files might become too cluttered anyway once you include more text in them. Regardless, I'll reopen this issue just to have it on a TODO list for the next patch.

Cheers!

cemdervis avatar Sep 24 '21 09:09 cemdervis

Alright. Sorry I closed it already.

Yes it might be cluttered. But this is an app for scientific purposes only. Thus it does not matter that much.

CSLVRlab-PW avatar Sep 24 '21 09:09 CSLVRlab-PW