Specific Procedures ASCII or Unicode

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Specific Procedures ASCII or Unicode

Post by IdeasVacuum »

I don't know if this request is even possible to invoke. What I would like to be able to do, within a project that is compiled as Unicode (default), is to declare one or more Procedures to be compiled as ASCII, which would mean all PB functions within the Procedure would give ASCII results.

For example, default result = 12, Ascii Procedure result = 6:

Code: Select all

StringByteLength("abcdef")
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Specific Procedures ASCII or Unicode

Post by STARGÅTE »

You have already the possibility to use the optional flag with:

Code: Select all

Debug StringByteLength("abcdef", #PB_Ascii)
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Specific Procedures ASCII or Unicode

Post by Thunder93 »

How I've interrupted this post yesterday. I thought he was asking for means to have the procedure run in ASCII mode under Unicode. Then the requirement to specify ASCII flags with various commands becomes nullified. :twisted:
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Specific Procedures ASCII or Unicode

Post by IdeasVacuum »

...Exactly so Thunder93. It would essentially mean 1 flag for all members of the Procedure.
e.g.

Code: Select all

Procedure_Ascii MyProc(sStringIn.s, sStringOut.s)
... This in my opinion will help to prevent tricky errors where the wrong flag or no flag has been added to any given function.

Also there are functions affected by compilation that do not have a format flag. AESDecoder() for example, where correct format is absolutely critical.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Specific Procedures ASCII or Unicode

Post by IdeasVacuum »

...It works the other way too. In the example below, Procedure WinLang() must be Unicode format. However, the app itself could be processing ASCII Data (including the decoding of license strings for example), and so other Procedures would need to be ASCII format.

Code: Select all

Enumeration
#WinLanguage
#CmbLanguage
#BtnOK
#Font14R
EndEnumeration

LoadFont(#Font14R, "Microsoft Sans Serif", 14, #PB_Font_HighQuality)

Procedure WinLang()
;#-----------------
Protected     iItem.i
Protected    iFlags.i = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
Protected Dim sLang.s(38)
sLang(00) = "Afrikaans"
sLang(01) = "Albanian"
sLang(02) = "العربية"
sLang(03) = "Беларускі"
sLang(04) = "বাঙ্গালী"
sLang(05) = "Bosanski"
sLang(06) = "Português (Brasil)"
sLang(07) = "Български"
sLang(08) = "中文简体"
sLang(09) = "中文繁体"
sLang(10) = "Hrvatski"
sLang(11) = "Čeština"
sLang(12) = "Dansk"
sLang(13) = "Nederlands"
sLang(14) = "English"
sLang(15) = "Eesti"
sLang(16) = "Pilipino"
sLang(17) = "Suomalainen"
sLang(18) = "Français"
sLang(19) = "Georgian"
sLang(20) = "Deutsch"
sLang(21) = "Ελληνικά"
sLang(22) = "עברית"
sLang(23) = "हिंदी"
sLang(24) = "Magyar"
sLang(25) = "Icelandic"
sLang(26) = "Bahasa Indonesia"
sLang(27) = "Italiano"
sLang(28) = "日本の"
sLang(29) = "Korean"
sLang(30) = "Latviski"
sLang(31) = "Lietuviu"
sLang(32) = "Македонски"
sLang(33) = "Melayu"
sLang(34) = "Malti"
sLang(35) = "Norsk"
sLang(36) = "فارسی"
sLang(37) = "Polski"
sLang(38) = "Português (Portugal)"


      If OpenWindow(#WinLanguage, 0, 0, 382, 42, "", iFlags)

             ComboBoxGadget(#CmbLanguage,  10, 6, 316, 32)
               ButtonGadget(#BtnOK,       334, 6,  42, 32, "OK")

             For iItem = 0 To 38

                    AddGadgetItem(#CmbLanguage, iItem, sLang(iItem))
             Next

              SetGadgetFont(#CmbLanguage, FontID(#Font14R))
             SetGadgetState(#CmbLanguage, 0)
      EndIf

EndProcedure

Procedure WaitForUser()
;#---------------------
Protected iEvent.i, iExit.i = #False

      Repeat

              iEvent = WaitWindowEvent(1)

              If(iEvent = #PB_Event_CloseWindow) : iExit = #True : EndIf
              If(iEvent = #PB_Event_Gadget) And (EventGadget() = #BtnOK) : iExit = #True : EndIf

      Until iExit = #True

EndProcedure

    WinLang()
WaitForUser()
End
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply