Proper whitespace formatting in mini_xml_karma.cpp example code
Seth <[email protected]> Mon, 23 Apr 2018 21:59:18 +0200
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <[email protected]> |
Do you want pretty printing? Or do you want whitespace preservation, as you seemingly say. Regardless of the choice there, stateful pretty printing in karma isn't my favorite pastime. I always find that writing a visitor myself is less work. There's an old thread here: http://boost.2283326.n4.nabble.com/Indentation-on-Karma-td2677502.html that discusses a mechanism for inclusion in the library. Related sample directives are here: https://stackoverflow.com/questions/18085020/boostspiritkarma-how-to-get-current-position-of-output (the answers are by llonesmiz from this list, usually recommendable). I thought I'd have tackled this problem on SO myself once or twicewith varying degrees of success. See e.g. this answer: https://stackoverflow.com/a/46854802/85371 which is a followup to my earlier answer that didn't use Karma. The topic is similar, but about pretty-printing Json instead. In that answer I show how to do "the same" but without karma, and you can see the difference. As I remember the end-result wasn't as bad as I anticipated, so you might find it perfectly viable :) I just glanced it over and I think it didn't go all the way and left proper indenting as an "exercise for the reader". Hope the info helps you, Seth On 17-04-18 08:52, Maarten Verhage wrote: > Dear people, > > I'm using some CAD software tool that produces output that looks a bit like > xml. Certain values that are produced in these files are undesired in my > perspective. So I wish to change them automatically. Therefore I was > thinking that the mini_xml_karma example code of Spirit 2.5.3 is a good > starting point to write such an utility program. Correct? > > I've done some stuff with Spirit in the past but you still should consider > me a novice on this topic. > > Regarding the mini_xml_karma example code I managed to write the result to a > file. However the whitespace is removed from it, as was the case with the > original output to std::cout. > > My next objective is to generate proper whitespace. I've no need the > preserve the original line numbers so I can define my own formatting style > for this. I think something like the formatting of the "3.toyxml" file would > be fine. So, top hierarchy start tags should have a line feed directly after > it. Any line that follows should have indentation of some spaces until the > end tag. Subsequent start/end tags should be on the same line. > > Do you know of some example code that shows behavior like this? Or which > Spirit and/or Karma facilities should I be using to implement this? > > Thank you very much for your attention and time! > > Best regards, > Maarten Verhage > > > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Spirit-general mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/spirit-general ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Spirit-general mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/spirit-general