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

easier text printing #25

Open
chriscamacho opened this issue Feb 13, 2020 · 2 comments
Open

easier text printing #25

chriscamacho opened this issue Feb 13, 2020 · 2 comments

Comments

@chriscamacho
Copy link

by accessing the string structs (defining the whole struct in end user code)

struct xml_string {
	uint8_t const* buffer;
	size_t length;
};

the end user can then print a string like so....

struct xml_string* anc = xml_node_attribute_content(tchild, k);
printf("%*.*s ", 0, (int)anc->length, (char*)anc->buffer);

I think this would make the examples easier to follow...

@ooxi
Copy link
Owner

ooxi commented Feb 20, 2020

Thanks for the input. In order to increase ABI stability, the definition of struct xml_string is not exposed.

Nevertheless a utility method returning the a content's of a node as zero terminated char* copy (to be freed by the caller) might be useful, since it's quite rare to have 0 inside XML content.

Patches welcome.

@chriscamacho
Copy link
Author

chriscamacho commented Feb 20, 2020

as well as that something like the following would be useful too...

static inline float xmlStrToFloat(struct xml_string* str) 
{
    uint8_t* str_0 = RL_CALLOC(xml_string_length(str) + 1, sizeof(uint8_t));
    xml_string_copy(str, str_0, xml_string_length(str));
    float f = strtof((char*)str_0, NULL);
        RL_FREE(str_0);
    return f;
}

...

static inline bool xmlStrEqu(const char* cmpstr, struct xml_string* str)
{
    if (strncmp(cmpstr, (char*)str->buffer, str->length )==0) {
	    return true;
    } else {
	    return false;
    }
}

I find comparing attribute and node names very useful when parsing the xml when loading a "level"
xmlstr to float (which can be cast to int if needed...) is also useful for attribute contents...

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

No branches or pull requests

2 participants