Author Topic: Using WSTRING crashes string concatenations.  (Read 3326 times)

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Guest
Re: Using WSTRING crashes string concatenations.
« Reply #15 on: May 27, 2019, 02:42:05 PM »
 Thanks charles, its good to hear it will make it in the next update! :)

:)

Brian Alvarez

  • Guest
Re: Using WSTRING crashes string concatenations.
« Reply #16 on: May 27, 2019, 02:47:43 PM »
This raises a new question... how do i compare an ansi string variable to a unicode string variable? how do i make the unicode to ansi conversion?

I ask because this example returns EQUAL...

Code: [Select]
FUNCTION CMPR(STRING »a, STRING »b) AS INT
   STRING a = »a
   STRING b = »b
   RETURN (a=b)
END FUNCTION

   WSTRING su
   STRING sa
   su = "compare 1"
   sa = "compare 2"
   IF CMPR(su, sa) THEN
      print "EQUAL"
   ELSE
      print "DIFFERENT"
   END IF
« Last Edit: May 27, 2019, 02:54:48 PM by Brian Alvarez »

Charles Pegge

  • Guest
Re: Using WSTRING crashes string concatenations.
« Reply #17 on: May 27, 2019, 10:31:37 PM »
Hi Brian,

Comparing different string types is a mine-field. So the best strategy is to assign to a matching type. Then use it for the comparison expression.

typeof(leftside) rightside 'dim a matching type
rightside=rightside_expression


Code: [Select]
string  s="abc"
wstring t="abc"
char    u="abc"
wchar   v="abc"

typeof(t) rs 'dim a matching type

'these will auto-convert
'rs=s
rs=u
'rs=v

if t=rs
  print "ok"
else
  print "nok"
endif


« Last Edit: May 27, 2019, 10:46:32 PM by Charles Pegge »

Brian Alvarez

  • Guest
Re: Using WSTRING crashes string concatenations.
« Reply #18 on: May 27, 2019, 10:48:34 PM »
I understand, no problem. I can handle comparisons and make them seamless.

 However, I would like you to take a look at this Charles:

Code: [Select]
FUNCTION CMPR(STRING »a, STRING »b) AS INT
   STRING a = »a
   STRING b = »b
   IF (a=b) THEN
      print "equal 1"
   ELSE
      print "different 1"
   END IF
   RETURN (a = b)
END FUNCTION

   STRING su
   STRING sa
   su = "compare2"
   sa = "compare3"
   IF CMPR(su, sa) THEN
      print "equal 2"
   ELSE
      print "different 2"
   END IF

This outputs:

Code: [Select]
different 1
equal 2

 I think the comparison is correct, but the return value is wrong...

Charles Pegge

  • Guest
Re: Using WSTRING crashes string concatenations.
« Reply #19 on: May 28, 2019, 12:36:59 AM »
Yes, there is a confusion between assignment and equality.

This fixes it:

return (a == b)

Code: [Select]
FUNCTION CMPR(STRING »a, STRING »b) AS INT
   STRING a = »a
   STRING b = »b
   IF (a=b) THEN
      print "equal 1"
   ELSE
      print "different 1"
   END IF
int c=(a==b)
print c
   return (a == b)
   'function = (a == b)
END FUNCTION

   STRING su
   STRING sa
   su = "compare3"
   sa = "compare3"
   IF CMPR(su, sa) THEN
      print "equal 2"
   ELSE
      print "different 2"
   END IF

You can see the difference more clearly here:

Code: [Select]
'assignments vs logical expressions
int a,b,c,d
c=2
d=2
a=(c=d)
b=(c==d)
print a ",  " b
« Last Edit: May 28, 2019, 12:57:54 AM by Charles Pegge »

Aurel

  • Guest
Re: Using WSTRING crashes string concatenations.
« Reply #20 on: May 28, 2019, 05:01:13 AM »
What kind of sign is this prefix of a  :o
I don't have such a symbol on my keyboard.
and really why complicate with ==  ::)

jack

  • Guest
Re: Using WSTRING crashes string concatenations.
« Reply #21 on: May 28, 2019, 08:46:40 AM »
in the case of OxygenBasic using == seems appropriate, because of the support C'ish syntax, which can come in handy when porting C code to O2

Brian Alvarez

  • Guest
Re: Using WSTRING crashes string concatenations.
« Reply #22 on: May 28, 2019, 09:03:24 AM »
What kind of sign is this prefix of a  :o
I don't have such a symbol on my keyboard.
and really why complicate with ==  ::)

 That is the idea, to add a symbol that is not in the keyboard. I thought that symbol was apropriate
because the parameters are being "passed". Oxygen does not have a full byval feature, so, one has to
add a manual copy in some cases, a copy that can be altered if necessary.

Although i think in this case is not necessary for editing the parameter, it is necessary to make conversion from unicode to ANSI.

 In the real code, you never have to touch the symbol, see the image attached.




Charles Pegge

  • Guest
Re: Using WSTRING crashes string concatenations.
« Reply #23 on: May 28, 2019, 10:22:28 AM »
After investigating this Assignment-versus-Equality problem, I will allow (a=b) to be an equality expression instead an assignment expression. This will now have the same behaviour as (a==b)

But we still have the Pascal-style assignment operator available (a := b)

There may be one or two eamples using assignment expressions like:

a=b=c=d

These will have to be changed to:

a = b := c := d

Brian Alvarez

  • Guest
Re: Using WSTRING crashes string concatenations.
« Reply #24 on: May 28, 2019, 10:28:53 AM »
Perfect! Thanks! :)

Charles Pegge

  • Guest
Re: Using WSTRING crashes string concatenations.
« Reply #25 on: May 28, 2019, 10:38:00 AM »
Speaking of Unicode, o2 required some small fixes to be able to read Unicode source-code files.
Unicode string literals will now be possible. Note the 'L' prefix before the quote mark for Unicode.


Code: [Select]
uses corewin
messageboxW 0, l"Γεια σου κόσμο",l"title",0

Charles Pegge

  • Guest
Re: Using WSTRING crashes string concatenations.
« Reply #26 on: May 29, 2019, 08:16:40 AM »
o2 will also support Unicode symbols:

Code: [Select]
double φ, ϕ, π

φ = (sqr(5)+1)/2
ϕ = (sqr(5)-1)/2
π = pi()

print φ chr(13) ϕ