-/* Why doesn't pango/gtk have these quoting functions? */
-static inline int add_char(char *buffer, size_t size, int len, char c)
-{
- if (len < size)
- buffer[len++] = c;
- return len;
-}
-
-/* Add an escape string "atomically" - all or nothing */
-static int add_str(char *buffer, size_t size, int len, const char *s)
-{
- int oldlen = len;
- char c;
- while ((c = *s++) != 0) {
- if (len >= size)
- return oldlen;
- buffer[len++] = c;
- }
- return len;
-}
-
-static int add_quoted_string(char *buffer, size_t size, int len, const char *s)
-{
- if (!s)
- return len;
-
- /* Room for '\0' */
- size--;
- for (;;) {
- const char *escape;
- unsigned char c = *s++;
- switch(c) {
- default:
- len = add_char(buffer, size, len, c);
- continue;
- case 0:
- escape = "\n";
- break;
- case '&':
- escape = "&";
- break;
- case '>':
- escape = ">";
- break;
- case '<':
- escape = "<";
- break;
- }
- len = add_str(buffer, size, len, escape);
- if (c)
- continue;
- buffer[len] = 0;
- return len;
- }
-}
-