
On 20-2-2014 23:55, Martin Owens wrote:
On Thu, 2014-02-20 at 23:34 +0100, Johan Engelen wrote:
I don't fully understand your question, but eventually, pretty much everything of Inkscape should use std::string. So it's good not to add any C-string stuff, to make the refactoring easier.
I agree. Although it's good to make sure that these things are being done right.
I've put everything in a new branch and I'm going to be asking for a full review when it's ready. Might take a while to get image.cpp done though.
use char*, if that is how the uri was stored in the first place. So you'd have to look at who will call parseDataUri and if they have the uri in a std::string or char*
parseDataUri is a private function for uri.cpp to store data from a data uri instead of passing the uri to libxml's uri handling which doesn't handle data uris.
So in the case of normal urls, the data gets copied by libxml. In the case of data uris, the fewer copies the better. So, instead of using cstring, how to say:
const char *preformed = "data:..........."
if preformed[:5] == "data:": // this is a data uri and we're going to parse it
Like this daft conditional:?
if(p[0]=='d' && p[1] =='a' && p[2] == 't' && p[3] =='a' && p[4]==':'){ ... }
I was also going to store the const char offsets to the data and only feed back the conversion from base64 when needed as part of a stream pattern which would feed gdk image creation.
- Is this safe, the char is owned by the same object that creates the
URI object. Technically they should both be still in use? 2. Would this work?
It's ok to use <cstring.h> if needed, it's just that it puts up a red flag for me is all. So you probably indeed will need strcmp or a sibling, that's fine I think. When you work with C-strings, you have to realize that you are working with raw data, and pointers to raw data. So memleaks and exception-safety issues become easy traps to fall in to. And so you have to make sure that somewhere, someone calls free/delete on your data. You simply have to be way more careful when programming with C-strings, and so it's best to keep the code confined and internal to your class.
-Johan