Browse Source

Remove "boxing" dependency from "io" module

Patrick-Christopher Mattulat 2 years ago
parent
commit
ec9b54ea55

+ 2 - 3
include/ls_std/io/kv/KvParseParameter.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-12-25
- * Changed:         2022-05-12
+ * Changed:         2022-05-13
  *
  * */
 
@@ -11,7 +11,6 @@
 #define LS_STD_KV_PARSE_DATA_HPP
 
 #include <string>
-#include <ls_std/boxing/String.hpp> // FIXME: remove "boxing" dependency from "io" module
 
 namespace ls
 {
@@ -22,7 +21,7 @@ namespace ls
       struct KvParseParameter
       {
         ::std::string::size_type index{};
-        ls::std::boxing::String line{};
+        ::std::string line{};
       };
     }
   }

+ 4 - 3
include/ls_std/io/kv/KvParser.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-12-25
- * Changed:         2022-05-12
+ * Changed:         2022-05-13
  *
  * */
 
@@ -38,9 +38,10 @@ namespace ls
           ::std::shared_ptr<ls::std::io::KvDocument> document{};
 
           void _assignDocument(const ::std::shared_ptr<ls::std::io::KvDocument> &_document);
-          static bool _lineHasPair(ls::std::io::KvParseParameter _parseParameter);
+          static bool _contains(const ::std::string &_text, const ::std::string &_searchText);
+          static bool _lineHasPair(const ls::std::io::KvParseParameter& _parseParameter);
           void _parse(const ls::std::core::type::byte_field &_data);
-          void _parsePair(ls::std::io::KvParseParameter _parseParameter);
+          void _parsePair(const ls::std::io::KvParseParameter& _parseParameter);
           static ls::std::io::KvParseParameter _readLine(const ls::std::core::type::byte_field &_data, ::std::string::size_type _index);
           static void _readLineWithUnixLineBreak(ls::std::io::KvParseParameter &_parseParameter);
           static void _readLineWithWindowsLineBreak(ls::std::io::KvParseParameter &_parseParameter);

+ 3 - 0
include/ls_std/io/logging/Logger.hpp

@@ -45,8 +45,11 @@ namespace ls
           ::std::shared_ptr<ls::std::core::IWriter> writer{};
 
           void _assignWriter(const ::std::shared_ptr<ls::std::core::IWriter> &_writer);
+          static ::std::string _buildCharacterChain(size_t _amount);
+          static ::std::string _createFillContent(const ::std::string &_text);
           static ::std::string _generateTimeString(tm *_localTime);
           void _log(const ls::std::core::type::byte *_data, const ls::std::io::LogLevel &_logLevel);
+          static ::std::string _padRight(const ::std::string& _text);
       };
     }
   }

+ 3 - 1
include/ls_std/io/xml/XmlParser.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-25
- * Changed:         2022-05-12
+ * Changed:         2022-05-13
  *
  * */
 
@@ -49,8 +49,10 @@ namespace ls
 
           void _analyze(const ls::std::core::type::byte_field &_data, ::std::string::size_type _index);
           void _assignDocument(const ::std::shared_ptr<ls::std::io::XmlDocument> &_document);
+          static bool _contains(const ::std::string &_text, const ::std::string &_searchText);
           static ::std::shared_ptr<ls::std::io::XmlDeclaration> _createDeclaration(const ::std::list<::std::pair<::std::string, ::std::string>> &_attributes);
           static ::std::shared_ptr<ls::std::io::XmlNode> _createNode(const ::std::list<::std::pair<::std::string, ::std::string>> &_attributes, const ::std::string &_name);
+          static bool _endsWith(const ::std::string &_text, const ::std::string &_ending);
           static ::std::pair<::std::string, ::std::string> _findAttribute(const ::std::list<::std::pair<::std::string, ::std::string>> &_attributes, const ::std::string &_name);
           static size_t _findAttributeEndPosition(const ls::std::core::type::byte_field &_data);
           static ls::std::core::type::byte_field _getNextTagString(const ls::std::core::type::byte_field &_data, ::std::string::size_type _index);

+ 19 - 14
source/ls_std/io/kv/KvParser.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-12-25
- * Changed:         2022-05-12
+ * Changed:         2022-05-13
  *
  * */
 
@@ -41,9 +41,14 @@ void ls::std::io::KvParser::_assignDocument(const ::std::shared_ptr<ls::std::io:
   this->document = _document;
 }
 
-bool ls::std::io::KvParser::_lineHasPair(ls::std::io::KvParseParameter _parseParameter)
+bool ls::std::io::KvParser::_contains(const ::std::string &_text, const ::std::string &_searchText)
 {
-  return _parseParameter.line.contains("=") && _parseParameter.line.contains(";");
+  return _text.find(_searchText) != ::std::string::npos;
+}
+
+bool ls::std::io::KvParser::_lineHasPair(const ls::std::io::KvParseParameter& _parseParameter)
+{
+  return ls::std::io::KvParser::_contains(_parseParameter.line, "=") && ls::std::io::KvParser::_contains(_parseParameter.line, ";");
 }
 
 void ls::std::io::KvParser::_parse(const ls::std::core::type::byte_field &_data)
@@ -56,13 +61,13 @@ void ls::std::io::KvParser::_parse(const ls::std::core::type::byte_field &_data)
   }
 }
 
-void ls::std::io::KvParser::_parsePair(ls::std::io::KvParseParameter _parseParameter)
+void ls::std::io::KvParser::_parsePair(const ls::std::io::KvParseParameter& _parseParameter)
 {
   if (ls::std::io::KvParser::_lineHasPair(_parseParameter))
   {
-    size_t equalSignPosition = _parseParameter.line.toString().find('=');
-    ls::std::core::type::kv_key key = _parseParameter.line.toString().substr(0, equalSignPosition);
-    ls::std::core::type::kv_value value = _parseParameter.line.toString().substr(equalSignPosition + 1);
+    size_t equalSignPosition = _parseParameter.line.find('=');
+    ls::std::core::type::kv_key key = _parseParameter.line.substr(0, equalSignPosition);
+    ls::std::core::type::kv_value value = _parseParameter.line.substr(equalSignPosition + 1);
     value = value.substr(0, value.find(';'));
 
     this->document->addPair(ls::std::io::KvPair{key, value});
@@ -74,30 +79,30 @@ ls::std::io::KvParseParameter ls::std::io::KvParser::_readLine(const ls::std::co
   ls::std::io::KvParseParameter parseParameter{};
   parseParameter.line = _data.substr(_index);
 
-  if (parseParameter.line.contains(ls::std::io::NewLine::getWindowsNewLine()))
+  if (ls::std::io::KvParser::_contains(parseParameter.line, ls::std::io::NewLine::getWindowsNewLine()))
   {
     ls::std::io::KvParser::_readLineWithWindowsLineBreak(parseParameter);
   }
   else
   {
-    if (parseParameter.line.contains(ls::std::io::NewLine::getUnixNewLine()))
+    if (ls::std::io::KvParser::_contains(parseParameter.line, ls::std::io::NewLine::getUnixNewLine()))
     {
       ls::std::io::KvParser::_readLineWithUnixLineBreak(parseParameter);
     }
   }
 
-  parseParameter.index = _index + parseParameter.line.toString().size();
+  parseParameter.index = _index + parseParameter.line.size();
   return parseParameter;
 }
 
 void ls::std::io::KvParser::_readLineWithUnixLineBreak(ls::std::io::KvParseParameter &_parseParameter)
 {
-  size_t newLinePosition = _parseParameter.line.toString().find(ls::std::io::NewLine::getUnixNewLine());
-  _parseParameter.line = _parseParameter.line.toString().substr(0, newLinePosition);
+  size_t newLinePosition = _parseParameter.line.find(ls::std::io::NewLine::getUnixNewLine());
+  _parseParameter.line = _parseParameter.line.substr(0, newLinePosition);
 }
 
 void ls::std::io::KvParser::_readLineWithWindowsLineBreak(ls::std::io::KvParseParameter &_parseParameter)
 {
-  size_t newLinePosition = _parseParameter.line.toString().find(ls::std::io::NewLine::getWindowsNewLine());
-  _parseParameter.line = _parseParameter.line.toString().substr(0, newLinePosition + 1);
+  size_t newLinePosition = _parseParameter.line.find(ls::std::io::NewLine::getWindowsNewLine());
+  _parseParameter.line = _parseParameter.line.substr(0, newLinePosition + 1);
 }

+ 33 - 2
source/ls_std/io/logging/Logger.cpp

@@ -11,7 +11,6 @@
 #include <ctime>
 #include <iomanip>
 #include <ls_std/io/NewLine.hpp>
-#include <ls_std/boxing/String.hpp> // FIXME: remove "boxing" dependency from "io" module
 #include <ls_std/core/exception/IllegalArgumentException.hpp>
 
 ls::std::io::Logger::Logger(const ::std::shared_ptr<ls::std::core::IWriter> &_writer)
@@ -89,6 +88,32 @@ void ls::std::io::Logger::_assignWriter(const ::std::shared_ptr<ls::std::core::I
   this->writer = _writer;
 }
 
+::std::string ls::std::io::Logger::_buildCharacterChain(size_t _amount)
+{
+  ::std::string fillContent{};
+
+  for (size_t iteration{}; iteration < _amount; iteration++)
+  {
+    fillContent += ' ';
+  }
+
+  return fillContent;
+}
+
+std::string ls::std::io::Logger::_createFillContent(const ::std::string &_text)
+{
+  size_t padSize = 10;
+  size_t fillSize = _text.size() > padSize ? 0 : padSize - _text.size();
+  ::std::string fillContent{};
+
+  if (fillSize > 0)
+  {
+    fillContent = ls::std::io::Logger::_buildCharacterChain(fillSize);
+  }
+
+  return fillContent;
+}
+
 ::std::string ls::std::io::Logger::_generateTimeString(tm *_localTime)
 {
   ::std::stringstream _stream{};
@@ -102,6 +127,12 @@ void ls::std::io::Logger::_log(const ls::std::core::type::byte *_data, const ls:
   time_t timestamp = ::std::time(nullptr);
   tm *localTime = ::std::localtime(&timestamp);
 
-  ::std::string message = "[" + ls::std::io::Logger::_generateTimeString(localTime) + "] " + ls::std::boxing::String{_logLevel.toString() + ":"}.padRight(10, ' ') + ::std::string(_data) + ls::std::io::NewLine::getUnixNewLine();
+  ::std::string logLevelString = ls::std::io::Logger::_padRight(::std::string{_logLevel.toString() + ":"});
+  ::std::string message = "[" + ls::std::io::Logger::_generateTimeString(localTime) + "] " + logLevelString + ::std::string(_data) + ls::std::io::NewLine::getUnixNewLine();
   this->writer->write(message);
 }
+
+::std::string ls::std::io::Logger::_padRight(const ::std::string& _text)
+{
+  return _text + ls::std::io::Logger::_createFillContent(_text);
+}

+ 21 - 12
source/ls_std/io/xml/XmlParser.cpp

@@ -3,13 +3,12 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-26
- * Changed:         2022-05-12
+ * Changed:         2022-05-13
  *
  * */
 
 #include <ls_std/io/xml/XmlParser.hpp>
 #include <ls_std/core/exception/IllegalArgumentException.hpp>
-#include <ls_std/boxing/String.hpp> // FIXME: remove "boxing" dependency from "io" module
 
 ls::std::io::XmlParser::XmlParser(const ::std::shared_ptr<ls::std::io::XmlDocument> &_document) : ls::std::core::Class("XmlParser")
 {
@@ -62,6 +61,11 @@ void ls::std::io::XmlParser::_assignDocument(const ::std::shared_ptr<ls::std::io
   this->document = _document;
 }
 
+bool ls::std::io::XmlParser::_contains(const ::std::string &_text, const ::std::string &_searchText)
+{
+  return _text.find(_searchText) != ::std::string::npos;
+}
+
 ::std::shared_ptr<ls::std::io::XmlDeclaration> ls::std::io::XmlParser::_createDeclaration(const ::std::list<::std::pair<::std::string, ::std::string>> &_attributes)
 {
   ::std::shared_ptr<ls::std::io::XmlDeclaration> declaration = ::std::make_shared<ls::std::io::XmlDeclaration>("1.0");
@@ -94,7 +98,7 @@ void ls::std::io::XmlParser::_assignDocument(const ::std::shared_ptr<ls::std::io
   ::std::shared_ptr<ls::std::io::XmlNode> node = ::std::make_shared<ls::std::io::XmlNode>(_name);
   ::std::shared_ptr<ls::std::io::XmlAttribute> attribute{};
 
-  for (const auto &parsedAttribute : _attributes)
+  for (const auto &parsedAttribute: _attributes)
   {
     attribute = ::std::make_shared<ls::std::io::XmlAttribute>(parsedAttribute.first);
     attribute->setValue(parsedAttribute.second);
@@ -104,11 +108,16 @@ void ls::std::io::XmlParser::_assignDocument(const ::std::shared_ptr<ls::std::io
   return node;
 }
 
+bool ls::std::io::XmlParser::_endsWith(const ::std::string &_text, const ::std::string &_ending)
+{
+  return _text.rfind(_ending) == (_text.size() - _ending.size());
+}
+
 ::std::pair<::std::string, ::std::string> ls::std::io::XmlParser::_findAttribute(const ::std::list<::std::pair<::std::string, ::std::string>> &_attributes, const ::std::string &_name)
 {
   ::std::pair<::std::string, ::std::string> attribute{};
 
-  for (const auto &currentAttribute : _attributes)
+  for (const auto &currentAttribute: _attributes)
   {
     if (currentAttribute.first == _name)
     {
@@ -125,7 +134,7 @@ size_t ls::std::io::XmlParser::_findAttributeEndPosition(const ls::std::core::ty
   ::std::string::size_type position = ::std::string::npos;
   ::std::string::size_type counter{};
 
-  for (char letter : _data)
+  for (char letter: _data)
   {
     if (letter == '"')
     {
@@ -189,9 +198,9 @@ void ls::std::io::XmlParser::_isValue(const ls::std::core::type::byte_field &_da
 
     if (isValue)
     {
-      ls::std::boxing::String value{_data.substr(_index, end)};
+      ::std::string value{_data.substr(_index, end)};
 
-      if (!value.contains("\n") && !value.contains("\r\n"))
+      if (!ls::std::io::XmlParser::_contains(value, "\n") && !ls::std::io::XmlParser::_contains(value, "\r\n"))
       {
         this->mode = XML_PARSE_MODE_VALUE;
       }
@@ -314,7 +323,7 @@ void ls::std::io::XmlParser::_parse(const ls::std::core::type::byte_field &_data
       position = _data.find(' ') + 1;
     } while (_data[position] == ' ');
 
-    if (_data.size() <= 3 && ls::std::boxing::String{_data}.endsWith(">"))
+    if (_data.size() <= 3 && ls::std::io::XmlParser::_endsWith(::std::string{_data}, ">"))
     {
       break;
     }
@@ -350,8 +359,8 @@ size_t ls::std::io::XmlParser::_parseDeclaration(const ls::std::core::type::byte
 
 size_t ls::std::io::XmlParser::_parseOpeningTag(const ls::std::core::type::byte_field &_data, ::std::string::size_type _index)
 {
-  ls::std::boxing::String tagString{ls::std::io::XmlParser::_getNextTagString(_data, _index)};
-  bool isValidTagString = !tagString.toString().empty();
+  ::std::string tagString{ls::std::io::XmlParser::_getNextTagString(_data, _index)};
+  bool isValidTagString = !tagString.empty();
   ls::std::io::XmlParseParameter singleParseParameter{};
 
   if (isValidTagString)
@@ -362,14 +371,14 @@ size_t ls::std::io::XmlParser::_parseOpeningTag(const ls::std::core::type::byte_
     singleParseParameter.node = node;
     this->parseParameters.push_back(singleParseParameter);
 
-    if (!tagString.endsWith("/>"))
+    if (!ls::std::io::XmlParser::_endsWith(tagString, "/>"))
     {
       this->currentLevel += 1;
       this->_setMaxLevel();
     }
   }
 
-  return !isValidTagString ? _index : _index + (tagString.toString().size() - 1);
+  return !isValidTagString ? _index : _index + (tagString.size() - 1);
 }
 
 ls::std::core::type::byte_field ls::std::io::XmlParser::_parseTagName(const ls::std::core::type::byte_field &_data)

+ 1 - 2
source/ls_std/io/xml/XmlReader.cpp

@@ -3,14 +3,13 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-10-10
- * Changed:         2022-05-12
+ * Changed:         2022-05-13
  *
  * */
 
 #include <ls_std/io/xml/XmlReader.hpp>
 #include <ls_std/core/exception/IllegalArgumentException.hpp>
 #include <ls_std/io/FileReader.hpp>
-#include <ls_std/boxing/String.hpp> // FIXME: remove "boxing" dependency from "io" module
 #include <ls_std/io/xml/XmlParser.hpp>
 
 ls::std::io::XmlReader::XmlReader(const ::std::shared_ptr<ls::std::io::XmlDocument> &_document, const ::std::string &_absolutePath)