@@ -151,12 +151,12 @@ class CommandLineParser {
151151 }
152152
153153 void removeOption (Option *O) {
154- SmallVector<const char * , 16 > OptionNames;
154+ SmallVector<StringRef , 16 > OptionNames;
155155 O->getExtraOptionNames (OptionNames);
156156 if (O->hasArgStr ())
157157 OptionNames.push_back (O->ArgStr );
158158 for (auto Name : OptionNames)
159- OptionsMap.erase (StringRef ( Name) );
159+ OptionsMap.erase (Name);
160160
161161 if (O->getFormattingFlag () == cl::Positional)
162162 for (auto Opt = PositionalOpts.begin (); Opt != PositionalOpts.end ();
@@ -182,13 +182,13 @@ class CommandLineParser {
182182 nullptr != ConsumeAfterOpt);
183183 }
184184
185- void updateArgStr (Option *O, const char * NewName) {
185+ void updateArgStr (Option *O, StringRef NewName) {
186186 if (!OptionsMap.insert (std::make_pair (NewName, O)).second ) {
187187 errs () << ProgramName << " : CommandLine Error: Option '" << O->ArgStr
188188 << " ' registered more than once!\n " ;
189189 report_fatal_error (" inconsistency in registered CommandLine options" );
190190 }
191- OptionsMap.erase (StringRef ( O->ArgStr ) );
191+ OptionsMap.erase (O->ArgStr );
192192 }
193193
194194 void printOptionValues ();
@@ -227,7 +227,7 @@ void Option::addArgument() {
227227
228228void Option::removeArgument () { GlobalParser->removeOption (this ); }
229229
230- void Option::setArgStr (const char * S) {
230+ void Option::setArgStr (StringRef S) {
231231 if (FullyInitialized)
232232 GlobalParser->updateArgStr (this , S);
233233 ArgStr = S;
@@ -296,24 +296,23 @@ static Option *LookupNearestOption(StringRef Arg,
296296 ie = OptionsMap.end ();
297297 it != ie; ++it) {
298298 Option *O = it->second ;
299- SmallVector<const char * , 16 > OptionNames;
299+ SmallVector<StringRef , 16 > OptionNames;
300300 O->getExtraOptionNames (OptionNames);
301- if (O->ArgStr [ 0 ] )
301+ if (O->hasArgStr () )
302302 OptionNames.push_back (O->ArgStr );
303303
304304 bool PermitValue = O->getValueExpectedFlag () != cl::ValueDisallowed;
305305 StringRef Flag = PermitValue ? LHS : Arg;
306- for (size_t i = 0 , e = OptionNames.size (); i != e; ++i) {
307- StringRef Name = OptionNames[i];
306+ for (auto Name : OptionNames) {
308307 unsigned Distance = StringRef (Name).edit_distance (
309308 Flag, /* AllowReplacements=*/ true , /* MaxEditDistance=*/ BestDistance);
310309 if (!Best || Distance < BestDistance) {
311310 Best = O;
312311 BestDistance = Distance;
313312 if (RHS.empty () || !PermitValue)
314- NearestString = OptionNames[i] ;
313+ NearestString = Name ;
315314 else
316- NearestString = (Twine (OptionNames[i] ) + " =" + RHS).str ();
315+ NearestString = (Twine (Name ) + " =" + RHS).str ();
317316 }
318317 }
319318 }
@@ -1157,8 +1156,8 @@ bool Option::addOccurrence(unsigned pos, StringRef ArgName, StringRef Value,
11571156// getValueStr - Get the value description string, using "DefaultMsg" if nothing
11581157// has been specified yet.
11591158//
1160- static const char * getValueStr (const Option &O, const char * DefaultMsg) {
1161- if (O.ValueStr [ 0 ] == 0 )
1159+ static StringRef getValueStr (const Option &O, StringRef DefaultMsg) {
1160+ if (O.ValueStr . empty () )
11621161 return DefaultMsg;
11631162 return O.ValueStr ;
11641163}
@@ -1168,7 +1167,7 @@ static const char *getValueStr(const Option &O, const char *DefaultMsg) {
11681167//
11691168
11701169// Return the width of the option tag for printing...
1171- size_t alias::getOptionWidth () const { return std::strlen ( ArgStr) + 6 ; }
1170+ size_t alias::getOptionWidth () const { return ArgStr. size ( ) + 6 ; }
11721171
11731172static void printHelpStr (StringRef HelpStr, size_t Indent,
11741173 size_t FirstLineIndentedBy) {
@@ -1183,7 +1182,7 @@ static void printHelpStr(StringRef HelpStr, size_t Indent,
11831182// Print out the option for the alias.
11841183void alias::printOptionInfo (size_t GlobalWidth) const {
11851184 outs () << " -" << ArgStr;
1186- printHelpStr (HelpStr, GlobalWidth, std::strlen ( ArgStr) + 6 );
1185+ printHelpStr (HelpStr, GlobalWidth, ArgStr. size ( ) + 6 );
11871186}
11881187
11891188// ===----------------------------------------------------------------------===//
@@ -1195,9 +1194,9 @@ void alias::printOptionInfo(size_t GlobalWidth) const {
11951194
11961195// Return the width of the option tag for printing...
11971196size_t basic_parser_impl::getOptionWidth (const Option &O) const {
1198- size_t Len = std::strlen ( O.ArgStr );
1197+ size_t Len = O.ArgStr . size ( );
11991198 if (const char *ValName = getValueName ())
1200- Len += std::strlen ( getValueStr (O, ValName)) + 3 ;
1199+ Len += getValueStr (O, ValName). size ( ) + 3 ;
12011200
12021201 return Len + 6 ;
12031202}
@@ -1218,7 +1217,7 @@ void basic_parser_impl::printOptionInfo(const Option &O,
12181217void basic_parser_impl::printOptionName (const Option &O,
12191218 size_t GlobalWidth) const {
12201219 outs () << " -" << O.ArgStr ;
1221- outs ().indent (GlobalWidth - std::strlen ( O.ArgStr ));
1220+ outs ().indent (GlobalWidth - O.ArgStr . size ( ));
12221221}
12231222
12241223// parser<bool> implementation
@@ -1332,7 +1331,7 @@ unsigned generic_parser_base::findOption(const char *Name) {
13321331// Return the width of the option tag for printing...
13331332size_t generic_parser_base::getOptionWidth (const Option &O) const {
13341333 if (O.hasArgStr ()) {
1335- size_t Size = std::strlen ( O.ArgStr ) + 6 ;
1334+ size_t Size = O.ArgStr . size ( ) + 6 ;
13361335 for (unsigned i = 0 , e = getNumOptions (); i != e; ++i)
13371336 Size = std::max (Size, std::strlen (getOption (i)) + 8 );
13381337 return Size;
@@ -1351,15 +1350,15 @@ void generic_parser_base::printOptionInfo(const Option &O,
13511350 size_t GlobalWidth) const {
13521351 if (O.hasArgStr ()) {
13531352 outs () << " -" << O.ArgStr ;
1354- printHelpStr (O.HelpStr , GlobalWidth, std::strlen ( O.ArgStr ) + 6 );
1353+ printHelpStr (O.HelpStr , GlobalWidth, O.ArgStr . size ( ) + 6 );
13551354
13561355 for (unsigned i = 0 , e = getNumOptions (); i != e; ++i) {
13571356 size_t NumSpaces = GlobalWidth - strlen (getOption (i)) - 8 ;
13581357 outs () << " =" << getOption (i);
13591358 outs ().indent (NumSpaces) << " - " << getDescription (i) << ' \n ' ;
13601359 }
13611360 } else {
1362- if (O.HelpStr [ 0 ] )
1361+ if (! O.HelpStr . empty () )
13631362 outs () << " " << O.HelpStr << ' \n ' ;
13641363 for (unsigned i = 0 , e = getNumOptions (); i != e; ++i) {
13651364 const char *Option = getOption (i);
@@ -1378,7 +1377,7 @@ void generic_parser_base::printGenericOptionDiff(
13781377 const Option &O, const GenericOptionValue &Value,
13791378 const GenericOptionValue &Default, size_t GlobalWidth) const {
13801379 outs () << " -" << O.ArgStr ;
1381- outs ().indent (GlobalWidth - std::strlen ( O.ArgStr ));
1380+ outs ().indent (GlobalWidth - O.ArgStr . size ( ));
13821381
13831382 unsigned NumOpts = getNumOptions ();
13841383 for (unsigned i = 0 ; i != NumOpts; ++i) {
@@ -1522,7 +1521,7 @@ class HelpPrinter {
15221521 outs () << " USAGE: " << GlobalParser->ProgramName << " [options]" ;
15231522
15241523 for (auto Opt : GlobalParser->PositionalOpts ) {
1525- if (Opt->ArgStr [ 0 ] )
1524+ if (Opt->hasArgStr () )
15261525 outs () << " --" << Opt->ArgStr ;
15271526 outs () << " " << Opt->HelpStr ;
15281527 }
0 commit comments