| 4048 | */ |
| 4049 | |
| 4050 | static void |
| 4051 | print_xml_string(cups_file_t *outfile, /* I - Test data */ |
| 4052 | const char *element, /* I - Element name or NULL */ |
| 4053 | const char *s) /* I - String to print */ |
| 4054 | { |
| 4055 | if (element) |
| 4056 | cupsFilePrintf(outfile, "<%s>", element); |
| 4057 | |
| 4058 | while (*s) |
| 4059 | { |
| 4060 | if (*s == '&') |
| 4061 | cupsFilePuts(outfile, "&"); |
| 4062 | else if (*s == '<') |
| 4063 | cupsFilePuts(outfile, "<"); |
| 4064 | else if (*s == '>') |
| 4065 | cupsFilePuts(outfile, ">"); |
| 4066 | else if ((*s & 0xe0) == 0xc0) |
| 4067 | { |
| 4068 | /* |
| 4069 | * Validate UTF-8 two-byte sequence... |
| 4070 | */ |
| 4071 | |
| 4072 | if ((s[1] & 0xc0) != 0x80) |
| 4073 | { |
| 4074 | cupsFilePutChar(outfile, '?'); |
| 4075 | s ++; |
| 4076 | } |
| 4077 | else |
| 4078 | { |
| 4079 | cupsFilePutChar(outfile, *s++); |
| 4080 | cupsFilePutChar(outfile, *s); |
| 4081 | } |
| 4082 | } |
| 4083 | else if ((*s & 0xf0) == 0xe0) |
| 4084 | { |
| 4085 | /* |
| 4086 | * Validate UTF-8 three-byte sequence... |
| 4087 | */ |
| 4088 | |
| 4089 | if ((s[1] & 0xc0) != 0x80 || (s[2] & 0xc0) != 0x80) |
| 4090 | { |
| 4091 | cupsFilePutChar(outfile, '?'); |
| 4092 | s += 2; |
| 4093 | } |
| 4094 | else |
| 4095 | { |
| 4096 | cupsFilePutChar(outfile, *s++); |
| 4097 | cupsFilePutChar(outfile, *s++); |
| 4098 | cupsFilePutChar(outfile, *s); |
| 4099 | } |
| 4100 | } |
| 4101 | else if ((*s & 0xf8) == 0xf0) |
| 4102 | { |
| 4103 | /* |
| 4104 | * Validate UTF-8 four-byte sequence... |
| 4105 | */ |
| 4106 | |
| 4107 | if ((s[1] & 0xc0) != 0x80 || (s[2] & 0xc0) != 0x80 || |
no test coverage detected