Converting URIs to file paths

I’m wondering if there’s a C/C++ library or example source that demonstrates how to correctly convert a uri to a file path. This is necessary for loading texture images in Collada, since the <image>/<init_from> element is a uri.

I’ve put in some hacks that allow me to properly handle all the uris I’ve come across, including things like “file:///C:/Program%20Files/3dsmax7/maps/FIR2.TGA”, which is exported from Max. I’m sure there are many cases my simple code isn’t handling though, so I’m looking for a better solution.

Does the Collada DOM provide any help with this perhaps?

See this link for information on URI processing…

Yes the COLLADA DOM has functions to resolve URI for you.

There’s a lot of information in that document and I was wondering if someone had already tackled the problem of converting a file-scheme uri to a file path for use with a function like fopen.

I know the Collada DOM has code to resolve an uri to another Collada element, but I’m not sure if there’s code to help me convert “file:///C:/my%20Folder/image.tga” to “C:/myFolder/image.tga”. Really I’m only worried about the encoded space there. Everything else I should be able to do with the daeUri class.

Actually now that I look at it, 20 is just the hexadecimal value of a space in ASCII. If the rule is just “for every %, take the next two characters and treat them as the hexadecimal code of an ASCII value”, then it’ll be easy to implement that myself. I wonder if the DOM does this when resolving uris.

The DOM does handle %20 space encoding for you. Until recently it would only encode on save but we have changed that so it will do it on load as well.
In the COLLADA document there will be “%20” but the in the DOM memory they will have all become " ".

As for the file system path… thats still left up to the client. But it would be a very useful contribution if someone were to add functionality to the daeURI class.


More proof that I really need to update to the latest version of the DOM. I’ll do that today. Thanks.