Jump to content
Sign in to follow this  
sp0987

Unicode NBSP(u00A0) No-Break Space character for 64-bit

Recommended Posts

Hi,

 

I am trying to create a .JSON file in Delphi 11 64-bit. While writing sample data to .json file , the &nbsp character was weird in 64-bit.

In 32-bit version , it was like "u00A0" and when coming to 64-bit version it was like "u=<68" and sometimes "u3<78". 

When I parse this resulted json file in .JS files , it throws an error like "invalid JSON".  Attached are samples from 32-bit and 64-bit.

 

Please suggest.

32-bit.json

64-bit.json

Share this post


Link to post

A sample application that we can compile as a 64 and 32 bit would help us to help you. We can only suggest that you make improvements in your code.
 

Share this post


Link to post

Are added samples supposed to be valid json? Because they both are missing end. Which raises a question, how the json was generated.

Share this post


Link to post

It was just a part of json file, not the whole thing.

Share this post


Link to post

Am having issue with "u3<78" . Instead of "u1618", am getting "u3<78" in some areas. When we see the 32-bit , it was 'u00A0' all over. 

Share this post


Link to post
1 hour ago, Lajos Juhász said:

A sample application that we can compile as a 64 and 32 bit would help us to help you. We can only suggest that you make improvements in your code.
 

 

Share this post


Link to post
Posted (edited)

Attaching a sample project. The project will create a json file, which when we try to use in javascript reults in error "invalid Json".

 

can be run in bot 32-bit and 64-bit with few changes. The changes were mentioned in the respected .pas files as comments. 

 

TestJson.7z

Edited by sp0987

Share this post


Link to post
Posted (edited)
9 hours ago, sp0987 said:

Am sorry i didn't get you

In 64bit RAX does not contain the first parameter of your Int2Hex function, RCX does.  Looks like there are also other problems with the 64 bit ASM code like where the return value is stored: it should end up in RAX, 

 

Ref: Using Inline Assembly Code - RAD Studio (embarcadero.com)

Quote

The first four parameters to inline assembler functions are passed via RCX, RDX, R8, and R9 respectively, except for floating-point arguments which use XMMO, XMM1, XMM2, XMM3. The math coprocessor is not normally used from x64 code. Registers used for function parameters can be modified freely.

Ref: Assembly Procedures and Functions - RAD Studio (embarcadero.com)

Quote

64-bit

  • Values 8 bytes or less in size are return in RAX.
  • Real values are returned in XMM0.
  • Other types are returned by a reference whose pointer value resides in RAX whose memory is allocated by the calling routine.

 

Edited by Brian Evans

Share this post


Link to post

FWIW the assembly implementation of that function is pointless given you can do it in a way more readable way - also performance cannot be a reason given the following call to mem_write causes a temporary heap allocation to convert your hex_code variable into an AnsiString.

 

Quickly slapped together (anyone who wants to further optimize this - be my guest, i cba right now):

type
  hex_code = Array [1 .. 4] of AnsiChar;

function Int2Hex(c: Word): hex_code;
const
  HexChars: array[0..15] of AnsiChar = '0123456789ABCDEF';
var
  i: NativeUInt;
begin
  i := c;
  Result[4] := HexChars[i and $0F];
  i := i shr 4;
  Result[3] := HexChars[i and $0F];
  i := i shr 4;
  Result[2] := HexChars[i and $0F];
  i := i shr 4;
  Result[1] := HexChars[i and $0F];
end;

and then instead of mem_write with AnsiString as the first argument use one that writes 4 bytes at once.

  • Like 1

Share this post


Link to post
Quote

CBA is an acronym that means can't be arsed, meaning, essentially, that a person can't be bothered to find the energy or willingness to do something. It's used in England, Australia, and New Zealand more than it is in the US. Arse is a British slang version of ass.

 

  • Haha 1

Share this post


Link to post
if S[I] in [WideChar(' ') .. WideChar('~')] Then
  mem_char(AnsiChar(S[I]), Buf)
else
Begin
  mem_char('\', Buf);
  mem_char('u', Buf);
  mem_write(IntToHex(ord(S[I]),4), Buf);
end;

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×