-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix include #2604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix include #2604
Conversation
I like the simplification of leaving out regex.h. But I don't think you need to make a copy. For example, for the first of the two sections, wouldn't this suffice?:
|
strtok(str) will set the next byte of last byte of token to '\0' if token found, so it may change the str. If str contains multiple [ \t], and we need enumerate all possible tokens(call strtok multiple times), multiple bytes would be set to 0. below is a example.
the output is: token2 = www.runoob.com token3 = website str =This is For our case, strtok only is called only once, and based on the below grammar, it is NOT possible there is a [ \t]+ in "CONFIG_VALUE_PATH", so strtok will not change CONFIG_VALUE_PATH LUCKILY; so below change can suffice. But I think it is a good practice to first strdup and then free for strtok:
|
Ok, good point. I agree that it's unwise to use strtok here without a copy. Is it worth considering using strspn instead? It's a little more narrowly focussed on what is needed here.
|
Perfect, strspn exactly matches this context. I think I should go through libc.pdf to know every function. const char *file = yytext + strlen("include")+ strspn ( yytext + strlen("include"), " \t"); Is it OK to remove tmpStr? |
#include <stdio.h> |
BTW, |
misoperation close this PR and delete lexhandle |
Regarding collapsing the code change to a single line, I might lean towards leaving it as two lines, because:
My preference on that isn't particularly strong, however, |
reasonable |
will submit PR tomorrow |
Fix lex "include [ \t]filename" handle. To support more spaces/tabs after include key word. Before this change, code supports only one space after include. but lex support more.