MCPcopy Create free account
hub / github.com/coreutils/coreutils / collapse_escapes

Function collapse_escapes

src/paste.c:92–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90 final backslash and return nonzero. */
91
92static int
93collapse_escapes (char const *strptr)
94{
95 char *strout = xstrdup (strptr);
96 bool backslash_at_end = false;
97
98 delims = strout;
99 delim_lens = xnmalloc (MAX (1, strlen (strptr)), sizeof *delim_lens);
100
101 char const *s = strptr;
102 idx_t idx = 0;
103
104 while (*s)
105 {
106 if (*s == '\\')
107 {
108 s++;
109 if (*s == '\0')
110 {
111 backslash_at_end = true;
112 break;
113 }
114 else if (*s == '0')
115 {
116 /* Empty delimiter at this position. */
117 s++;
118 delim_lens[idx++] = 0;
119 }
120 else
121 {
122 switch (*s)
123 {
124 case 'b': *strout++ = '\b'; break;
125 case 'f': *strout++ = '\f'; break;
126 case 'n': *strout++ = '\n'; break;
127 case 'r': *strout++ = '\r'; break;
128 case 't': *strout++ = '\t'; break;
129 case 'v': *strout++ = '\v'; break;
130 case '\\': *strout++ = '\\'; break;
131 default: goto copy_character;
132 }
133
134 s++;
135 delim_lens[idx++] = 1;
136 }
137
138 continue;
139 }
140
141 copy_character:;
142 mcel_t g = mcel_scanz (s);
143 strout = mempcpy (strout, s, g.len);
144 s += g.len;
145 delim_lens[idx++] = g.len;
146 }
147
148 *strout = '\0';
149

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected