Last active
June 16, 2017 18:22
-
-
Save yamaguchi1024/5213d3312a42fcf869a5eedec2cbb24f 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
static bool optionMatches(const OptTable::Info &In, std::string C) { | |
if (!In.ArgValues || !In.Prefixes) | |
return true; | |
for (size_t I = 0; In.Prefixes[I]; I++) | |
if (C == std::string(In.Prefixes[I]) + In.Name) | |
return false; | |
return true; | |
} | |
// This function is for flag value completion. | |
// Eg. When l,=,-stdlib was passed to this function, it will return appropiriate | |
// values for stdlib, which starts with l. | |
std::vector<std::string> OptTable::suggestValueCompletions( | |
const SmallVectorImpl<StringRef> &Command) const { | |
if (Command.size() <= 1) | |
return {}; | |
std::vector<std::string> Result; | |
int eq = 0; | |
std::string C; | |
if (Command[0] == "=") { | |
C = std::string(Command[1]) + "="; | |
eq = 1; | |
} else { | |
// values are parsed like l,=,-stdlib by bash. We have to concat = to | |
// -stdlib because they are separated. | |
C = (Command[1] == "=") ? std::string(Command[2]) + "=" | |
: std::string(Command[1]); | |
} | |
for (const Info &In : OptionInfos.slice(FirstSearchableIndex)) { | |
if (optionMatches(In, C)) | |
continue; | |
SmallVector<StringRef, 8> Values; | |
StringRef(In.ArgValues).split(Values, ",", -1, false); | |
for (StringRef Val : Values) { | |
if (eq) | |
Result.push_back(Val); | |
else if (Val.startswith(Command[0])) | |
Result.push_back(Val); | |
} | |
} | |
return Result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment