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

Add node style setter #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions include/libfyaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -2784,6 +2784,20 @@ enum fy_node_style
fy_node_get_style(struct fy_node *fyn)
FY_EXPORT;

/**
* fy_node_set_style() - Set the node style
*
* Set the node rendering style.
* If current node style is alias it won't be changed
* to save document structure
*
* @fyn: The node
* @style: The node style
*/
void
fy_node_set_style(struct fy_node *fyn, enum fy_node_style style)
FY_EXPORT;

/**
* fy_node_is_scalar() - Check whether the node is a scalar
*
Expand Down
12 changes: 12 additions & 0 deletions src/lib/fy-doc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3343,6 +3343,18 @@ enum fy_node_style fy_node_get_style(struct fy_node *fyn)
return fyn ? fyn->style : FYNS_PLAIN;
}

void fy_node_set_style(struct fy_node *fyn, enum fy_node_style style)
{
if (!fyn)
return;

/* ignore alias nodes to save document structure */
if (fyn->style == FYNS_ALIAS)
return;

fyn->style = style;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish it was so simple.

The problem is that for scalars it is quite possible to set a style that is illegal.

For instance change a double quoted scalar node's style to plain is illegal if the scalar has \0 for example.

So for the setter to work it must run a check of what are the permissible styles, and allow the setting if permitted.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to make at least unchecked dangrous version like fy_node_set_style_unchecked, because currently we don't have public interface to change style at all. It is a problem for outputting some nodes in somehow beautified way

}

bool fy_node_is_null(struct fy_node *fyn)
{
if (!fyn)
Expand Down