SuperString relational operators
authorArjen Baart <arjen@andromeda.nl>
Mon, 15 Jun 2020 16:35:13 +0000 (18:35 +0200)
committerArjen Baart <arjen@andromeda.nl>
Mon, 15 Jun 2020 16:35:13 +0000 (18:35 +0200)
src/Integer.cpp
src/Integer.h
src/String.h
src/builtin.h
src/string.cpp
src/superstring.cpp
test/Makefile.am
test/superstring_cat.cpp
test/superstring_compare.cpp [new file with mode: 0644]

index e116478..751cf24 100644 (file)
@@ -25,9 +25,6 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
   Thanks to the creators of the algorithms.
 */
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
 #include <Integer.h>
 //#include <std.h>
 #include <ctype.h>
index 7ed5797..7955877 100644 (file)
@@ -18,9 +18,6 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
 #ifndef _Integer_h
-#ifdef __GNUG__
-#pragma interface
-#endif
 #define _Integer_h 1
 
 #include <iostream>
index 2fb6f18..bd66c53 100644 (file)
@@ -447,7 +447,44 @@ public:
    // Adding Strings and SuperStrings
 
    friend SuperString operator+(const SuperString&, const String&);
+   friend SuperString operator+(const String&, const SuperString&);
+   friend SuperString operator+(const SuperString&, const SuperString&);
    SuperString& operator+=(const String&);
+
+   /*
+    *   SuperString comparison tests
+    */
+
+   friend int operator==(const SuperString& x, const SuperString& y)
+   {
+      return x._ss == y._ss;
+   }
+
+   friend int operator!=(const SuperString& x, const SuperString& y)
+   {
+      return x._ss != y._ss;
+   }
+
+   friend int operator<=(const SuperString& x, const SuperString& y)
+   {
+      return x._ss <= y._ss;
+   }
+
+   friend int operator>=(const SuperString& x, const SuperString& y)
+   {
+      return x._ss >= y._ss;
+   }
+
+   friend int operator<(const SuperString& x, const SuperString& y)
+   {
+      return x._ss < y._ss;
+   }
+
+   friend int operator>(const SuperString& x, const SuperString& y)
+   {
+      return x._ss > y._ss;
+   }
+
 };
 
 #endif  /* STRING_H */
index 9600daf..ef68846 100644 (file)
@@ -23,9 +23,6 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
 
 #ifndef _builtin_h
-#ifdef __GNUG__
-#pragma interface
-#endif
 #define _builtin_h 1
 
 //#include <_G_config.h>
index 6ad0fd3..0659652 100644 (file)
 ********************************
 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
 **      CREATION DATE   : Nov 17, 1997
-**      LAST UPDATE     : Nov 30, 2003
-**      MODIFICATIONS   : 
+**      LAST UPDATE     : Jun 12, 2020
 **************************************************************************/
 
-/*****************************
-   $Log: string.cpp,v $
-   Revision 1.5  2007-05-04 13:55:18  arjen
-   Dynamically allocate more memory if the string buffer runs out of space when
-   reading a String object from an input stream.
-
-   Revision 1.4  2003/03/29 07:18:54  arjen
-   String constructor and assignment from char * are more robust fro NULL pointers.
-
-   Revision 1.3  2002/11/03 13:18:57  arjen
-   New functions - String::escape() and String::unescape()
-
-   Revision 1.2  2002/09/28 06:42:11  arjen
-   A few small bug fixes.
-
-   Revision 1.1  2002/07/25 08:01:27  arjen
-   First checkin, AXE release 0.2
-
-*****************************/
-
-static const char RCSID[] = "$Id: string.cpp,v 1.5 2007-05-04 13:55:18 arjen Exp $";
-
 #include <stdio.h>
 #include <ctype.h>
 #include "String.h"
index 5715ac9..6624470 100644 (file)
 
 // Addition operators
 
+SuperString operator+(const SuperString& sx, const SuperString& sy)
+{
+   SuperString sum;
+
+   return sum;
+}
+
 SuperString operator+(const SuperString& ss, const String& s)
 {
    SuperString SS(ss);
@@ -36,6 +43,13 @@ SuperString operator+(const SuperString& ss, const String& s)
    return SS;
 }
 
+SuperString operator+(const String& s, const SuperString& ss)
+{
+   SuperString sum;
+
+   return sum;
+}
+
 SuperString& SuperString::operator+=(const String& x)
 {
    _ss.push_back(x);
index 7313716..c5ce407 100644 (file)
@@ -4,7 +4,7 @@ AM_CPPFLAGS = -I../src
 LDADD = ../src/.libs/libACL.la
 check_PROGRAMS = string_assign string_basics string_compare string_cat string_convert string_modify \
                  string_shift string_substring string_regex \
-                 superstring_assign superstring_basics superstring_cat string_split_join \
+                 superstring_assign superstring_basics superstring_cat superstring_compare string_split_join \
                  date_assign date_parse date_compare date_arithmetic date_attributes date_check_today \
                  hour_assign hour_parse hour_compare hour_arithmetic hour_check_now \
                  utc_assign utc_parse utc_compare utc_arithmetic utc_convert \
@@ -22,10 +22,11 @@ string_shift_SOURCES       = string_shift.cpp
 string_substring_SOURCES   = string_substring.cpp
 string_regex_SOURCES       = string_regex.cpp
 
-superstring_assign_SOURCES  = superstring_assign.cpp
-superstring_basics_SOURCES  = superstring_basics.cpp
-superstring_cat_SOURCES     = superstring_cat.cpp
-string_split_join_SOURCES   = string_split_join.cpp
+superstring_assign_SOURCES      = superstring_assign.cpp
+superstring_basics_SOURCES      = superstring_basics.cpp
+superstring_cat_SOURCES         = superstring_cat.cpp
+superstring_compare_SOURCES     = superstring_compare.cpp
+string_split_join_SOURCES       = string_split_join.cpp
 
 date_assign_SOURCES        = date_assign.cpp
 date_parse_SOURCES         = date_parse.cpp
index ff16ae0..194154f 100644 (file)
@@ -23,7 +23,7 @@ void print_ss(SuperString ss)
 
 int main()
 {
-   // Add a String to a SuperString, + operator
+   // Add a String to a SuperString, + operator(SuperString, String)
 
    SuperString ss0;
 
@@ -53,6 +53,42 @@ int main()
    print_ss(ss2);
    std::cout << "\n";
 
+   // Add a String to a SuperString, + operator(String, SuperString)
+
+   SuperString ss4;
+
+   String s5("abc");
+   String s6("def");
+   SuperString ss5(s5);
+
+   ss4 = s6 + ss5;
+
+   std::cout << s6 << " + ";
+   print_ss(ss5);
+   std::cout << " = ";
+   print_ss(ss4);
+   std::cout << "\n";
+
+   // Add a SuperString  to a SuperString, + operator(SuperString, SuperString)
+   SuperString  ss7(2);
+   SuperString  ss8(2);
+   SuperString  ss9;
+
+   ss7[0] = "abc";
+   ss7[1] = "def";
+   ss8[0] = "uvw";
+   ss8[1] = "xyz";
+
+   ss9 = ss7 + ss8;
+
+   print_ss(ss7);
+   std::cout << " + ";
+   print_ss(ss8);
+   std::cout << " = ";
+   print_ss(ss9);
+   std::cout << "\n";
+
    return 0;
 }
 
diff --git a/test/superstring_compare.cpp b/test/superstring_compare.cpp
new file mode 100644 (file)
index 0000000..5de519b
--- /dev/null
@@ -0,0 +1,133 @@
+/*******************************************************
+ *  Unit test for the SuperString class
+ *
+ * test relational operators
+ ******************************************************
+ *
+ */
+
+#include "String.h"
+#include <assert.h>
+
+void print_ss(SuperString ss)
+{
+   std::cout << "[";
+   for (int i = 0; i < ~ss; i++)
+   {
+      if (i != 0)
+         std::cout << ",";
+      std::cout << "\"" << ss[i] << "\"";
+   }
+   std::cout << "]";
+}
+
+int main()
+{
+   String s1("abcdef");
+   String s2("abcdef");
+   String s3("vwuxyz");
+
+   SuperString ss1(s1);
+   SuperString ss2(s2);
+   SuperString ss3(s3);
+
+   print_ss(ss1);
+   std::cout << " == ";
+   print_ss(ss2);
+   std::cout << " = " << (ss1 == ss2)  << "\n";
+   assert((ss1 == ss2) == true);
+
+   print_ss(ss1);
+   std::cout << " == ";
+   print_ss(ss3);
+   std::cout << " = " << (ss1 == ss3)  << "\n";
+   assert((ss1 == ss3) == false);
+
+   print_ss(ss1);
+   std::cout << " != ";
+   print_ss(ss2);
+   std::cout << " = " << (ss1 != ss2)  << "\n";
+   assert((ss1 != ss2) == false);
+
+   print_ss(ss1);
+   std::cout << " != ";
+   print_ss(ss3);
+   std::cout << " = " << (ss1 != ss3)  << "\n";
+   assert((ss1 != ss3) == true);
+
+   print_ss(ss1);
+   std::cout << " < ";
+   print_ss(ss2);
+   std::cout << " = " << (ss1 < ss2)  << "\n";
+   assert((ss1 < ss2) == false);
+
+   print_ss(ss1);
+   std::cout << " < ";
+   print_ss(ss3);
+   std::cout << " = " << (ss1 < ss3)  << "\n";
+   assert((ss1 < ss3) == true);
+
+   print_ss(ss3);
+   std::cout << " < ";
+   print_ss(ss1);
+   std::cout << " = " << (ss3 < ss1)  << "\n";
+   assert((ss3 < ss1) == false);
+
+   print_ss(ss1);
+   std::cout << " > ";
+   print_ss(ss2);
+   std::cout << " = " << (ss1 > ss2)  << "\n";
+   assert((ss1 > ss2) == false);
+
+   print_ss(ss1);
+   std::cout << " > ";
+   print_ss(ss3);
+   std::cout << " = " << (ss1 > ss3)  << "\n";
+   assert((ss1 > ss3) == false);
+
+   print_ss(ss3);
+   std::cout << " > ";
+   print_ss(ss1);
+   std::cout << " = " << (ss3 > ss1)  << "\n";
+   assert((ss3 > ss1) == true);
+
+   print_ss(ss1);
+   std::cout << " <= ";
+   print_ss(ss2);
+   std::cout << " = " << (ss1 <= ss2)  << "\n";
+   assert((ss1 <= ss2) == true);
+
+   print_ss(ss1);
+   std::cout << " <= ";
+   print_ss(ss3);
+   std::cout << " = " << (ss1 <= ss3)  << "\n";
+   assert((ss1 <= ss3) == true);
+
+   print_ss(ss3);
+   std::cout << " <= ";
+   print_ss(ss1);
+   std::cout << " = " << (ss3 <= ss1)  << "\n";
+   assert((ss3 <= ss1) == false);
+
+   print_ss(ss1);
+   std::cout << " >= ";
+   print_ss(ss2);
+   std::cout << " = " << (ss1 >= ss2)  << "\n";
+   assert((ss1 >= ss2) == true);
+
+   print_ss(ss1);
+   std::cout << " >= ";
+   print_ss(ss3);
+   std::cout << " = " << (ss1 >= ss3)  << "\n";
+   assert((ss1 >= ss3) == false);
+
+   print_ss(ss3);
+   std::cout << " >= ";
+   print_ss(ss1);
+   std::cout << " = " << (ss3 >= ss1)  << "\n";
+   assert((ss3 >= ss1) == true);
+
+
+   return 0;
+}
+