-
-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Utf-8 check, C++ initial version #463
Utf-8 check, C++ initial version #463
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of things. Looks good overall. The bit shifting is well documented, which I appreciate.
FWIW, I think savegame.cpp/.h is a perfectly fine place to put this functionality.
Thanks for the PR, @P-D-E !
@@ -174,6 +180,99 @@ void SaveFileCopy( const char *src, const char *dst ) | |||
} | |||
} | |||
|
|||
class Utf8Checker { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit late to the party, but I wonder if you could have used some boost facility instead.
Something like https://www.boost.org/doc/libs/1_48_0/libs/locale/doc/html/charset_handling.html. It's possible to ask it to throw an exception. Other than that, LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this code a lot. I'm ready to give it my approval. What do you guys say?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally this looks good; one minor change to move to the smart pointer object and we should be good to go
engine/src/savegame.cpp
Outdated
{ | ||
std::string path = GetSaveDir() + filename; | ||
std::vector<BYTE> savegame = readFile(path); | ||
std::unique_ptr<Utf8Checker> check(new Utf8Checker); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: does this need to be a pointer to an instance? Or can it just be a local instance?
Utf8Checker check;
...
if (check.validUtf8(...
If we don't need to allocate, then let's not. If there's a reason we need to, then okay; but I think we may not need to - stack allocation should be sufficient.
NOTE: This wasn't quite clear before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it can, @vegastrike/code-developers do you all agree on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could just be a local instance instead of a pointer, but personally, I don't think that it matters much one way or the other.
I say let's merge this PR as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the Utf8Checker class instance is only ever used/accessed inside the scope of the isUtf8SaveGame function, then it makes sense to just use it directly as a local instance since it doesn't need to be passed around to other consumers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we could save some time by leaving the code the way it is here, but I see that that is not the way this is going. So sure, let's change it to use the UTF8Checker directly, as a local instance.
please port this over to the 0.8.x branch. |
@BenjamenMeyer: Who is supposed to do this? |
@ermo ideally the same person that did the PR; but anyone can do it:
Or something like that...some adjustments might need to be made, but that's the general process |
@P-D-E: Would you mind taking a look at porting it to the 0.8.x branch since you're familiar with the code? 🥳 |
@ermo Benjamen and I talked about it and agreed that he'll take care of it 👍 |
Thank you for submitting a pull request and becoming a contributor to the Vega Strike Core Engine.
Please answer the following:
Code Changes:
Issues:
Purpose: