Page 2 of 2

Re: Color filter for Directional Codes filename protection

Posted: 22 Oct 2016 10:01
by Marco
admin wrote:What about a variable for single characters in this format:

Code: Select all

<U+200E>
Looks ok to me!
So I could input (for example) a tab either as <tab> or <U+0009>, right?

Re: Color filter for Directional Codes filename protection

Posted: 22 Oct 2016 10:50
by admin
Yep! I will also allow longer sequences like this: <U+200E00090009>

Re: Color filter for Directional Codes filename protection

Posted: 22 Oct 2016 11:37
by Marco
Cool x2!
May I suggest a separator between sequences, like <U+200E,0009,0009>? (or whatever you prefer)
I think it makes easier to parse when you read it or if you want to programmatically create/disassemble such sequences, and also prevents misbehavior when longer codes are used (for example http://www.fileformat.info/info/unicode ... /index.htm ).

Re: Color filter for Directional Codes filename protection

Posted: 22 Oct 2016 13:19
by PeterH
At least allow such a separator - it really would help reading (and also writing) :tup:

Re: Color filter for Directional Codes filename protection

Posted: 22 Oct 2016 14:05
by admin
OK, good for reading and writing, but I can support only Unicode between -32,768 and +32,767, so no 5-digit hex codes.

Re: Color filter for Directional Codes filename protection

Posted: 22 Oct 2016 14:12
by Marco
admin wrote:OK, good for reading and writing, but I can support only Unicode between -32,768 and +32,767, so no 5-digit hex codes.
Oh yes I remember, well iirc there's an easy workaround for that, will post it asap...

EDIT:

Code: Select all

function surrogatepairexpander($codepoint) {

// Returns a representation in the form U+XXXX;U+YYYY (ie. using
// surrogate pairs) of a codepoint in the range U+10000 to U+10FFFF (see
// https://en.wikipedia.org/wiki/UTF-16#U.2B10000_to_U.2B10FFFF).
//
// Codepoint must be given in the form U+ZZZZZ, with ZZZZZ between
// 0x10000 and 0x10FFFF. If anything else is given as input, the
// function throws an error and aborts.
//
// Source of the code: http://www.russellcottrell.com/greek/utilities/SurrogatePairCalculator.htm
//
//   $codepoint   the codepoint to convert

 assert regexmatches("$codepoint", "U\+[0-9A-F]{5}") != "", "Invalid argument";
 $codepoint = eval("0x" . substr("$codepoint", 2));
 assert ($codepoint >= 0x10000) AND ($codepoint <= 0x10FFFF), "Invalid argument";

 $h_dec = ($codepoint - 0x10000) \ 0x400 + 0xD800;
 $l_dec = ($codepoint - 0x10000) % 0x400 + 0xDC00;

 $surrogatepair = "";

 foreach ($dec, "$h_dec,$l_dec", ",", "r") {

  $hex = "";

  while ("$dec" != "0") {

   $digit = $dec % 16;

   if ("$digit" Like "#") {break 0;}
   elseif ("$digit" == "10") {$digit = "A";} elseif ("$digit" == "11") {$digit = "B";} elseif ("$digit" == "12") {$digit = "C";}
   elseif ("$digit" == "13") {$digit = "D";} elseif ("$digit" == "14") {$digit = "E";} elseif ("$digit" == "15") {$digit = "F";};

   $hex = "$digit$hex";
   $dec = $dec \ 16;

  };

  $surrogatepair = "U+$hex;$surrogatepair";

 };

 $surrogatepair = trim("$surrogatepair", ";", "r");

 return "$surrogatepair";

}

Re: Color filter for Directional Codes filename protection

Posted: 23 Oct 2016 09:27
by admin
Thanks! Won't use it now, but might come in handy one day.

Re: Color filter for Directional Codes filename protection

Posted: 31 Oct 2016 12:44
by Jerry
I use this filter for all those codes plus, the first in the list is a pesky homologue I recently encountered.

Code: Select all

name:<U+0425>;<U+200E>;<U+200F>;<U+202A>;<U+202B>;<U+202C>;<U+202D>;<U+202E>

Re: Color filter for Directional Codes filename protection

Posted: 07 Feb 2025 15:25
by admin
admin wrote: 23 Oct 2016 09:27 Thanks! Won't use it now, but might come in handy one day.
Today :)