José solved this issue in his wide string classes user code by overloading the dereference operator to get a WSTRING ptr (which I thought was a clever use of the operator).
Here is a minimal implementation with only the relavant parts (from DWSTR, I think), using a dynamic memory allocation. Can be tried with or without the 'extends wstring' to show the differences and I've included the output in the listing.
Code: Select all
type T '' extends wstring
buffer as wstring ptr
declare constructor( byref s as const wstring )
declare destructor()
declare operator cast() byref as const wstring
end type
constructor T( byref s as const wstring )
buffer = callocate( (len(s) + 1) * sizeof(wstring) )
*buffer = s
end constructor
destructor T()
deallocate buffer
end destructor
operator T.cast() byref as const wstring
operator = *buffer
end operator
operator * (byref s as const T) as wstring ptr
operator = s.buffer
end operator
sub print_string( byref title as const string, byref x as const wstring, byval indent as integer = 0 )
print left( title & space(20), 20 ) & ": "; space( indent*(1+sizeof(wstring)*2) );
for i as integer = 0 to len(x) -1
print hex( x[i], sizeof(wstring)*2 ); " ";
next
print
end sub
dim x as T = !" \u3041\u3043\u3045\u3047\u3049 "
print_string( "x", x )
dim w as wstring * 50 = x
print_string( "w", w )
'' fbc wraps UDT's in a str() conversion for quirk string functions
print_string( "ltrim(x)", ltrim(x), 2 )
print_string( "rtrim(x)", rtrim(x) )
print_string( "trim(x)", trim(x), 2 )
'' double-deref gets the wstring data
print_string( "ltrim(**x)", ltrim(**x), 2 )
print_string( "rtrim(**x)", rtrim(**x) )
print_string( "trim(**x)", trim(**x), 2 )
/'
OUTPUT (without extends wstring):
x : 0020 0020 3041 3043 3045 3047 3049 0020 0020
w : 0020 0020 3041 3043 3045 3047 3049 0020 0020
ltrim(x) : 003F 003F 003F 003F 003F 0020 0020
rtrim(x) : 0020 0020 003F 003F 003F 003F 003F
trim(x) : 003F 003F 003F 003F 003F
ltrim(**x) : 3041 3043 3045 3047 3049 0020 0020
rtrim(**x) : 0020 0020 3041 3043 3045 3047 3049
trim(**x) : 3041 3043 3045 3047 3049
OUTPUT (with extends wstring):
x : 0020 0020 3041 3043 3045 3047 3049 0020 0020
w : 0020 0020 3041 3043 3045 3047 3049 0020 0020
ltrim(x) : 3041 3043 3045 3047 3049 0020 0020
rtrim(x) : 0020 0020 3041 3043 3045 3047 3049
trim(x) : 3041 3043 3045 3047 3049
ltrim(**x) : 3041 3043 3045 3047 3049 0020 0020
rtrim(**x) : 0020 0020 3041 3043 3045 3047 3049
trim(**x) : 3041 3043 3045 3047 3049
'/