Skip to content

util/xmlfile.h: API update #14032

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ajrhacker
Copy link
Contributor

  • Convert most const char * parameters to std::string_view, cleaning up associated use of null pointers
  • Rename get_name and get_value methods to name and value and make them return references to std::string

- Convert most const char * parameters to std::string_view, cleaning up associated use of null pointers
- Rename get_name and get_value methods to name and value and make them return references to std::string
Comment on lines -140 to +141
// return the string value of an attribute, or the specified default if not present
const char *get_attribute_string(const char *attribute, const char *defvalue) const;
// return the string value of an attribute, or the specified default or empty string if not present
std::string_view get_attribute_string(std::string_view attribute, std::string_view defvalue = std::string_view()) const;
Copy link
Member

Choose a reason for hiding this comment

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

I really dislike treating not present as an empty string by default. It goes against the “XML way”. Maybe you could make it return a std::optional<std::string_view> instead? Then the default value could be std::nullopt.

Comment on lines -83 to +85
char const *get_value() const { return m_value.empty() ? nullptr : m_value.c_str(); }
void set_value(char const *value);
void append_value(char const *value, int length);
const std::string &value() const { return m_value; }
void set_value(std::string_view value) { m_value.assign(value); }
void append_value(std::string_view value) { m_value.append(value); }
Copy link
Member

Choose a reason for hiding this comment

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

Exposing that the value is a std::string in the getter feels like a bit of a leaky abstraction. I know you’re doing it (rather than returning std::string_view) for convenience because various things want to use the “value” for things that want a NUL-terminated string, and you can use .c_str() this way, but it feels dirtier before because it changes it from “value is internally stored as something that can be exposed as a NUL-terminated stringto “value is internally stored as astd::string`”.

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