Prechádzať zdrojové kódy

Remove SectionPairSectionIdUnmarshalValidator class

This validator is no longer needed, since there is now a dedicated evaluator for
SectionPairSection class.
Patrick-Christopher Mattulat 1 rok pred
rodič
commit
51deda0e9a

+ 0 - 2
CMakeLists.txt

@@ -186,7 +186,6 @@ set(SOURCE_FILES_IO
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/section-pair/validator/SectionPairRowListValueValidator.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/section-pair/validator/SectionPairRowSingleValueValidator.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/section-pair/validator/SectionPairRowValidator.cpp
-        ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/section-pair/validator/SectionPairSectionIdUnmarshalValidator.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/section-pair/validator/SectionPairSectionValidator.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/section-pair/validator/SectionPairValueValidator.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/section-pair/serialization/SerializableSectionPairDocument.cpp
@@ -286,7 +285,6 @@ if (${LS_STD_BUILD_WITH_TESTS})
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/section-pair/validator/SectionPairRowListValueValidatorTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/section-pair/validator/SectionPairRowSingleValueValidatorTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/section-pair/validator/SectionPairRowValidatorTest.cpp
-            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/section-pair/validator/SectionPairSectionIdUnmarshalValidatorTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/section-pair/validator/SectionPairSectionValidatorTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/section-pair/validator/SectionPairValueValidatorTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/section-pair/model/SectionPairDocumentTest.cpp

+ 1 - 2
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-02-17
+* Changed:         2023-02-20
 *
 * */
 
@@ -33,7 +33,6 @@ namespace ls::std::io
 
       ls::std::io::SerializableSectionPairParameter parameter{};
 
-      void _checkSectionHeader(const ls::std::core::type::byte_field &_sectionHeader);
       [[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 _collectSectionListValueRow(const core::type::byte_field &_currentRows, SectionPairRowEnumType &_type);
       [[nodiscard]] static core::type::byte_field _collectSectionSingleValueRow(const ls::std::core::type::byte_field &_firstRow, SectionPairRowEnumType &type);

+ 0 - 40
include/ls-std/io/section-pair/validator/SectionPairSectionIdUnmarshalValidator.hpp

@@ -1,40 +0,0 @@
-/*
-* Author:          Patrick-Christopher Mattulat
-* Company:         Lynar Studios
-* E-Mail:          webmaster@lynarstudios.com
-* Created:         2023-02-14
-* Changed:         2023-02-17
-*
-* */
-
-#ifndef LS_STD_SECTION_PAIR_SECTION_ID_UNMARSHAL_VALIDATOR_HPP
-#define LS_STD_SECTION_PAIR_SECTION_ID_UNMARSHAL_VALIDATOR_HPP
-
-#include <ls-std/core/Class.hpp>
-#include <ls-std/core/interface/IValidator.hpp>
-#include <ls-std/core/type/Types.hpp>
-#include <ls-std/os/dynamic-goal.hpp>
-#include <string>
-
-namespace ls::std::io
-{
-  class LS_STD_DYNAMIC_GOAL SectionPairSectionIdUnmarshalValidator : public ls::std::core::Class, public ls::std::core::interface_type::IValidator
-  {
-    public:
-
-      explicit SectionPairSectionIdUnmarshalValidator(ls::std::core::type::byte_field _data, ::std::string _newLine);
-      ~SectionPairSectionIdUnmarshalValidator() override;
-
-      [[nodiscard]] bool isValid() override;
-
-    private:
-
-      ls::std::core::type::byte_field data{};
-      ::std::string newLine{};
-
-      [[nodiscard]] static bool _isValidSection(const ls::std::core::type::byte_field &_bracketsNotation);
-      [[nodiscard]] static ls::std::core::type::byte_field _trimStartAndEnd(const ls::std::core::type::byte_field &_trimmedWord, const ls::std::core::type::byte_field &_beginningTrimWord, const ls::std::core::type::byte_field &_endingTrimWord);
-  };
-}
-
-#endif

+ 0 - 1
include/ls-std/ls-std-io.hpp

@@ -40,7 +40,6 @@
 #include <ls-std/io/section-pair/validator/SectionPairRowListValueValidator.hpp>
 #include <ls-std/io/section-pair/validator/SectionPairRowSingleValueValidator.hpp>
 #include <ls-std/io/section-pair/validator/SectionPairRowValidator.hpp>
-#include <ls-std/io/section-pair/validator/SectionPairSectionIdUnmarshalValidator.hpp>
 #include <ls-std/io/section-pair/validator/SectionPairSectionValidator.hpp>
 #include <ls-std/io/section-pair/validator/SectionPairValueValidator.hpp>
 

+ 0 - 11
source/ls-std/io/section-pair/serialization/SerializableSectionPairSection.cpp

@@ -8,12 +8,10 @@
 * */
 
 #include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
-#include <ls-std/core/exception/IllegalArgumentException.hpp>
 #include <ls-std/io/section-pair/evaluator/SectionPairSectionArgumentEvaluator.hpp>
 #include <ls-std/io/section-pair/model/SectionPairRow.hpp>
 #include <ls-std/io/section-pair/model/SectionPairSection.hpp>
 #include <ls-std/io/section-pair/serialization/SerializableSectionPairSection.hpp>
-#include <ls-std/io/section-pair/validator/SectionPairSectionIdUnmarshalValidator.hpp>
 
 ls::std::io::SerializableSectionPairSection::SerializableSectionPairSection(const ls::std::io::SerializableSectionPairParameter &_parameter) : ls::std::core::Class("SerializableSectionPairSection")
 {
@@ -46,14 +44,6 @@ void ls::std::io::SerializableSectionPairSection::unmarshal(const ls::std::core:
   this->_unmarshalRows(_data.substr(sectionHeaderSize));
 }
 
-void ls::std::io::SerializableSectionPairSection::_checkSectionHeader(const ls::std::core::type::byte_field &_sectionHeader)
-{
-  if (!ls::std::io::SectionPairSectionIdUnmarshalValidator{_sectionHeader, this->parameter.getNewLine()}.isValid())
-  {
-    throw ls::std::core::IllegalArgumentException{"serialized section header is not valid!"};
-  }
-}
-
 ls::std::core::type::byte_field ls::std::io::SerializableSectionPairSection::_collectSectionRow(const ls::std::core::type::byte_field &_currentRows, ls::std::io::SectionPairRowEnumType &_type)
 {
   ::std::string row{};
@@ -213,7 +203,6 @@ void ls::std::io::SerializableSectionPairSection::_unmarshalRows(const ls::std::
 size_t ls::std::io::SerializableSectionPairSection::_unmarshalSectionHeader(const ls::std::core::type::byte_field &_data)
 {
   ls::std::core::type::byte_field sectionHeader = this->_getSectionHeader(_data);
-  this->_checkSectionHeader(sectionHeader);
   ::std::dynamic_pointer_cast<ls::std::io::SectionPairSection>(this->parameter.getValue())->setSectionId(ls::std::io::SerializableSectionPairSection::_getSectionId(sectionHeader));
 
   return sectionHeader.size();

+ 0 - 52
source/ls-std/io/section-pair/validator/SectionPairSectionIdUnmarshalValidator.cpp

@@ -1,52 +0,0 @@
-/*
-* Author:          Patrick-Christopher Mattulat
-* Company:         Lynar Studios
-* E-Mail:          webmaster@lynarstudios.com
-* Created:         2023-02-14
-* Changed:         2023-02-17
-*
-* */
-
-#include <ls-std/io/NewLine.hpp>
-#include <ls-std/io/section-pair/validator/SectionPairIdentifierValidator.hpp>
-#include <ls-std/io/section-pair/validator/SectionPairSectionIdUnmarshalValidator.hpp>
-
-ls::std::io::SectionPairSectionIdUnmarshalValidator::SectionPairSectionIdUnmarshalValidator(ls::std::core::type::byte_field _data, ::std::string _newLine) : ls::std::core::Class("SectionPairSectionIdUnmarshalValidator"), data(::std::move(_data)), newLine(::std::move(_newLine))
-{}
-
-ls::std::io::SectionPairSectionIdUnmarshalValidator::~SectionPairSectionIdUnmarshalValidator() = default;
-
-bool ls::std::io::SectionPairSectionIdUnmarshalValidator::isValid()
-{
-  bool isValidSectionId = this->data.rfind(this->newLine, 0) == 0;
-  isValidSectionId = isValidSectionId && this->data.rfind(this->newLine + this->newLine) == (this->data.size() - 2 * this->newLine.size());
-
-  if (isValidSectionId)
-  {
-    isValidSectionId = ls::std::io::SectionPairSectionIdUnmarshalValidator::_isValidSection(ls::std::io::SectionPairSectionIdUnmarshalValidator::_trimStartAndEnd(this->data, this->newLine, this->newLine + this->newLine));
-  }
-
-  return isValidSectionId;
-}
-
-bool ls::std::io::SectionPairSectionIdUnmarshalValidator::_isValidSection(const ls::std::core::type::byte_field &_bracketsNotation)
-{
-  bool isValidBracketsNotation = _bracketsNotation.rfind('[', 0) == 0;
-  isValidBracketsNotation = isValidBracketsNotation && _bracketsNotation.rfind(']') == (_bracketsNotation.size() - 1);
-
-  if (isValidBracketsNotation)
-  {
-    ls::std::core::type::byte_field identifier = ls::std::io::SectionPairSectionIdUnmarshalValidator::_trimStartAndEnd(_bracketsNotation, "[", "]");
-    isValidBracketsNotation = ls::std::io::SectionPairIdentifierValidator{identifier}.isValid();
-  }
-
-  return isValidBracketsNotation;
-}
-
-ls::std::core::type::byte_field ls::std::io::SectionPairSectionIdUnmarshalValidator::_trimStartAndEnd(const ls::std::core::type::byte_field &_trimmedWord, const ls::std::core::type::byte_field &_beginningTrimWord, const ls::std::core::type::byte_field &_endingTrimWord)
-{
-  ls::std::core::type::byte_field trimmedWord = _trimmedWord.substr(_beginningTrimWord.size());
-  trimmedWord.erase(trimmedWord.end() - (uint32_t) _endingTrimWord.size(), trimmedWord.end());
-
-  return trimmedWord;
-}

+ 0 - 61
test/cases/io/section-pair/validator/SectionPairSectionIdUnmarshalValidatorTest.cpp

@@ -1,61 +0,0 @@
-/*
-* Author:          Patrick-Christopher Mattulat
-* Company:         Lynar Studios
-* E-Mail:          webmaster@lynarstudios.com
-* Created:         2023-02-14
-* Changed:         2023-02-17
-*
-* */
-
-#include <gtest/gtest.h>
-#include <ls-std/ls-std-core.hpp>
-#include <ls-std/ls-std-io.hpp>
-
-using namespace ls::std::core;
-using namespace ls::std::core::type;
-using namespace ls::std::io;
-using namespace ::std;
-
-namespace
-{
-  class SectionPairSectionIdUnmarshalValidatorTest : public ::testing::Test
-  {
-    protected:
-
-      SectionPairSectionIdUnmarshalValidatorTest() = default;
-      ~SectionPairSectionIdUnmarshalValidatorTest() override = default;
-
-      void SetUp() override
-      {}
-
-      void TearDown() override
-      {}
-  };
-
-  TEST_F(SectionPairSectionIdUnmarshalValidatorTest, getClassName)
-  {
-    ASSERT_STREQ("SectionPairSectionIdUnmarshalValidator", SectionPairSectionIdUnmarshalValidator("\n[general]\n", NewLine::get()).getClassName().c_str());
-  }
-
-  TEST_F(SectionPairSectionIdUnmarshalValidatorTest, isValid)
-  {
-    string newLine = NewLine::get();
-    byte_field generalSection = newLine + "[general]" + newLine + newLine;
-    byte_field localServerSection = newLine + "[local-server]" + newLine + newLine;
-
-    ASSERT_TRUE(SectionPairSectionIdUnmarshalValidator(generalSection, newLine).isValid());
-    ASSERT_TRUE(SectionPairSectionIdUnmarshalValidator(localServerSection, newLine).isValid());
-  }
-
-  TEST_F(SectionPairSectionIdUnmarshalValidatorTest, isValid_not_valid)
-  {
-    string newLine = NewLine::get();
-    byte_field generalSection = newLine + "[general]" + newLine;
-    byte_field localServerSection = newLine + "[local-server]";
-    byte_field position = newLine + "position" + newLine;
-
-    ASSERT_FALSE(SectionPairSectionIdUnmarshalValidator(generalSection, newLine).isValid());
-    ASSERT_FALSE(SectionPairSectionIdUnmarshalValidator(localServerSection, newLine).isValid());
-    ASSERT_FALSE(SectionPairSectionIdUnmarshalValidator(position, newLine).isValid());
-  }
-}