Explorar el Código

Address SonarLint findings in Color class

Patrick-Christopher Mattulat hace 1 año
padre
commit
4f9910a1fe

+ 7 - 7
test/cases/event/NarratorTest.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-14
- * Changed:         2023-03-25
+ * Changed:         2023-05-15
  *
  * */
 
@@ -147,15 +147,15 @@ namespace
     paintingMachine.addListener(this->mercedes2);
     paintingMachine.addListener(this->mercedes3);
 
-    ASSERT_STREQ("pink", this->mercedes1->getColor().c_str());
-    ASSERT_STREQ("blue", this->mercedes2->getColor().c_str());
-    ASSERT_STREQ("red", this->mercedes3->getColor().c_str());
+    ASSERT_STREQ("pink", this->mercedes1->getColor().data());
+    ASSERT_STREQ("blue", this->mercedes2->getColor().data());
+    ASSERT_STREQ("red", this->mercedes3->getColor().data());
 
     Colour newColor = Colour{"black"};
     paintingMachine.tell(static_cast<const Class &>(newColor));
 
-    ASSERT_STREQ("black", this->mercedes1->getColor().c_str());
-    ASSERT_STREQ("black", this->mercedes2->getColor().c_str());
-    ASSERT_STREQ("black", this->mercedes3->getColor().c_str());
+    ASSERT_STREQ("black", this->mercedes1->getColor().data());
+    ASSERT_STREQ("black", this->mercedes2->getColor().data());
+    ASSERT_STREQ("black", this->mercedes3->getColor().data());
   }
 }

+ 5 - 6
test/classes/event/Colour.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2022-05-14
- * Changed:         2023-02-23
+ * Changed:         2023-05-15
  *
  * */
 
@@ -11,16 +11,15 @@
 
 using ls::std::core::Class;
 using std::string;
+using std::string_view;
 using test::event::Colour;
 
-Colour::Colour(const string &_value) : Class("Colour")
-{
-  this->value = _value;
-}
+Colour::Colour(string_view _value) : Class("Colour"), value(_value)
+{}
 
 Colour::~Colour() noexcept = default;
 
-string Colour::getValue() const
+string_view Colour::getValue() const
 {
   return this->value;
 }

+ 5 - 4
test/classes/event/Colour.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2022-05-14
- * Changed:         2023-02-23
+ * Changed:         2023-05-15
  *
  * */
 
@@ -11,6 +11,7 @@
 #define LS_STD_COLOUR_HPP
 
 #include <ls-std/ls-std-core.hpp>
+#include <string_view>
 
 namespace test::event
 {
@@ -18,14 +19,14 @@ namespace test::event
   {
     public:
 
-      explicit Colour(const ::std::string &_value);
+      explicit Colour(::std::string_view _value);
       ~Colour() noexcept override;
 
-      [[nodiscard]] ::std::string getValue() const;
+      [[nodiscard]] ::std::string_view getValue() const;
 
     private:
 
-      ::std::string value{};
+      ::std::string_view value{};
   };
 }
 

+ 5 - 6
test/classes/event/TestDataCar.cpp

@@ -3,14 +3,13 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-14
- * Changed:         2023-02-23
+ * Changed:         2023-05-15
  *
  * */
 
 #include "TestDataCar.hpp"
 
-using std::move;
-using std::string;
+using std::string_view;
 using test::event::TestDataCar;
 
 TestDataCar::TestDataCar() : color("white")
@@ -18,12 +17,12 @@ TestDataCar::TestDataCar() : color("white")
 
 TestDataCar::~TestDataCar() = default;
 
-string TestDataCar::getColor()
+string_view TestDataCar::getColor()
 {
   return this->color;
 }
 
-void TestDataCar::setColor(string _color)
+void TestDataCar::setColor(string_view _color)
 {
-  this->color = ::move(_color);
+  this->color = _color;
 }

+ 5 - 4
test/classes/event/TestDataCar.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-14
- * Changed:         2023-03-27
+ * Changed:         2023-05-15
  *
  * */
 
@@ -11,6 +11,7 @@
 #define LS_STD_TEST_DATA_CAR_HPP
 
 #include <string>
+#include <string_view>
 
 namespace test::event
 {
@@ -21,12 +22,12 @@ namespace test::event
       TestDataCar();
       virtual ~TestDataCar();
 
-      [[nodiscard]] ::std::string getColor();
-      void setColor(::std::string _color);
+      [[nodiscard]] ::std::string_view getColor();
+      void setColor(::std::string_view _color);
 
     private:
 
-      ::std::string color{};
+      ::std::string_view color{};
   };
 }