-
Notifications
You must be signed in to change notification settings - Fork 5
Function to encode strings #3
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
base: master
Are you sure you want to change the base?
Conversation
|
Thanks for your contribution @miguelleitao! I'm very interested in adding this functionality, since we do not have an encoding functionality yet. Please see my inline comments on your merge requests for details (will follow in a couple of minutes :-) |
ooxi
left a comment
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.
Needs some work, but looks promising! Please also add a test case for this functionality.
entities.c
Outdated
| return (size_t)(to - dest); | ||
| } | ||
|
|
||
| int encode_html_entities(char *dest, const char *src) { |
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.
Please return sitze_t instead of int
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.
Completely agree. I'll commit the correction.
entities.c
Outdated
| int encode_html_entities(char *dest, const char *src) { | ||
| char *to = dest; | ||
| for( const char *from = src ; *from ; from++ ) { | ||
| int i = 9999; |
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.
Please declare i as late as possible and do not assign a magic unused value to it
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.
Completely agree. I'll commit the correction.
entities.c
Outdated
| } | ||
| //if ( *from=='\r' || *from=='\n' ) continue; | ||
| for( i=0 ; i<sizeof NAMED_ENTITIES / sizeof *NAMED_ENTITIES ; i++ ) | ||
| if ( *from == NAMED_ENTITIES[i][1][0] ) break; |
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 don't really get this logic :-) are you comparing just the first character or am I missing something? Or is this sufficient because of the available entities (then please make sure this remains the case by adding an appropriate test case)
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, I'm just comparing the first character. I found this sufficient for the final application I was developing. Maybe this encoder should be classified as an ASCII encoder instead of an UTF-8 encoder. I'll think about this during next week. Enlarging the length of the test can be done but this solution will still be inefficient since it uses a top-down search on an unsorted table.
If I won't improve the test, I'll try to keep the restriction clear to future users or developers.
Any way, I'll provide a test case.
entities.c
Outdated
| } | ||
| } | ||
| *to = 0; | ||
| return strlen(dest); |
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.
Since you know dest and to, no call to strlen is necessary
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.
Completely agree. I'll commit the correction.
|
Hi ooxi. Thank you for your reviews. I just pushed a new version of the encoding function.
|
|
Thanks for splitting your changes into topic commits, of which I already have merged several into master! The rest can be found in the feature/encode branch and will be merged as soon as I have had a chance to look at it :-) |
Was this ever merged? 😅 |
|
@gjtorikian unfortunately, no. But feel free to use it as is :-) |
Added a function to encode strings.