See ChangeLog entry 19990514-20:10 EDT David G. Holm <dholm@jsd-llc.com>
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
19990514-20:10 EDT David G. Holm <dholm@jsd-llc.com>
|
||||
* source/rtl/strcmp.c
|
||||
- Added SET EXACT ON rules for null strings and trailing spaces.
|
||||
* tests/working/strings3.prg
|
||||
- Added tests for null strings and trailing spaces.
|
||||
|
||||
19990515-01:15 CET Eddie Runia
|
||||
* source/compiler/harbour.y
|
||||
#include again
|
||||
|
||||
@@ -12,10 +12,17 @@ int hb_itemStrCmp( PITEM pFirst, PITEM pSecond, BOOL bForceExact )
|
||||
char *szSecond = pSecond->value.szText;
|
||||
long lLenFirst = pFirst->wLength; /* TODO: change ITEM.wLength from WORD to long */
|
||||
long lLenSecond = pSecond->wLength; /* TODO: change ITEM.wLength from WORD to long */
|
||||
long lMinLen = lLenFirst < lLenSecond ? lLenFirst : lLenSecond;
|
||||
long lMinLen;
|
||||
long lCounter;
|
||||
int iRet = 0; /* Current status */
|
||||
|
||||
if (hb_set.HB_SET_EXACT && !bForceExact)
|
||||
{ /* SET EXACT ON and not using == */
|
||||
/* Don't include trailing spaces */
|
||||
while( lLenFirst > 0 && szFirst[ lLenFirst - 1 ] == ' ') lLenFirst--;
|
||||
while( lLenSecond > 0 && szSecond[ lLenSecond - 1 ] == ' ') lLenSecond--;
|
||||
}
|
||||
lMinLen = lLenFirst < lLenSecond ? lLenFirst : lLenSecond;
|
||||
if( lMinLen ) /* One of the strings is empty */
|
||||
{
|
||||
for( lCounter = 0; lCounter < lMinLen && !iRet; lCounter++ )
|
||||
@@ -28,19 +35,20 @@ int hb_itemStrCmp( PITEM pFirst, PITEM pSecond, BOOL bForceExact )
|
||||
szSecond++;
|
||||
}
|
||||
}
|
||||
/* printf ("\nhb_itemStrCmp: iRet = %d, lCounter = %ld, lLenFirst = %ld, lLenSecond = %ld", iRet, lCounter, lLenFirst, lLenSecond); */
|
||||
if( hb_set.HB_SET_EXACT || bForceExact || lLenSecond > lCounter )
|
||||
{ /* Force an exact comparison */
|
||||
if( !iRet && lLenFirst != lLenSecond )
|
||||
/* If length is different ! */
|
||||
iRet = (lLenFirst < lLenSecond) ? -1 : 1;
|
||||
iRet = (lLenFirst < lLenSecond) ? -1 : 1;
|
||||
}
|
||||
/* printf ("\n; hb_set.HB_SET_EXACT = %d, bForceExact = %d, iRet = %d.\n", hb_set.HB_SET_EXACT, bForceExact, iRet); */
|
||||
}
|
||||
else
|
||||
{
|
||||
if( lLenFirst != lLenSecond ) /* Both empty ? */
|
||||
iRet = (lLenFirst < lLenSecond) ? -1 : 1;
|
||||
if( hb_set.HB_SET_EXACT || bForceExact )
|
||||
iRet = (lLenFirst < lLenSecond) ? -1 : 1;
|
||||
else
|
||||
iRet = (lLenSecond == 0) ? 0 : -1;
|
||||
else
|
||||
iRet = 0; /* Both empty => Equal ! */
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ local cTest, nI, nJ, crlf := CHR(13)+CHR(10)
|
||||
OUTSTD (cStr)
|
||||
OUTSTD (UPPER (cStr))
|
||||
OUTSTD (LOWER (cStr))
|
||||
OUTSTD (CHR (13) + CHR (10))
|
||||
OUTSTD (crlf)
|
||||
OUTSTD (ASC (SUBSTR (cStr, 8)))
|
||||
OUTSTD (ASC (SUBSTR (cStr, 9)))
|
||||
OUTSTD (ASC (SUBSTR (cStr, 10)))
|
||||
@@ -76,45 +76,40 @@ local cTest, nI, nJ, crlf := CHR(13)+CHR(10)
|
||||
OUTSTD (crlf)
|
||||
|
||||
// Test the string comparison operators in the HVM.
|
||||
OUTSTD ("EXACT ")
|
||||
IF SET (_SET_EXACT)
|
||||
OUTSTD ("ON")
|
||||
ELSE
|
||||
OUTSTD ("OFF")
|
||||
ENDIF
|
||||
StrTest ("ABC", "ABC")
|
||||
StrTest ("ABC", "ABCD")
|
||||
StrTest ("ABCD", "ABC")
|
||||
StrTest ("ABC", "DEF")
|
||||
StrTest ("ABC", "DEFG")
|
||||
StrTest ("ABCD", "DEF")
|
||||
// Note: SET (_SET_EXACT) defaults to .F.
|
||||
TestStr ()
|
||||
OUTSTD (crlf)
|
||||
OUTSTD (crlf)
|
||||
OUTSTD ("EXACT ")
|
||||
|
||||
SET (_SET_EXACT, .T.)
|
||||
TestStr ()
|
||||
OUTSTD (crlf)
|
||||
return nil
|
||||
|
||||
function TestStr ()
|
||||
OUTSTD ("EXACT ")
|
||||
IF SET (_SET_EXACT)
|
||||
OUTSTD ("ON")
|
||||
ELSE
|
||||
OUTSTD ("OFF")
|
||||
ENDIF
|
||||
StrTest ("ABC", "")
|
||||
StrTest ("ABC", " ")
|
||||
StrTest ("ABC", "ABC")
|
||||
StrTest ("ABC", "ABCD")
|
||||
StrTest ("ABCD", "ABC")
|
||||
StrTest ("ABC", "ABC ")
|
||||
StrTest ("ABC", "DEF")
|
||||
StrTest ("ABC", "DEFG")
|
||||
StrTest ("ABCD", "DEF")
|
||||
OUTSTD (crlf)
|
||||
OUTSTD (crlf)
|
||||
return nil
|
||||
|
||||
function StrTest (Str1, Str2)
|
||||
|
||||
OUTSTD (CHR(13)+CHR(10)+CHR(10))
|
||||
OUTSTD ("'")
|
||||
OUTSTD (Str1)
|
||||
OUTSTD (", ")
|
||||
OUTSTD ("', '")
|
||||
OUTSTD (Str2)
|
||||
OUTSTD (" == ")
|
||||
OUTSTD ("' == ")
|
||||
OUTSTD (Str1 == Str2)
|
||||
OUTSTD (" = ")
|
||||
OUTSTD (Str1 = Str2)
|
||||
@@ -130,10 +125,11 @@ function StrTest (Str1, Str2)
|
||||
OUTSTD (Str1 >= Str2)
|
||||
|
||||
OUTSTD (CHR(13)+CHR(10))
|
||||
OUTSTD ("'")
|
||||
OUTSTD (Str2)
|
||||
OUTSTD (", ")
|
||||
OUTSTD ("', '")
|
||||
OUTSTD (Str1)
|
||||
OUTSTD (" == ")
|
||||
OUTSTD ("' == ")
|
||||
OUTSTD (Str2 == Str1)
|
||||
OUTSTD (" = ")
|
||||
OUTSTD (Str2 = Str1)
|
||||
|
||||
Reference in New Issue
Block a user