How to decode HTML Entities in C?

后端 未结 5 1445
广开言路
广开言路 2020-11-30 11:29

I\'m interested in unescaping text for example: \ maps to \\ in C. Does anyone know of a good library?

As reference the Wikipedia

5条回答
  •  难免孤独
    2020-11-30 11:51

    I had some free time today and wrote a decoder from scratch: entities.c, entities.h.

    The only function with external linkage is

    size_t decode_html_entities_utf8(char *dest, const char *src);
    

    If src is a null pointer, the string will be taken from dest, ie the entities will be decoded in-place. Otherwise, the decoded string will be put in dest - which should point to a buffer big enough to hold strlen(src) + 1 characters - and src will be unchanged.

    The function will return the length of the decoded string.

    Please note that I haven't done any extensive testing, so there's a high probability of bugs...

提交回复
热议问题