]> git.sur5r.net Git - cc65/commitdiff
Added SB_Compare
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 11 Jul 2004 11:13:10 +0000 (11:13 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 11 Jul 2004 11:13:10 +0000 (11:13 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@3153 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/common/strbuf.c
src/common/strbuf.h

index 0adf5a5c3bb1ba2f49c0d1033a403151e269c6fc..66c07b875d912f820483a261b77395d21661b2b8 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2001-2003 Ullrich von Bassewitz                                       */
+/* (C) 2001-2004 Ullrich von Bassewitz                                       */
 /*               Römerstrasse 52                                             */
 /*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
@@ -202,7 +202,7 @@ void SB_AppendChar (StrBuf* B, int C)
     if (NewLen > B->Allocated) {
        SB_Realloc (B, NewLen);
     }
-    B->Buf[B->Len] = (char) C;            
+    B->Buf[B->Len] = (char) C;
     B->Len = NewLen;
 }
 
@@ -302,3 +302,27 @@ void SB_Move (StrBuf* Target, StrBuf* Source)
 
 
 
+int SB_Compare (const StrBuf* S1, const StrBuf* S2)
+/* Do a lexical compare of S1 and S2. See strcmp for result codes. */
+{       
+    int Result;
+    if (S1->Len < S2->Len) {
+        Result = memcmp (S1->Buf, S2->Buf, S1->Len);
+        if (Result == 0) {
+            /* S1 considered lesser because it's shorter */
+            Result = -1;
+        }
+    } else if (S1->Len > S2->Len) {
+        Result = memcmp (S1->Buf, S2->Buf, S2->Len);
+        if (Result == 0) {
+            /* S2 considered lesser because it's shorter */
+            Result = 1;
+        }
+    } else {
+        Result = memcmp (S1->Buf, S2->Buf, S1->Len);
+    }
+    return Result;
+}
+
+
+
index a209f4e9e940d6c31dc19fb9c3503fdb1cd857a5..5d159cd5f91434b7f9d0751b1cc8fce7c030a68c 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2001-2003 Ullrich von Bassewitz                                       */
+/* (C) 2001-2004 Ullrich von Bassewitz                                       */
 /*               Römerstrasse 52                                             */
 /*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
@@ -343,6 +343,9 @@ void SB_Move (StrBuf* Target, StrBuf* Source);
  * contents of Target, and Source will be empty after the call.
  */
 
+int SB_Compare (const StrBuf* S1, const StrBuf* S2);
+/* Do a lexical compare of S1 and S2. See strcmp for result codes. */
+
 
 
 /* End of strbuf.h */