+ if (Name.size() == 1) return 0;
+ do {
+ Name.erase(Name.end()-1, Name.end()); // Chop off the last character...
+ OMI = OptionsMap.find(Name);
+
+ // Loop while we haven't found an option and Name still has at least two
+ // characters in it (so that the next iteration will not be the empty
+ // string...
+ } while ((OMI == OptionsMap.end() || !Pred(OMI->second)) && Name.size() > 1);
+
+ if (OMI != OptionsMap.end() && Pred(OMI->second)) {
+ Length = Name.length();
+ return OMI->second; // Found one!
+ }
+ return 0; // No option found!
+}
+
+static bool RequiresValue(const Option *O) {
+ return O->getNumOccurrencesFlag() == cl::Required ||
+ O->getNumOccurrencesFlag() == cl::OneOrMore;
+}
+
+static bool EatsUnboundedNumberOfValues(const Option *O) {
+ return O->getNumOccurrencesFlag() == cl::ZeroOrMore ||
+ O->getNumOccurrencesFlag() == cl::OneOrMore;
+}
+
+/// ParseCStringVector - Break INPUT up wherever one or more
+/// whitespace characters are found, and store the resulting tokens in
+/// OUTPUT. The tokens stored in OUTPUT are dynamically allocated
+/// using strdup (), so it is the caller's responsibility to free ()
+/// them later.
+///
+static void ParseCStringVector(std::vector<char *> &output,
+ const char *input) {
+ // Characters which will be treated as token separators:
+ static const char *delims = " \v\f\t\r\n";
+
+ std::string work (input);
+ // Skip past any delims at head of input string.
+ size_t pos = work.find_first_not_of (delims);
+ // If the string consists entirely of delims, then exit early.
+ if (pos == std::string::npos) return;
+ // Otherwise, jump forward to beginning of first word.
+ work = work.substr (pos);
+ // Find position of first delimiter.
+ pos = work.find_first_of (delims);
+
+ while (!work.empty() && pos != std::string::npos) {
+ // Everything from 0 to POS is the next word to copy.
+ output.push_back (strdup (work.substr (0,pos).c_str ()));
+ // Is there another word in the string?
+ size_t nextpos = work.find_first_not_of (delims, pos + 1);
+ if (nextpos != std::string::npos) {
+ // Yes? Then remove delims from beginning ...
+ work = work.substr (work.find_first_not_of (delims, pos + 1));
+ // and find the end of the word.
+ pos = work.find_first_of (delims);
+ } else {
+ // No? (Remainder of string is delims.) End the loop.
+ work = "";
+ pos = std::string::npos;