Browse Source

Fix SonarLint findings in SerializableSectionPairSection class

Patrick-Christopher Mattulat 1 year ago
parent
commit
eada8665ed

+ 3 - 3
include/ls-std/io/section-pair/serialization/SerializableSectionPairSection.hpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-14
-* Changed:         2023-05-18
+* Changed:         2023-05-19
 *
 * */
 
@@ -34,7 +34,7 @@ namespace ls::std::io
 
       ls::std::io::SerializableSectionPairParameter parameter{};
 
-      [[nodiscard]] ls::std::core::type::byte_field _collectSectionRow(const ls::std::core::type::byte_field &_currentRows, ls::std::io::SectionPairRowEnumType &_type);
+      [[nodiscard]] ls::std::core::type::byte_field _collectSectionRow(const ls::std::core::type::byte_field &_currentRows, ls::std::io::SectionPairRowEnumType &_type) const;
       [[nodiscard]] ls::std::core::type::byte_field _collectSectionListValueRow(const core::type::byte_field &_currentRows, ls::std::io::SectionPairRowEnumType &_type) const;
       [[nodiscard]] static core::type::byte_field _collectSectionSingleValueRow(const ls::std::core::type::byte_field &_firstRow, ls::std::io::SectionPairRowEnumType &type);
       [[nodiscard]] static size_t _getNthSubStringPosition(::std::string_view _text, ::std::string_view _subText);
@@ -47,7 +47,7 @@ namespace ls::std::io
       [[nodiscard]] ls::std::core::type::byte_field _marshalSectionId() const;
       void _unmarshalRow(const ::std::string &_sectionRow, ls::std::io::SectionPairRowEnumType _type) const;
       void _unmarshalRows(const ls::std::core::type::byte_field &_serializedRows);
-      [[nodiscard]] size_t _unmarshalSectionHeader(const ls::std::core::type::byte_field &_data);
+      [[nodiscard]] size_t _unmarshalSectionHeader(const ls::std::core::type::byte_field &_data) const;
   };
 }
 

+ 4 - 5
source/ls-std/io/section-pair/serialization/SerializableSectionPairSection.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-14
-* Changed:         2023-05-18
+* Changed:         2023-05-19
 *
 * */
 
@@ -59,7 +59,7 @@ void SerializableSectionPairSection::unmarshal(const byte_field &_data)
   this->_unmarshalRows(_data.substr(sectionHeaderSize));
 }
 
-byte_field SerializableSectionPairSection::_collectSectionRow(const byte_field &_currentRows, SectionPairRowEnumType &_type)
+byte_field SerializableSectionPairSection::_collectSectionRow(const byte_field &_currentRows, SectionPairRowEnumType &_type) const
 {
   string row{};
   string newLine = this->parameter.getNewLine();
@@ -141,9 +141,8 @@ byte_field SerializableSectionPairSection::_getSectionHeader(const byte_field &_
 {
   byte_field sectionHeader{};
   string newLine = this->parameter.getNewLine();
-  size_t position = SerializableSectionPairSection::_getNthSubStringPosition(_data, newLine);
 
-  if (position != -1)
+  if (size_t position = SerializableSectionPairSection::_getNthSubStringPosition(_data, newLine); position != -1)
   {
     sectionHeader = _data.substr(0, position + 2 * newLine.size());
   }
@@ -215,7 +214,7 @@ void SerializableSectionPairSection::_unmarshalRows(const byte_field &_serialize
   }
 }
 
-size_t SerializableSectionPairSection::_unmarshalSectionHeader(const byte_field &_data)
+size_t SerializableSectionPairSection::_unmarshalSectionHeader(const byte_field &_data) const
 {
   byte_field sectionHeader = this->_getSectionHeader(_data);
   dynamic_pointer_cast<SectionPairSection>(this->parameter.getValue())->setSectionId(SerializableSectionPairSection::_getSectionId(sectionHeader));