Recent

Author Topic: [SOLVED] Unicode versions of StrToInt  (Read 4748 times)

avk

  • Hero Member
  • *****
  • Posts: 752
[SOLVED] Unicode versions of StrToInt
« on: January 29, 2022, 08:45:11 am »
Hi!

Rtl doesn't seem to have versions of (Try)StrToInt() for unicodestring or did I just miss them?
« Last Edit: January 29, 2022, 06:49:11 pm by avk »

WooBean

  • Full Member
  • ***
  • Posts: 229
Re: Unicode versions of StrToInt
« Reply #1 on: January 29, 2022, 10:18:39 am »
Hi,
as valid strings for conversions in strToInt are like '12345', '-123', 'x0ffee', 'x12cc', '$FF' so automatic conversion unicodestring to ansistring does not causing problems itself.
BTW accepted format of hexadecimal string started from '$' is not documented (yet, already?).

WooBean
« Last Edit: January 29, 2022, 10:23:30 am by WooBean »
Platforms: Win7/64, Linux Mint Ulyssa/64

avk

  • Hero Member
  • *****
  • Posts: 752
Re: Unicode versions of StrToInt
« Reply #2 on: January 29, 2022, 11:07:14 am »
Thank you.
Transparent conversion of unicodestring to ansistring is certainly good, but it also increases the cost of conversion.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Unicode versions of StrToInt
« Reply #3 on: January 29, 2022, 01:32:59 pm »

BTW accepted format of hexadecimal string started from '$' is not documented (yet, already?).

WooBean

Hi!

It was documented in the 80s in the Turbo Pasal manuals.

Winni

AlexTP

  • Hero Member
  • *****
  • Posts: 2384
    • UVviewsoft
Re: Unicode versions of StrToInt
« Reply #4 on: January 29, 2022, 01:42:53 pm »
All number formats allowed for StrToInt + Val are now documented - https://www.freepascal.org/docs-html/rtl/sysutils/strtoint.html page is not _yet_ updated.

avk

  • Hero Member
  • *****
  • Posts: 752
Re: Unicode versions of StrToInt
« Reply #5 on: January 29, 2022, 02:14:28 pm »
use Ansistring where it matters?

Of course, this would be a clever approach, but a bit like "burying your head in the sand".

zamtmn

  • Hero Member
  • *****
  • Posts: 594
Re: Unicode versions of StrToInt
« Reply #6 on: January 29, 2022, 03:59:02 pm »
Where performance is important, unnecessary conversions are not needed.
avk I already suggested that you add unicode variant to your alternative))

avk

  • Hero Member
  • *****
  • Posts: 752
Re: Unicode versions of StrToInt
« Reply #7 on: January 29, 2022, 04:15:52 pm »
Well, you can see that I was not aware of the situation with StrToInt() for unicodestring, because I almost never use unicodestring.
I suppose the question can be marked as solved?

Seenkao

  • Hero Member
  • *****
  • Posts: 546
    • New ZenGL.
Re: [SOLVED] Unicode versions of StrToInt
« Reply #8 on: January 30, 2022, 04:07:08 pm »
Можно узнать, а в чём собственно проблема?
Первые 128 символов во всех кодировках одинаковы, я в чём-то ошибаюсь?
google translate:
May I know what is the actual problem?
The first 128 characters are the same in all encodings, am I wrong about something?
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

avk

  • Hero Member
  • *****
  • Posts: 752
Re: [SOLVED] Unicode versions of StrToInt
« Reply #9 on: January 31, 2022, 10:34:19 am »
...
May I know what is the actual problem?
...
Yes, of course, if we try something like this:
Code: Pascal  [Select][+][-]
  1. program test;
  2.  
  3. {$MODE OBJFPC}{$H+}
  4.  
  5. uses
  6.   SysUtils, DateUtils, ge_external_Utils;
  7.  
  8. var
  9.   a: TStringArray = nil;
  10.   ua: array of unicodestring = nil;
  11.  
  12. procedure GenAnsiData;
  13. var
  14.   I: Integer;
  15. const
  16.   TestSize = 1000;
  17. begin
  18.   SetLength(a, TestSize);
  19.   for I := 0 to High(a) do
  20.     a[I] := Random(High(Int64)).ToString;
  21. end;
  22.  
  23. procedure GenUniData;
  24. var
  25.   I: Integer;
  26. const
  27.   TestSize = 1000;
  28. begin
  29.   SetLength(ua, TestSize);
  30.   for I := 0 to High(ua) do
  31.     ua[I] := unicodestring(Random(High(Int64)).ToString);
  32. end;
  33.  
  34. procedure RunAscii;
  35. var
  36.   I, J: Integer;
  37.   Start: TTime;
  38.   Score: Int64;
  39.   v: QWord;
  40. begin
  41.   Start := Time;
  42.   for J := 1 to 30000 do
  43.     for I := 0 to High(a) do
  44.       sc_StrToQWord(a[I], v);
  45.   Score := MillisecondsBetween(Time, Start);
  46.   WriteLn('sc_StrToQWord ansi, score:       ', Score);
  47. end;
  48.  
  49. procedure RunUni;
  50. var
  51.   I, J: Integer;
  52.   Start: TTime;
  53.   Score: Int64;
  54.   v: QWord;
  55. begin
  56.   Start := Time;
  57.   for J := 1 to 30000 do
  58.     for I := 0 to High(ua) do
  59.       sc_StrToQWord(ua[I], v);
  60.   Score := MillisecondsBetween(Time, Start);
  61.   WriteLn('sc_StrToQWord unicode, score:    ', Score);
  62. end;
  63.  
  64. begin
  65.   Randomize;
  66.   GenAnsiData;
  67.   RunAscii;
  68.   WriteLn;
  69.  
  70.   GenUniData;
  71.   RunUni;
  72.   WriteLn;
  73.  
  74.   WriteLn('Press enter to exit...');
  75.   ReadLn;
  76. end.
  77.  

then we get something like this:
Code: Text  [Select][+][-]
  1. sc_StrToQWord ansi, score:       613
  2.  
  3. sc_StrToQWord unicode, score:    3853
  4.  
  5. Press enter to exit...
  6.  
« Last Edit: January 31, 2022, 11:00:07 am by avk »

Seenkao

  • Hero Member
  • *****
  • Posts: 546
    • New ZenGL.
Re: [SOLVED] Unicode versions of StrToInt
« Reply #10 on: January 31, 2022, 11:05:51 am »
понятно... очередная конвертация...
Пойти на ассемблере программировать? Хоть избегу данных конвертаций, когда меня это совсем не интересует.
google translate:
I see... another conversion...
To go on the assembler to program? At least I will avoid these conversions when it does not interest me at all. 8)
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

zamtmn

  • Hero Member
  • *****
  • Posts: 594
Re: [SOLVED] Unicode versions of StrToInt
« Reply #11 on: January 31, 2022, 11:35:07 am »
Seenkao
You didn't understand the essence of the problems. You don't need fast functions, VAL and StrToInt will completely cover all your needs

Seenkao

  • Hero Member
  • *****
  • Posts: 546
    • New ZenGL.
Re: [SOLVED] Unicode versions of StrToInt
« Reply #12 on: January 31, 2022, 12:00:23 pm »
Seenkao
You didn't understand the essence of the problems. You don't need fast functions, VAL and StrToInt will completely cover all your needs
Кто вам сказал, что в Val эта проблема решена? Вы тестировали Val c Unicode? С UTF8?
google translate:
Who told you that this problem is solved in Val? Have you tested Val with Unicode? With UTF8?
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

avk

  • Hero Member
  • *****
  • Posts: 752
Re: [SOLVED] Unicode versions of StrToInt
« Reply #13 on: January 31, 2022, 01:37:49 pm »
...
To go on the assembler to program? At least I will avoid these conversions when it does not interest me at all. 8)

Well, good luck then.

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: [SOLVED] Unicode versions of StrToInt
« Reply #14 on: January 31, 2022, 01:51:49 pm »
Well, good luck then.
Actually he deserves a couple of  >:D >:D >:D but I know you to be more polite... <btw, playing with your lgenerics.... 8-)>
Specialize a type, not a var.

 

TinyPortal © 2005-2018