-
Notifications
You must be signed in to change notification settings - Fork 6
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
Support quoted relations in collection #633
Conversation
src/dlite-type.c
Outdated
if (!(t = jsmn_element(src, tokens, 0))) return -1; | ||
rel->s = strndup(src + t->start, t->end - t->start); | ||
if (strnput_unquote(&buf, &bufsize, 0, src + t->start, |
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.
seems to be a lot of hard-to-read copy-pasted code here. Please create a function, or even a macro to simplify the reading.
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.
Good point. Done
while (s[j] && (n < 0 || (int)j < n)) { | ||
if (s[j] == '"' && !(flags & strquoteNoEscape)) { | ||
if (size > i) dest[i] = '\\'; | ||
if (s) { |
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.
hard to follow the logic. Comment line-by-line what is happening here, or simplify the expression with standard functions.
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.
Added some comments to make it easier to follow.
|
||
On allocation error, -3 is returned. | ||
*/ | ||
int strnput_unquote(char **destp, size_t *sizep, size_t pos, const char *s, |
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.
Hard to follow logic. Please document what is the execution logic, or use a standard function to simplify the expression
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.
Good suggestion. When adding explanations it became clear that the code both could be simplified and made more efficient by removing an unnecessary call to realloc().
# Description Example with OTEAPI and OTELib using TEM data. This example currently depends on a set of other PRs: * #633 (already merged into this branch) * EMMC-ASBL/oteapi-core#318 * EMMC-ASBL/tripper#129 * EMMC-ASBL/oteapi-dlite#163 ## Type of change - [ ] Bug fix & code cleanup - [ ] New feature - [x] Documentation update - [ ] Test update ## Checklist for the reviewer This checklist should be used as a help for the reviewer. - [ ] Is the change limited to one issue? - [ ] Does this PR close the issue? - [ ] Is the code easy to read and understand? - [ ] Do all new feature have an accompanying new test? - [ ] Has the documentation been updated as necessary?
Description
We use the collection as a local knowledge base. Since n3-represented literals contains embedded double-quotes it is essential that serialisation and de-serialisation of collections retain embedded double-quotes.
This PR ensures that embedded double-quotes are escaped in the internal representation of relations, which is used by the built-in json encoder/decoder.
Type of change
Checklist for the reviewer
This checklist should be used as a help for the reviewer.