PixInsight Forum (historical)

Software Development => PCL and PJSR Development => Topic started by: mschuster on 2012 September 25 09:13:56

Title: PJSR view id filter?
Post by: mschuster on 2012 September 25 09:13:56
Never mind: I wrote a function to do this.

When PI open an image, PI uses its name as a mainView id, but filtered for invalid characters (no spaces, no leading digits, etc). I'd like to do this same filtering in PJSR when my script opens images. Is there a PJSR function that does this filtering?

Thanks,
Mike
Title: Re: PJSR view id filter?
Post by: bitli on 2012 September 25 23:12:55
Would you be kind enought to post it (I am lazy ...)
-- bitli
Title: Re: PJSR view id filter?
Post by: mschuster on 2012 September 26 08:58:04
Here is my attempt. For example something strange like l`~!@#$%^&()_-+= {}[];',ïnput.fit maps to l___nput.
-Mike

Code: [Select]
function filterViewId(id) {
   var fId = "";
   if (id.length == 0) {
      return "_";
   }
   var c = id.charAt(0);
   if ("0" <= c && c <= "9") {
      fId = fId + "_";
   }
   for (var i = 0; i != id.length; ++i) {
      c = id.charAt(i);
      fId = fId + (
         (("0" <= c && c <= "9") || ("a" <= c && c <= "z") || ("A" <= c && c <= "Z")) ? c : "_"
      );
      if (fId.length > 3 && fId.substring(fId.length - 4, fId.length) == "____") {
         fId = fId.substring(0, fId.length - 1);
      }
   }
   return fId;
}