Recent

Author Topic: widechar evalution question  (Read 2391 times)

quantumfoam

  • New Member
  • *
  • Posts: 23
widechar evalution question
« on: February 22, 2018, 01:45:39 am »
I have a variable txtChar of type pWideChar.
If txtChar points to char of value 65533 ($FFFD) which is a �
according to https://en.wikibooks.org/wiki/Unicode/Character_reference/F000-FFFF,
then this expression:

Code: Pascal  [Select][+][-]
  1. widechar(txtChar^) in [ widechar(':')..widechar('@')  ]

evaluates to true.

My guess was, (and I'd like it to behave so), that it evaluates to false, since
65533 is not in [58..64] range. Although normal question mark "?" - 63, is in the range.

Is there any FPC/Lazarus setting so it behaves normally?

ASerge

  • Hero Member
  • *****
  • Posts: 2212
Re: widechar evalution question
« Reply #1 on: February 22, 2018, 03:52:22 pm »
Code: Pascal  [Select][+][-]
  1. program Project1;
  2. {$APPTYPE CONSOLE}
  3. {$MODE OBJFPC}
  4.  
  5. uses SysUtils;
  6.  
  7. begin
  8.   Writeln('Does the set ":".."@" include');
  9.   Writeln('Halfwidth black square - ', BoolToStr(CharInSet(#$FFFD, [':'..'@']), 'Yes', 'No'));
  10.   Writeln('Question mark - ', BoolToStr(CharInSet('?', [':'..'@']), 'Yes', 'No'));
  11.   Readln;
  12. end.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: widechar evalution question
« Reply #2 on: February 23, 2018, 05:16:40 am »
Is there any FPC/Lazarus setting so it behaves normally?

Disregard this answer, check my next reply.

Try to typecast widechar to word:
Code: Pascal  [Select][+][-]
  1.   <Wrong code>  word(widechar(txtChar^)) in [word(widechar(':'))..word(widechar('@'))]
« Last Edit: February 23, 2018, 07:08:48 pm by engkin »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4458
  • I like bugs.
Re: widechar evalution question
« Reply #3 on: February 23, 2018, 08:22:10 am »
@Beardsley, you are writing nonsense in your first 2 posts. Are you a spammer?
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: widechar evalution question
« Reply #4 on: February 23, 2018, 07:10:16 pm »
Sets are limited to "ordinal type with a range between 0 and 255."
The compiler converts your widechar code points to chars silently!! Which turns $FFFD into 63, making it between [58..64] (58 & 64 also came from similar silent conversions).

I believe this deserve a hint/warning.

 

TinyPortal © 2005-2018