Recent

Author Topic: StrToInt in pure pascal.  (Read 20706 times)

AlexTP

  • Hero Member
  • *****
  • Posts: 2384
    • UVviewsoft
Re: StrToInt in pure pascal.
« Reply #45 on: January 19, 2022, 02:10:24 pm »
IMO it's not needed. New function names are not needed. When your unit is used, user already knows he wants the speed, and he uses your func name.
« Last Edit: January 19, 2022, 02:50:46 pm by Alextp »

Thaddy

  • Hero Member
  • *****
  • Posts: 14200
  • Probably until I exterminate Putin.
Re: StrToInt in pure pascal.
« Reply #46 on: January 19, 2022, 02:16:55 pm »
except for unit order that is. Do not overlook that.
Specialize a type, not a var.

Seenkao

  • Hero Member
  • *****
  • Posts: 546
    • New ZenGL.
Re: StrToInt in pure pascal.
« Reply #47 on: January 19, 2022, 02:48:33 pm »
Думаю вы правы.
Благодарю!

Eng:
I think you are right.
Thanks!
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

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

Seenkao

  • Hero Member
  • *****
  • Posts: 546
    • New ZenGL.
Re: StrToInt in pure pascal.
« Reply #48 on: January 19, 2022, 06:25:03 pm »
Но я не смог не предоставить версии для общего использования. :-[ По моему мнению, функции, предоставленные мной, не достаточно удобны для обычного пользователя. Потому я ввёл дополнительные функции, с которыми пользователю проще работать. В количестве 16. ::)
google translate:
But I couldn't help but provide versions for general use. :-[ In my opinion, the functions provided by me are not convenient enough for the average user. Therefore, I introduced additional functions that are easier for the user to work with. In the amount of 16. ::)

Code: Pascal  [Select][+][-]
  1. (* Rus: Ниже реализованы стандартные функции для перевода строк в число. Их
  2.  *      использование будет проще для большинства. Функции отмечены префиксом.
  3.  *      s_ - функции возвращают результат (если операция была неудачной, то
  4.  *      в результате вернётся ноль, но вы не узнаете, что операция была неудачной).
  5.  *      sc_ - результат функций удачная или не удачная была операция. Сам
  6.  *      конечный числовой результат считывайте в Value.
  7.  * Eng: The standard functions for converting strings to numbers are implemented
  8.  *      below. Their use will be easier for most. Functions are marked with a prefix.
  9.  *      s_ - functions return a result (if the operation was unsuccessful, the result
  10.  *      will be zero, but you will not know that the operation was unsuccessful).
  11.  *      sc_ - the result of the functions - the operation was successful or
  12.  *      unsuccessful. Read the final numerical result in Value.
  13.  *)
  14.  
  15. // Rus: Числа со знаком. Здесь нельзя использовать шестнадцатеричные, восьмеричные
  16. //      и двоичные числа.
  17. // Eng: Signed numbers. Hexadecimal, octal and binary numbers cannot be used here.
  18. function sc_StrToShortInt(const Str: String; out Value: ShortInt): Boolean;    // byte
  19. function s_StrToShortInt(const Str: String): ShortInt;                         // byte
  20. function sc_StrToSmallInt(const Str: String; out Value: SmallInt): Boolean;    // word
  21. function s_StrToSmallInt(const Str: String): SmallInt;                         // word
  22. function sc_StrToInt(const Str: String; out Value: Integer): Boolean;
  23. function s_StrToInt(const Str: String): Integer;
  24. function sc_StrToInt64(const Str: String; out Value: Int64): Boolean;
  25. function s_StrToInt64(const Str: String): Int64;
  26.  
  27. // Rus: Числа без знака. Эти функции могут использоваться и для шестнадцатеричныи
  28. //      и восьмеричных и двоичных чисел.
  29. // Eng: Numbers without a sign. These functions can be used for hexadecimal, octal
  30. //      and binary numbers as well.
  31. function sc_StrToByte(const Str: String; out Value: Byte): Boolean;
  32. function s_StrToByte(const Str: String): Byte;
  33. function sc_StrToWord(const Str: String; out Value: Word): Boolean;
  34. function s_StrToWord(const Str: String): Word;
  35. function sc_StrToLongWord(const Str: String; out Value: LongWord): Boolean;
  36. function s_StrToLongWord(const Str: String): LongWord;
  37. function sc_StrToQWord(const Str: String; out Value: QWord): Boolean;
  38. function s_StrToQWord(const Str: String): QWord;  

Все функции критичны к архитектуре и на 16-ти битной архитектуре не будет функций sc_StrToInt, s_StrToInt64, sc_StrToLongWord и подобных. Они исключаться (если вы не использовали define UP_CPU).
google translate:
All functions are critical to the architecture and there will be no sc_StrToInt, s_StrToInt64, sc_StrToLongWord and similar functions on a 16-bit architecture. They are excluded (unless you used define UP_CPU).
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

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

AlexTP

  • Hero Member
  • *****
  • Posts: 2384
    • UVviewsoft
Re: StrToInt in pure pascal.
« Reply #49 on: January 19, 2022, 06:28:52 pm »
Can you put this unit to GitHub? Please. I tried to download file from the 1st post (Yandex.disk) and got Yandex warning (it suggests to login).

Seenkao

  • Hero Member
  • *****
  • Posts: 546
    • New ZenGL.
Re: StrToInt in pure pascal.
« Reply #50 on: January 19, 2022, 06:34:38 pm »
Yes OK! I'll take care of it now.

until then I'll post it here.
« Last Edit: January 19, 2022, 11:59:35 pm by Seenkao »
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

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

Seenkao

  • Hero Member
  • *****
  • Posts: 546
    • New ZenGL.
Re: StrToInt in pure pascal.
« Reply #51 on: January 19, 2022, 11:56:49 pm »
GitHub: fast_StrToInt
Все старые версии, с маленькими глюками, последний код так же надо проверять. Надеюсь что устранил все ошибки, но это вряд ли. )))

google translate:
All old versions, with small glitches, the latest code also needs to be checked. I hope that eliminated all the errors, but it is unlikely. )))

Всем большое спасибо! И за не лестные отзывы тоже! Почти все они мне пригодились выявлять ошибки в коде.
google translate:
Thank you all! And for the bad reviews too! Almost all of them were useful to me to identify errors in the code. ;)
« Last Edit: January 20, 2022, 12:03:34 am by Seenkao »
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

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

Seenkao

  • Hero Member
  • *****
  • Posts: 546
    • New ZenGL.
Re: StrToInt in pure pascal.
« Reply #52 on: January 20, 2022, 07:58:19 am »
Мелочи, мелочи, мелочи...
Решил проблему с восьмеричной системой счисления (надеюсь всё, хотя кто его знает).
Добавил define ADD_FAST - он немного ускорит работу пользовательских функций, и немного увеличит код. На основные функции ни как не влияет.
Произвёл небольшую оптимизацию кода.
... пора бы уже заканчивать...  :)

google translate:
Little things, little things, little things...
I solved the problem with the octal number system (I hope everything, although who knows).
Added define ADD_FAST - it will slightly speed up the work of custom functions, and slightly increase the code. It does not affect the main functions in any way.
Made some code optimizations.
... it's time to finish already ... :)
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

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

Seenkao

  • Hero Member
  • *****
  • Posts: 546
    • New ZenGL.
Re: StrToInt in pure pascal.
« Reply #53 on: January 23, 2022, 12:05:19 am »
Теперь три основные функции удаляют ведущие нули.
Пользовательские функции тоже, но функции:
sc_StrToByte, s_StrToByte, sc_StrToWord, s_StrToWord, sc_StrToLongWord, s_StrToLongWord, sc_StrToQWord и s_StrToQWord - не должны содержать ведущие нули для десятичной системы счисления.
Google translate:
Now the three main functions remove leading zeros.
Custom functions too, but functions:
sc_StrToByte, s_StrToByte, sc_StrToWord, s_StrToWord, sc_StrToLongWord, s_StrToLongWord, sc_StrToQWord and s_StrToQWord - must not contain leading zeros for the decimal number system.
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

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

Seenkao

  • Hero Member
  • *****
  • Posts: 546
    • New ZenGL.
Re: StrToInt in pure pascal.
« Reply #54 on: January 31, 2022, 09:21:34 pm »
в файле конфигурации добавил возможность выбора "вида строки", на выбор:
Code: [Select]
{$DEFINE USE_STRING} // String
{$DEFINE USE_ANSISTRING} // AnsiString
{$DEFINE USE_UNICODESTRING} // UnicodeString
{$DEFINE USE_UTF8STRING} //UTF8String
Если в своём коде вы используете какой-то из видов строк, то лучше переключать дефайны. Иначе можно потерять в скорости из-за перевода строки из одного вида в другой.
Дефайны действуют в порядке приоритета сверху вниз. Нижние отключаться, если какой-то из верхних включен.

Так же мелкое исправление в коде, функция geStrToUInt (и все зависимые от неё) могли выдать ошибку при подсчёте.

Да, да, я знаю, что нужны функции для разных видов строк. Но лично я считаю, что неправильно прыгать с одного вида строк на другой.

google translate:
added the ability to select the "string type" in the configuration file, to choose from:
Code: [Select]
{$DEFINE USE_STRING} // String
{$DEFINE USE_ANSISTRING} // AnsiString
{$DEFINE USE_UNICODESTRING} // UnicodeString
{$DEFINE USE_UTF8STRING} //UTF8String
If in your code you use one of the types of strings, then it is better to switch defines. Otherwise, you can lose speed due to the translation of a string from one type to another.
Defines operate in order of priority from top to bottom. The lower ones will turn off if any of the upper ones is on.

Also a minor fix in the code, the function geStrToUInt (and all dependent on it) could give an error when calculating.

Yes, yes, I know that functions are needed for different kinds of strings. But personally, I think it's wrong to jump from one string type to another. ::)

-->fast_StrToInt download.<-- ;)
« Last Edit: January 31, 2022, 09:24:17 pm by Seenkao »
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

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

Seenkao

  • Hero Member
  • *****
  • Posts: 546
    • New ZenGL.
Re: StrToInt in pure pascal.
« Reply #55 on: February 03, 2022, 04:50:32 pm »
Основа была полностью переработана и теперь всё основывается на шести функциях (можно отключать по желанию три первых или три последних):
Eng: The base has been completely redesigned and now everything is based on six functions (you can turn off the first three or the last three at will):
Code: Pascal  [Select][+][-]
  1. function geCharToInt(const aStr: array of Char; out Value: maxIntVal; Size: maxIntVal = maxSize): Boolean;
  2. function geCharToUInt(const aStr: array of Char; out Value: maxUIntVal; Size: maxIntVal = maxSize): Boolean;
  3. function geHOBCharToUInt(const aStr: array of Char; out Value: maxUIntVal; Size: maxIntVal = maxSize): Boolean;
  4.  
  5. // for unicode
  6. function geWCharToInt(const aStr: array of WideChar; out Value: maxIntVal; Size: maxIntVal = maxSize): Boolean;
  7. function geWCharToUInt(const aStr: array of WideChar; out Value: maxUIntVal; Size: maxIntVal = maxSize): Boolean;
  8. function geWHOBCharToUInt(const aStr: array of WideChar; out Value: maxUIntVal; Size: maxIntVal = maxSize): Boolean;

Остальные функции дублированы для юникода. Описание на GitHub.
Протестировал насколько возможно, но лишними тесты ни когда не будут.  :)
Обратите внимание!!! Если вы работаете с UTF8String и вы не включите дефайн USE_UTF8STRING, вы можете не получить ни какого ускорения!!!
Максимальное ускорение работы кода, только в том случае если используемые типы совпадают.
google translate:
The remaining functions are duplicated for Unicode. Description at GitHub.
I tested as much as possible, but tests will never be superfluous. :)
Note!!! If you are working with UTF8String and you don't include USE_UTF8STRING define, you may not get any speedup!!!
The maximum speedup of the code, only if the used types match.
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

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

ASBzone

  • Hero Member
  • *****
  • Posts: 678
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: StrToInt in pure pascal.
« Reply #56 on: February 08, 2022, 04:46:44 pm »
except for unit order that is. Do not overlook that.


Please elaborate, Thaddy...

Are you talking about "uses" order? or something else?
-ASB: https://www.BrainWaveCC.com/

Lazarus v2.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)

Thaddy

  • Hero Member
  • *****
  • Posts: 14200
  • Probably until I exterminate Putin.
Re: StrToInt in pure pascal.
« Reply #57 on: February 08, 2022, 08:06:36 pm »
except for unit order that is. Do not overlook that.


Please elaborate, Thaddy...

Are you talking about "uses" order? or something else?
Uses order...
Specialize a type, not a var.

ASBzone

  • Hero Member
  • *****
  • Posts: 678
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: StrToInt in pure pascal.
« Reply #58 on: February 08, 2022, 11:21:20 pm »
-ASB: https://www.BrainWaveCC.com/

Lazarus v2.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)

 

TinyPortal © 2005-2018