Community discussions

MikroTik App
 
User avatar
Sertik
Member
Member
Topic Author
Posts: 435
Joined: Fri Sep 25, 2020 3:30 pm
Location: Russia, Moscow

function convert UnicodeToURL

Sat Oct 14, 2023 7:55 pm

Our one Russian forum member wrote this recoding function. I can’t understand whether Rex already had one like this or not?
:global fUnicodeToURL
:if (!any $fUnicodeToURL) do={ :global fUnicodeToURL do={
  :local Ubytes [:tonum $1]
  :local EscapeStr ""
  :local HighByte
  :local LowByte
  :local firstList {1088;1089;1090;1091;1092;1093;1094;1095;1096;1097;1098;1099;1100;1101;1102;1103}
  :if ([:typeof [:find $firstList "$Ubytes"]] != "nil") do={
    #for lower
    :set HighByte (0xD1 | (($Ubytes - 0x0430 + 0xC0) >> 8))
    :set LowByte (0x80 | ($Ubytes & 0x3F))
    :put ("LowByte")
  } else={
     #for upper
    :set HighByte (0xD0 | (($Ubytes - 0x0410 + 0xC0) >> 8))
    :set LowByte (0x80 | ($Ubytes & 0xFF))
    :put ("HighByte")
  }
  :set EscapeStr ( "%".[:tostr [:pick "0123456789ABCDEF" ( $HighByte >> 4 & 0xF)]].[:tostr [:pick "0123456789ABCDEF" ( $HighByte & 0xF)]])
  :set EscapeStr ($EscapeStr . "%".[:tostr [:pick "0123456789ABCDEF" ( $LowByte >> 4 & 0xF)]].[:tostr [:pick "0123456789ABCDEF" ( $LowByte & 0xF)]])
  :return $EscapeStr
}}
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3606
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: function convert UnicodeToURL

Sat Oct 14, 2023 10:27 pm

IDK, but I learned something new. This is pretty cleaver to do a "#ifndef":
:if (!any $fUnicodeToURL)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12032
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: function convert UnicodeToURL

Mon Oct 16, 2023 2:37 am

UTF-8 or Unicode (UCS-2)? Are not the same...
Probably is UTF-8...

viewtopic.php?t=177551#p980163
Section "If the text is already on UTF-8..."
 
DyadyaGenya
Member Candidate
Member Candidate
Posts: 220
Joined: Mon May 08, 2023 10:34 pm

Re: function convert UnicodeToURL

Sun Nov 12, 2023 11:49 pm

Our one Russian forum member wrote this recoding function.
Isn't this Fly by any chance?

And one more clarification. As I understand it, this is for reading SMS. Can you show an example of use?

Who is online

Users browsing this forum: Google [Bot] and 10 guests