Skip to content

Instantly share code, notes, and snippets.

@assyrianic
Created November 16, 2019 19:40
Show Gist options
  • Save assyrianic/ac4844154d826336ec04b796d3a8fb95 to your computer and use it in GitHub Desktop.
Save assyrianic/ac4844154d826336ec04b796d3a8fb95 to your computer and use it in GitHub Desktop.
parses a target path
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