Skip to content
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

Merged
merged 6 commits into from
Sep 21, 2023
Merged

Conversation

jesper-friis
Copy link
Collaborator

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

  • Bug fix & code cleanup
  • New feature
  • 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?

@jesper-friis jesper-friis mentioned this pull request Sep 1, 2023
9 tasks
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,
Copy link
Collaborator

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.

Copy link
Collaborator Author

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) {
Copy link
Collaborator

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.

Copy link
Collaborator Author

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,
Copy link
Collaborator

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

Copy link
Collaborator Author

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().

@jesper-friis jesper-friis merged commit e9c31ac into master Sep 21, 2023
11 checks passed
@jesper-friis jesper-friis deleted the quoted-relations branch September 21, 2023 22:24
jesper-friis added a commit that referenced this pull request Sep 29, 2023
# 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?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants