Przeglądaj źródła

cmIDEOptions: use std::string

Vitaly Stakhovsky 7 lat temu
rodzic
commit
8182ebca32

+ 22 - 20
Source/cmIDEOptions.cxx

@@ -25,7 +25,7 @@ cmIDEOptions::~cmIDEOptions()
 {
 }
 
-void cmIDEOptions::HandleFlag(const char* flag)
+void cmIDEOptions::HandleFlag(std::string const& flag)
 {
   // If the last option was -D then this option is the definition.
   if (this->DoingDefine) {
@@ -49,26 +49,27 @@ void cmIDEOptions::HandleFlag(const char* flag)
   }
 
   // Look for known arguments.
-  if (flag[0] == '-' || (this->AllowSlash && flag[0] == '/')) {
+  size_t len = flag.length();
+  if (len > 0 && (flag[0] == '-' || (this->AllowSlash && flag[0] == '/'))) {
     // Look for preprocessor definitions.
-    if (this->AllowDefine && flag[1] == 'D') {
-      if (flag[2] == '\0') {
+    if (this->AllowDefine && len > 1 && flag[1] == 'D') {
+      if (len <= 2) {
         // The next argument will have the definition.
         this->DoingDefine = true;
       } else {
         // Store this definition.
-        this->Defines.push_back(flag + 2);
+        this->Defines.push_back(flag.substr(2));
       }
       return;
     }
     // Look for include directory.
-    if (this->AllowInclude && flag[1] == 'I') {
-      if (flag[2] == '\0') {
+    if (this->AllowInclude && len > 1 && flag[1] == 'I') {
+      if (len <= 2) {
         // The next argument will have the include directory.
         this->DoingInclude = true;
       } else {
         // Store this include directory.
-        this->Includes.push_back(flag + 2);
+        this->Includes.push_back(flag.substr(2));
       }
       return;
     }
@@ -92,8 +93,9 @@ void cmIDEOptions::HandleFlag(const char* flag)
 }
 
 bool cmIDEOptions::CheckFlagTable(cmIDEFlagTable const* table,
-                                  const char* flag, bool& flag_handled)
+                                  std::string const& flag, bool& flag_handled)
 {
+  const char* pf = flag.c_str() + 1;
   // Look for an entry in the flag table matching this flag.
   for (cmIDEFlagTable const* entry = table; entry->IDEName; ++entry) {
     bool entry_found = false;
@@ -102,17 +104,17 @@ bool cmIDEOptions::CheckFlagTable(cmIDEFlagTable const* table,
       // the entry specifies UserRequired we must match only if a
       // non-empty value is given.
       int n = static_cast<int>(strlen(entry->commandFlag));
-      if ((strncmp(flag + 1, entry->commandFlag, n) == 0 ||
+      if ((strncmp(pf, entry->commandFlag, n) == 0 ||
            (entry->special & cmIDEFlagTable::CaseInsensitive &&
-            cmsysString_strncasecmp(flag + 1, entry->commandFlag, n))) &&
+            cmsysString_strncasecmp(pf, entry->commandFlag, n))) &&
           (!(entry->special & cmIDEFlagTable::UserRequired) ||
-           static_cast<int>(strlen(flag + 1)) > n)) {
-        this->FlagMapUpdate(entry, flag + n + 1);
+           static_cast<int>(strlen(pf)) > n)) {
+        this->FlagMapUpdate(entry, std::string(pf + n));
         entry_found = true;
       }
-    } else if (strcmp(flag + 1, entry->commandFlag) == 0 ||
+    } else if (strcmp(pf, entry->commandFlag) == 0 ||
                (entry->special & cmIDEFlagTable::CaseInsensitive &&
-                cmsysString_strcasecmp(flag + 1, entry->commandFlag) == 0)) {
+                cmsysString_strcasecmp(pf, entry->commandFlag) == 0)) {
       if (entry->special & cmIDEFlagTable::UserFollowing) {
         // This flag expects a value in the following argument.
         this->DoingFollowing = entry;
@@ -137,7 +139,7 @@ bool cmIDEOptions::CheckFlagTable(cmIDEFlagTable const* table,
 }
 
 void cmIDEOptions::FlagMapUpdate(cmIDEFlagTable const* entry,
-                                 const char* new_value)
+                                 std::string const& new_value)
 {
   if (entry->special & cmIDEFlagTable::UserIgnored) {
     // Ignore the user-specified value.
@@ -157,9 +159,9 @@ void cmIDEOptions::AddDefine(const std::string& def)
   this->Defines.push_back(def);
 }
 
-void cmIDEOptions::AddDefines(const char* defines)
+void cmIDEOptions::AddDefines(std::string const& defines)
 {
-  if (defines) {
+  if (!defines.empty()) {
     // Expand the list of definitions.
     cmSystemTools::ExpandListArgument(defines, this->Defines);
   }
@@ -179,9 +181,9 @@ void cmIDEOptions::AddInclude(const std::string& include)
   this->Includes.push_back(include);
 }
 
-void cmIDEOptions::AddIncludes(const char* includes)
+void cmIDEOptions::AddIncludes(std::string const& includes)
 {
-  if (includes) {
+  if (!includes.empty()) {
     // Expand the list of includes.
     cmSystemTools::ExpandListArgument(includes, this->Includes);
   }

+ 7 - 6
Source/cmIDEOptions.h

@@ -22,12 +22,12 @@ public:
 
   // Store definitions, includes and flags.
   void AddDefine(const std::string& define);
-  void AddDefines(const char* defines);
+  void AddDefines(std::string const& defines);
   void AddDefines(const std::vector<std::string>& defines);
   std::vector<std::string> const& GetDefines() const;
 
   void AddInclude(const std::string& includes);
-  void AddIncludes(const char* includes);
+  void AddIncludes(std::string const& includes);
   void AddIncludes(const std::vector<std::string>& includes);
   std::vector<std::string> const& GetIncludes() const;
 
@@ -95,11 +95,12 @@ protected:
     FlagTableCount = 16
   };
   cmIDEFlagTable const* FlagTable[FlagTableCount];
-  void HandleFlag(const char* flag);
-  bool CheckFlagTable(cmIDEFlagTable const* table, const char* flag,
+  void HandleFlag(std::string const& flag);
+  bool CheckFlagTable(cmIDEFlagTable const* table, std::string const& flag,
                       bool& flag_handled);
-  void FlagMapUpdate(cmIDEFlagTable const* entry, const char* new_value);
-  virtual void StoreUnknownFlag(const char* flag) = 0;
+  void FlagMapUpdate(cmIDEFlagTable const* entry,
+                     std::string const& new_value);
+  virtual void StoreUnknownFlag(std::string const& flag) = 0;
 };
 
 #endif

+ 2 - 2
Source/cmLocalVisualStudio7Generator.cxx

@@ -1678,8 +1678,8 @@ bool cmLocalVisualStudio7Generator::WriteGroup(
             }
             Options fileOptions(this, tool, table, gg->ExtraFlagTable);
             fileOptions.Parse(fc.CompileFlags.c_str());
-            fileOptions.AddDefines(fc.CompileDefs.c_str());
-            fileOptions.AddDefines(fc.CompileDefsConfig.c_str());
+            fileOptions.AddDefines(fc.CompileDefs);
+            fileOptions.AddDefines(fc.CompileDefsConfig);
             // validate source level include directories
             std::vector<std::string> includes;
             this->AppendIncludeDirectories(includes, fc.IncludeDirs, **sf);

+ 1 - 1
Source/cmVisualStudio10TargetGenerator.cxx

@@ -2138,7 +2138,7 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
         clOptions.AddDefines(
           genexInterpreter.Evaluate(configDefines, "COMPILE_DEFINITIONS"));
       } else {
-        clOptions.AddDefines(configDefines.c_str());
+        clOptions.AddDefines(configDefines);
       }
       std::vector<std::string> includeList;
       if (configDependentIncludes) {

+ 7 - 7
Source/cmVisualStudioGeneratorOptions.cxx

@@ -331,7 +331,7 @@ void cmVisualStudioGeneratorOptions::Parse(const char* flags)
   // Process flags that need to be represented specially in the IDE
   // project file.
   for (std::string const& ai : args) {
-    this->HandleFlag(ai.c_str());
+    this->HandleFlag(ai);
   }
 }
 
@@ -393,23 +393,23 @@ void cmVisualStudioGeneratorOptions::Reparse(std::string const& key)
   this->Parse(original.c_str());
 }
 
-void cmVisualStudioGeneratorOptions::StoreUnknownFlag(const char* flag)
+void cmVisualStudioGeneratorOptions::StoreUnknownFlag(std::string const& flag)
 {
   // Look for Intel Fortran flags that do not map well in the flag table.
   if (this->CurrentTool == FortranCompiler) {
-    if (strcmp(flag, "/dbglibs") == 0) {
+    if (flag == "/dbglibs") {
       this->FortranRuntimeDebug = true;
       return;
     }
-    if (strcmp(flag, "/threads") == 0) {
+    if (flag == "/threads") {
       this->FortranRuntimeMT = true;
       return;
     }
-    if (strcmp(flag, "/libs:dll") == 0) {
+    if (flag == "/libs:dll") {
       this->FortranRuntimeDLL = true;
       return;
     }
-    if (strcmp(flag, "/libs:static") == 0) {
+    if (flag == "/libs:static") {
       this->FortranRuntimeDLL = false;
       return;
     }
@@ -417,7 +417,7 @@ void cmVisualStudioGeneratorOptions::StoreUnknownFlag(const char* flag)
 
   // This option is not known.  Store it in the output flags.
   std::string const opts = cmOutputConverter::EscapeWindowsShellArgument(
-    flag, cmOutputConverter::Shell_Flag_AllowMakeVariables |
+    flag.c_str(), cmOutputConverter::Shell_Flag_AllowMakeVariables |
       cmOutputConverter::Shell_Flag_VSIDE);
   this->AppendFlagString(this->UnknownFlagField, opts);
 }

+ 1 - 1
Source/cmVisualStudioGeneratorOptions.h

@@ -107,7 +107,7 @@ private:
 
   std::string UnknownFlagField;
 
-  virtual void StoreUnknownFlag(const char* flag);
+  void StoreUnknownFlag(std::string const& flag) override;
 
   FlagValue TakeFlag(std::string const& key);
 };