Added SB_Compare
git-svn-id: svn://svn.cc65.org/cc65/trunk@3153 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
38fe19a1a3
commit
725afdee94
2 changed files with 30 additions and 3 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Add table
Reference in a new issue