Created
September 28, 2019 06:26
-
-
Save aiya000/dd57209f3abf43ce0a46fafb242fe79c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int is_closing_quote(char *template, int is_literal_string, int has_previous) | |
{ | |
if (!is_literal_string) | |
{ | |
// is not \" | |
return | |
(!has_previous || *(template - 1) != '\\') && | |
(*template == '"'); | |
} | |
// is not '' | |
return | |
(has_previous && *(template - 1) != '\'' && *template == '\'') || | |
(*template == '\'' && *(template + 1) != '\'') ; | |
} | |
int main(void) { | |
// char* str = "ho-ya! \\\"\""; | |
// printf("%d\n", is_closing_quote(str, 0, 0)); // 0 | |
// printf("%d\n", is_closing_quote(str + 8, 0, 1)); // 0 | |
// printf("%d\n", is_closing_quote(str + 9, 0, 1)); // 1 | |
char* lit = "ho-ya! '''"; | |
printf("%d\n", is_closing_quote(lit, 1, 0)); // 0 | |
printf("%d\n", is_closing_quote(lit + 7, 1, 0)); // 0 | |
printf("%d\n", is_closing_quote(lit + 8, 1, 0)); // 0 | |
printf("%d\n", is_closing_quote(lit + 9, 1, 0)); // 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment