MCPcopy Create free account
hub / github.com/eggert/tz / format_quoted_string

Function format_quoted_string

zdump.c:965–990  ·  view source on GitHub ↗

Store into BUF (of size SIZE) a quoted string representation of P. If the representation's length is less than SIZE, return the length; the representation is not null terminated. Otherwise return SIZE, to indicate that BUF is too small. */

Source from the content-addressed store, hash-verified

963 length; the representation is not null terminated. Otherwise
964 return SIZE, to indicate that BUF is too small. */
965static ptrdiff_t
966format_quoted_string(char *buf, ptrdiff_t size, char const *p)
967{
968 char *b = buf;
969 ptrdiff_t s = size;
970 if (!s)
971 return size;
972 *b++ = '"', s--;
973 for (;;) {
974 char c = *p++;
975 if (s <= 1)
976 return size;
977 switch (c) {
978 default: *b++ = c, s--; continue;
979 case '\0': *b++ = '"', s--; return size - s;
980 case '"': case '\\': break;
981 case ' ': c = 's'; break;
982 case '\f': c = 'f'; break;
983 case '\n': c = 'n'; break;
984 case '\r': c = 'r'; break;
985 case '\t': c = 't'; break;
986 case '\v': c = 'v'; break;
987 }
988 *b++ = '\\', *b++ = c, s -= 2;
989 }
990}
991
992/* Store into BUF (of size SIZE) a timestamp formatted by TIME_FMT.
993 TM is the broken-down time, T the seconds count, AB the time zone

Callers 1

istrftimeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected