2
0

4 Коммиты 6a765f94e0 ... 513cba4c3d

Автор SHA1 Сообщение Дата
  Kolja Strohm 513cba4c3d fix uninitialized memory in regex expression parsing and correct problems with allowed character lists 6 месяцев назад
  Kolja Strohm 28e77ad6d2 fix BildschirmGröße did not return the correct size 6 месяцев назад
  Kolja Strohm e83a8a72ea add OutputDebugStringLoggingChannel 6 месяцев назад
  Kolja Strohm 93cd71e4c6 add stack datastructure 6 месяцев назад
7 измененных файлов с 207 добавлено и 25 удалено
  1. 58 9
      Framework Tests/Regex.cpp
  2. 14 2
      Logging.cpp
  3. 21 4
      Logging.h
  4. 1 1
      Punkt.cpp
  5. 4 4
      Regex.cpp
  6. 7 5
      Regex.h
  7. 102 0
      Stack.h

+ 58 - 9
Framework Tests/Regex.cpp

@@ -73,13 +73,13 @@ namespace FrameworkTests
         TEST_METHOD (MatchTest3)
         {
             auto parser = Framework::Regex::parse("(?:abc)*");
-            auto result = parser->match("_aabcabcc", (int)strlen(" aabcabcc")); 
+            auto result = parser->match("_aabcabcc", (int)strlen(" aabcabcc"));
             Assert::IsTrue(result->getEintragAnzahl() == 5,
                 L"Invalid result count while matching '_aabcabcc' against "
                 L"'(?:abc)*'");
-            auto* first = result->z(0); 
-            auto* second = result->z(1); 
-            auto* third = result->z(2); 
+            auto* first = result->z(0);
+            auto* second = result->z(1);
+            auto* third = result->z(2);
             auto* forth = result->z(3);
             auto* fifth = result->z(4);
             Assert::IsTrue(first->getStart() == 0 && first->getEnd() == 0,
@@ -127,8 +127,8 @@ namespace FrameworkTests
             auto result = parser->match("_aabcabcc", (int)strlen(" aabcabcc"));
             Assert::IsTrue(result->getEintragAnzahl() == 8,
                 L"Invalid result count while matching '_aabcabcc' against "
-                L"'(?:abc)*?'"); 
-            auto* _0 = result->z(0); 
+                L"'(?:abc)*?'");
+            auto* _0 = result->z(0);
             auto* _1 = result->z(1);
             auto* _2 = result->z(2);
             auto* _3 = result->z(3);
@@ -199,7 +199,8 @@ namespace FrameworkTests
         TEST_METHOD (MatchTest5)
         {
             auto parser = Framework::Regex::parse("(a|b)+");
-            auto result = parser->match("cabaccccbab", (int)strlen("cabaccccbab"));
+            auto result
+                = parser->match("cabaccccbab", (int)strlen("cabaccccbab"));
             Assert::IsTrue(result->getEintragAnzahl() == 2,
                 L"Invalid result count while matching 'cabaccccbab' against "
                 L"'a|b'");
@@ -236,8 +237,7 @@ namespace FrameworkTests
         TEST_METHOD (MatchTest6)
         {
             auto parser = Framework::Regex::parse("(?:^|c)ab");
-            auto result
-                = parser->match("abcabcasd", (int)strlen("abcabcasd"));
+            auto result = parser->match("abcabcasd", (int)strlen("abcabcasd"));
             Assert::IsTrue(result->getEintragAnzahl() == 2,
                 L"Invalid result count while matching 'abcabcasd' against "
                 L"'(?:^|c)ab'");
@@ -286,5 +286,54 @@ namespace FrameworkTests
             result->release();
             parser->release();
         }
+
+        TEST_METHOD (TestNumber0)
+        {
+            auto parser = Framework::Regex::parse("^[0-9]+$");
+            auto* results = parser->match("0", 1);
+            bool ok = results->getEintragAnzahl() == 1;
+            results->release();
+            parser->release();
+            Assert::IsTrue(
+                ok, L"no result found while matcging '0' against '^[0-9]+$'");
+        }
+
+        TEST_METHOD (TestNumber1)
+        {
+            auto parser = Framework::Regex::parse("^[0-9]+(\\.[0-9]+)?$");
+            auto* results = parser->match("0", 1);
+            bool ok = results->getEintragAnzahl() == 1;
+            results->release();
+            parser->release();
+            Assert::IsTrue(ok,
+                L"no result found while matcging '0' against "
+                L"'^[0-9]+(\\.[0-9]+)?$'");
+        }
+
+        TEST_METHOD (TestNumber2)
+        {
+            auto parser = Framework::Regex::parse(
+                "^[0-9]+(\\.[0-9]+)?([eE][+-]?[0-9]+)?$");
+            auto* results = parser->match("0", 1);
+            bool ok = results->getEintragAnzahl() == 1;
+            results->release();
+            parser->release();
+            Assert::IsTrue(ok,
+                L"no result found while matcging '0' against "
+                L"'^[0-9]+(\\.[0-9]+)?([eE][+-]?[0-9]+)?$'");
+        }
+
+        TEST_METHOD (TestNumber3)
+        {
+            auto parser = Framework::Regex::parse(
+                "^[0-9]+(\\.[0-9]+)?([eE][+-]?[0-9]+)?$");
+            auto* results = parser->match("1e-3", 1);
+            bool ok = results->getEintragAnzahl() == 1;
+            results->release();
+            parser->release();
+            Assert::IsTrue(ok,
+                L"no result found while matcging '1e-3' against "
+                L"'^[0-9]+(\\.[0-9]+)?([eE][+-]?[0-9]+)?$'");
+        }
     };
 } // namespace FrameworkTests

+ 14 - 2
Logging.cpp

@@ -562,7 +562,19 @@ Framework::Logging::CoutLoggingChannel::CoutLoggingChannel()
 
 void Framework::Logging::CoutLoggingChannel::writeMessage(const Text& msg) const
 {
-    std::cout << msg.getText();
+    std::cout << msg.getText() << std::endl;
+}
+
+Framework::Logging::OutputDebugStringLoggingChannel::
+    OutputDebugStringLoggingChannel()
+    : LoggingChannel()
+{}
+
+void Framework::Logging::OutputDebugStringLoggingChannel::writeMessage(
+    const Text& msg) const
+{
+    OutputDebugStringA(msg.getText());
+    OutputDebugStringA("\n");
 }
 
 Framework::Logging::ConsoleHandlerLoggingChannel::ConsoleHandlerLoggingChannel(
@@ -694,4 +706,4 @@ void Framework::Logging::LoggingHandler::log(
     {
         channel->writeMessage(message, level, location);
     }
-}
+}

+ 21 - 4
Logging.h

@@ -285,8 +285,27 @@ namespace Framework
              * writes a message to the std::cout.
              *
              * \param msg the message
-             * \param level the log level
-             * \param location the location of the call
+             */
+            DLLEXPORT virtual void writeMessage(const Text& msg) const override;
+        };
+
+        /**
+         * logs messages to OutputDebugString.
+         */
+        class OutputDebugStringLoggingChannel : public LoggingChannel
+        {
+        public:
+            /**
+             * creates a new cout logging channel.
+             *
+             */
+            DLLEXPORT OutputDebugStringLoggingChannel();
+
+        protected:
+            /**
+             * writes a message to OutputDebugString.
+             *
+             * \param msg the message
              */
             DLLEXPORT virtual void writeMessage(const Text& msg) const override;
         };
@@ -313,8 +332,6 @@ namespace Framework
              * writes a message to the given ConsoleHandler.
              *
              * \param msg the message
-             * \param level the log level
-             * \param location the location of the call
              */
             DLLEXPORT virtual void writeMessage(const Text& msg) const override;
         };

+ 1 - 1
Punkt.cpp

@@ -12,7 +12,7 @@ inline Punkt Framework::BildschirmGr
     int mId) // Gibt die Größe des Bildschirms zurück
 {
     Monitor m = getMonitor(mId);
-    return Punkt(m.x, m.y);
+    return Punkt(m.breite, m.height);
 }
 
 inline Punkt Framework::Bildschirmmitte(

+ 4 - 4
Regex.cpp

@@ -57,13 +57,13 @@ Automata<char>* parseCharacterList(Text* regex, RegexConfig& config)
         case '-':
             if (escaped || !minusValid)
             {
-                characterList += '-';
+                characterList += "-";
             }
             else if (minusValid)
             {
                 if (i == length - 1)
                 {
-                    characterList += '-';
+                    characterList += "-";
                 }
                 else
                 {
@@ -80,12 +80,12 @@ Automata<char>* parseCharacterList(Text* regex, RegexConfig& config)
                     }
                     for (unsigned char c = before; c <= after; c++)
                     {
-                        characterList += c;
+                        characterList.append((char)c);
                     }
                     i++;
                 }
-                break;
             }
+            break;
         default:
             {
                 if (escaped)

+ 7 - 5
Regex.h

@@ -28,7 +28,8 @@ namespace Framework
         public:
             Transition()
                 : conditionFunction(0),
-                  zTarget(0)
+                  zTarget(0),
+                  requiredFlags(0)
             {}
 
             Transition(std::function<bool(Data, int)> conditionFunction,
@@ -41,7 +42,8 @@ namespace Framework
 
             Transition(const Transition& other)
                 : conditionFunction(other.conditionFunction),
-                  zTarget(other.zTarget)
+                  zTarget(other.zTarget),
+                  requiredFlags(other.requiredFlags)
             {}
 
             bool test(Data value, int flags) const
@@ -326,12 +328,12 @@ namespace Framework
                 while (currentFrame)
                 {
                     if (currentFrame->getStrIndex() >= length)
-					{
-						flags |= Flags::END;
+                    {
+                        flags |= Flags::END;
                     }
                     else
                     {
-						flags &= ~Flags::END;
+                        flags &= ~Flags::END;
                     }
                     if (currentFrame->getStrIndex() == 0)
                     {

+ 102 - 0
Stack.h

@@ -0,0 +1,102 @@
+#pragma once
+
+#include "ReferenceCounter.h"
+
+namespace Framework
+{
+    template<class T> class Stack : public ReferenceCounter
+    {
+    private:
+        std::function<T()> nullSupplier;
+        T* data;
+        int size;
+        int capacity;
+
+    public:
+        Stack(std::function<T()> nullSupplier)
+            : ReferenceCounter(),
+              nullSupplier(nullSupplier),
+              data(0),
+              size(0),
+              capacity(0)
+        {}
+
+        Stack(T null)
+            : Stack([null]() { return null; })
+        {}
+
+        Stack()
+            : Stack([]() { return (T)0; })
+        {}
+
+        ~Stack()
+        {
+            if (data)
+            {
+                delete[] data;
+            }
+        }
+
+        void push(T element)
+        {
+            if (size == capacity)
+            {
+                int newCapacity
+                    = capacity == 0
+                        ? 1
+                        : capacity * 2; // new variable is needed to avoid false
+                                        // positive compiler warnings
+                T* newData = new T[newCapacity];
+                for (int i = 0; i < size; i++)
+                {
+                    newData[i] = data[i];
+                }
+                capacity = newCapacity;
+                if (data)
+                {
+                    delete[] data;
+                }
+                data = newData;
+            }
+            data[size++] = element;
+        }
+
+        T pop()
+        {
+            if (size == 0)
+            {
+                return nullSupplier();
+            }
+            return data[--size];
+        }
+
+        T peek()
+        {
+            if (size == 0)
+            {
+                return nullSupplier();
+            }
+            return data[size - 1];
+        }
+
+        void reset()
+        {
+            size = 0;
+        }
+
+        int getSize()
+        {
+            return size;
+        }
+
+        int getCapacity()
+        {
+            return capacity;
+        }
+
+        T* getData()
+        {
+            return data;
+        }
+    };
+} // namespace Framework