Created
November 16, 2019 19:40
-
-
Save assyrianic/ac4844154d826336ec04b796d3a8fb95 to your computer and use it in GitHub Desktop.
parses a target path
This file contains hidden or 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
public bool ParseTargetPath(const char[] key, char[] buffer, int buffer_len) | |
{ | |
/// parse something like: "root.section1.section2.section3.\\..dotsection" | |
int i = strlen(key) - 1; | |
while( i > 0 ) { | |
/// Patch: allow keys to use dot without interfering with dot path. | |
/// check if we hit a dot. | |
if( key[i]=='.' ) { | |
/// if we hit a dot, check if the previous char is an "escape" char. | |
if( key[i-1]=='\\' ) | |
i--; | |
else { | |
i++; | |
break; | |
} | |
} else i--; | |
} | |
int n; | |
/// now we save the target section and then use the resulting string. | |
while( key[i] != 0 && n < buffer_len ) { | |
if( key[i]=='\\' ) { | |
i++; | |
continue; | |
} | |
buffer[n++] = key[i++]; | |
} | |
return n > 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment