MCPcopy Create free account
hub / github.com/git/git / unquote_c_style

Function unquote_c_style

quote.c:386–442  ·  view source on GitHub ↗

* C-style name unquoting. * * Quoted should point at the opening double quote. * + Returns 0 if it was able to unquote the string properly, and appends the * result in the strbuf `sb'. * + Returns -1 in case of error, and doesn't touch the strbuf. Though note * that this function will allocate memory in the strbuf, so calling * strbuf_release is mandatory whichever result unquote_c_st

Source from the content-addressed store, hash-verified

384 * Updates endp pointer to point at one past the ending double quote if given.
385 */
386int unquote_c_style(struct strbuf *sb, const char *quoted, const char **endp)
387{
388 size_t oldlen = sb->len, len;
389 int ch, ac;
390
391 if (*quoted++ != '"')
392 return -1;
393
394 for (;;) {
395 len = strcspn(quoted, "\"\\");
396 strbuf_add(sb, quoted, len);
397 quoted += len;
398
399 switch (*quoted++) {
400 case '"':
401 if (endp)
402 *endp = quoted;
403 return 0;
404 case '\\':
405 break;
406 default:
407 goto error;
408 }
409
410 switch ((ch = *quoted++)) {
411 case 'a': ch = '\a'; break;
412 case 'b': ch = '\b'; break;
413 case 'f': ch = '\f'; break;
414 case 'n': ch = '\n'; break;
415 case 'r': ch = '\r'; break;
416 case 't': ch = '\t'; break;
417 case 'v': ch = '\v'; break;
418
419 case '\\': case '"':
420 break; /* verbatim */
421
422 /* octal values with first digit over 4 overflow */
423 case '0': case '1': case '2': case '3':
424 ac = ((ch - '0') << 6);
425 if ((ch = *quoted++) < '0' || '7' < ch)
426 goto error;
427 ac |= ((ch - '0') << 3);
428 if ((ch = *quoted++) < '0' || '7' < ch)
429 goto error;
430 ac |= (ch - '0');
431 ch = ac;
432 break;
433 default:
434 goto error;
435 }
436 strbuf_addch(sb, ch);
437 }
438
439 error:
440 strbuf_setlen(sb, oldlen);
441 return -1;
442}
443

Callers 15

parse_pathspec_fileFunction · 0.85
set_optionFunction · 0.85
add_file_cbFunction · 0.85
parse_attr_lineFunction · 0.85
find_name_gnuFunction · 0.85
git_header_nameFunction · 0.85
parse_alternatesFunction · 0.85
push_update_ref_statusFunction · 0.85
mktree_lineFunction · 0.85
parse_argFunction · 0.85
cmd_checkout_indexFunction · 0.85
check_attr_stdin_pathsFunction · 0.85

Calls 3

strbuf_addFunction · 0.85
strbuf_addchFunction · 0.85
strbuf_setlenFunction · 0.85

Tested by 1

parse_pathspec_fileFunction · 0.68