Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

40 lines
862 B

  1. #include "fmt.h"
  2. size_t fmt_escapecharxml(char* dest,uint32_t ch) {
  3. char a[FMT_LONG], b[FMT_XLONG];
  4. const char* s;
  5. size_t i,j;
  6. switch (ch) {
  7. case '&': s="&"; goto string;
  8. case '<': s="&lt;"; goto string;
  9. case '>': s="&gt;"; goto string;
  10. case '\'': s="&apos;"; goto string;
  11. case '"': s="&quot;"; goto string;
  12. default:
  13. a[i=fmt_ulong(a,ch)]=0;
  14. b[0]='x';
  15. b[j=fmt_xlong(b+1,ch)+1]=0;
  16. s=a;
  17. if (i>j) { s=b; i=j; }
  18. if (dest) {
  19. dest[0]='&';
  20. dest[1]='#';
  21. byte_copy(dest+2,i,s);
  22. dest[i+2]=';';
  23. }
  24. return i+3;
  25. }
  26. string:
  27. return fmt_str(dest,s);
  28. }
  29. #ifdef __GNUC__
  30. #ifdef __APPLE__
  31. size_t fmt_escapecharhtml(char* dest,uint32_t ch) {
  32. return fmt_escapecharxml(dest,ch);
  33. }
  34. #else
  35. size_t fmt_escapecharhtml(char* dest,uint32_t ch) __attribute__((__alias__("fmt_escapecharxml")));
  36. #endif
  37. #endif