fxm wrote: ↑Mar 12, 2024 9:28
Perhaps a generalization due to the final padding with null characters on the right side of the old STRING*N (fbc version 1.10.0):
(to be removed in fbc version 1.20.0 ?)
Seems like something could be improved here and need to investigate what is going on in the rtlib:
- rtrim( string )
- rtrim( string, filter )
- rtrim( string, any filter )
Unless my test is wrong, none of these forms are able to trim *only* chr(32) or trim *only* chr(0) while retaining the other chr(0|32).
Code: Select all
function escapeChar( byval ch as ubyte ) as string
if( ch >= 33 andalso ch <= 126 ) then
return chr(ch)
end if
return str(ch)
end function
sub showChars( byval p as ubyte ptr, byval n as integer )
print "n="; right( space(2)+str(n), 2); ": "; escapeChar(p[0]);
for i as integer = 1 to n - 1
print ",";escapeChar(p[i]);
next
print
end sub
sub CheckRTRIM( byref s as string, byref filter as string )
dim r as string
print "STRING : ";
showChars( strptr(s), len(s) )
print "FILTER : ";
showChars( strptr(filter), len(filter) )
print "RTRIM( string ) : ";
r = rtrim( s )
showChars( strptr(r), len(r) )
print "RTRIM( string, filter ) : ";
r = rtrim( s, filter )
showChars( strptr(r), len(r) )
print "RTRIM( string, any filter ): ";
r = rtrim( s, any filter )
showChars( strptr(r), len(r) )
print
end sub
dim b as string = "abcd"
CheckRTRIM( b + chr(0,0,32,32), chr(0) )
CheckRTRIM( b + chr(32,32,0,0), chr(32) )
CheckRTRIM( b + chr(0,0,32,32), chr(0,32) )
CheckRTRIM( b + chr(32,32,0,0), chr(0,32) )
CheckRTRIM( b + chr(0,0,32,32), chr(32,0) )
CheckRTRIM( b + chr(32,32,0,0), chr(32,0) )
sleep