Unquote a string literal: "foo" -> foo, 'foo' -> foo
| 15 | |
| 16 | // Unquote a string literal: "foo" -> foo, 'foo' -> foo |
| 17 | static const char *unquote(CBMArena *a, const char *s) { |
| 18 | if (!s || !s[0]) { |
| 19 | return NULL; |
| 20 | } |
| 21 | // Trim whitespace |
| 22 | while (*s == ' ' || *s == '\t') { |
| 23 | s++; |
| 24 | } |
| 25 | size_t len = strlen(s); |
| 26 | if (len >= CBM_QUOTE_PAIR) { |
| 27 | char first = s[0]; |
| 28 | char last = s[len - CBM_QUOTE_OFFSET]; |
| 29 | if ((first == '"' && last == '"') || (first == '\'' && last == '\'') || |
| 30 | (first == '`' && last == '`')) { |
| 31 | return cbm_arena_strndup(a, s + CBM_QUOTE_OFFSET, len - CBM_QUOTE_PAIR); |
| 32 | } |
| 33 | } |
| 34 | return s; |
| 35 | } |
| 36 | |
| 37 | // Extract env key from a function call like os.Getenv("KEY"). |
| 38 | static const char *extract_env_key_from_call(CBMExtractCtx *ctx, TSNode node, |
no test coverage detected