[gdal-dev] OGRStyleTool::GetStyleString() loosing quotes after modification
Even Rouault
even.rouault at spatialys.com
Sat Sep 6 05:36:12 PDT 2014
Le jeudi 04 septembre 2014 22:07:46, Andre Vautour a écrit :
> I ran into a problem where a quoted text string in a OGR Style String
> gets lost while interacting with it via an OGRStyleTool. Using the same
> style string afterwords causes OGRStyleTool::Parse() to fail because the
> quote string contained parentheses which would have typically been
> ignored because of the CSLT_HONOURSTRINGS and CSLT_PRESERVEQUOTES flags
> that are passed to CSLTokenizeString2.
>
> Here is a code snippet that exposes the issue that I am seeing:
>
> void testGetStyleString()
> {
> const char* const originalStyleString = "LABEL(t:\"MyText(1)\")";
> std::cout << "originalStyleString:" << originalStyleString <<
> std::endl;
>
> ::OGRStyleLabel styleLabel;
>
> styleLabel.SetStyleString(originalStyleString);
>
> const char* const styleStringAfterBeingSet =
> styleLabel.GetStyleString();
> std::cout << "styleStringAfterBeingSet:" <<
> styleStringAfterBeingSet << std::endl;
>
> GBool defaultValue = false;
> const char* const textString =
> styleLabel.TextString(defaultValue); std::cout << "textString:" <<
> textString << std::endl;
>
> const char* const styleStringAfterParsingStage =
> styleLabel.GetStyleString();
> std::cout << "styleStringAfterParsingStage:" <<
> styleStringAfterParsingStage << std::endl;
>
> return;
> }
>
> Which produces the following output:
>
> originalStyleString:LABEL(t:"MyText(1)")
> styleStringAfterBeingSet:LABEL(t:"MyText(1)")
> textString:MyText(1)
> styleStringAfterParsingStage:LABEL(t:MyText(1))
>
> So, the main problem I have encountered, as far as I can tell is that
> GetStyleString() does not honor the quotes after it has been set to have
> been parse and set as modified (StyleModified). I my case, I didn't even
> modify the tool, OGRStyleTool::Parse() seems to be the one who set the
> style tool as being modified. The modified flag is why GetStyleString()
> regenerates the string from the parameters. So, I have two questions:
>
> 1. Should Parse() set the style tool as modified as it currently does?
No, the m_bModified flag should be reset to FALSE at the end of Parse().
> 2. Should the parsing of the parameters retain the quotes? It currently
> doesn't specify CSLT_PRESERVEQUOTES when splitting t:"MyText" at the colon.
I see returning unquoted text as a desired behaviour, since quoting is a
serialization trick. But OGRStyleTool::GetStyleString() should add double-
quoting when building the feature style string.
I can also see that escaping of double-quote characters with \ will probably
not be correctly handled in de-serialization and serialization.
>
> Doing #2 would obviously mean the TextString() would return the quoted
> string which it doesn't do currently.
>
> Any thoughts?
> André
--
Spatialys - Geospatial professional services
http://www.spatialys.com
More information about the gdal-dev
mailing list