Parsing some simple markup and displaaying it

Started by
1 comment, last by Fire Lancer 14 years, 10 months ago
I was wondering what would be the best way to quickly parse a string to pull out formatting data, and then be able to format it quickly later with some sort of error handeling (eg if the format string expects a .name atribute and the object passed doesnt have that attribute). The format of the script does not have to be as describe here, just able to achive the same effect. Eg I have that following string:

Your ship <col=yellow><var>this.name</var></col> was destroyed by <col=yellow><var>killer.name</var></col> in sector <col=yellow></var>this.sector.name</var></col>.



Then when a ship killed I need to pass the info to the renderer (ie the two ship objects involed) so that it can render some text from the above format string on the screen (wrapping to multiple lines correctly if it wont fit within the avaible width). The ship objects have methods like string GetName() and Sector GetSector() (and a GetName for the sector object too) for accessing the info about them. I'm using d3d9 and d3d10 with c++ and am currently using the D3DX Font interfaces for text rendering. Previously I was hardcoding such format stuff but then regretted it when trying to implement the large number of diffrently formatted strings for log entries and mission breifings and stuff like that. [Edited by - Fire Lancer on June 7, 2009 1:45:11 PM]
Advertisement
I have no idea what programming language you're working in, but I'm going to guess C++. Have you looked into Boost.Spirit? It's a pretty powerful, yet relatively simple tool.
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
Ok, so that can parse the string (when I work out how...I guess some sort of object model), how am I meant to store the format data, fill out the <var> sections with the argument data and then render it?

This topic is closed to new replies.

Advertisement