1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Suggestion for SafeChars plugin

Discussion in 'Plugins' started by dcantor, Jan 20, 2012.

  1. dcantor

    Joined:
    May 29, 2008
    Messages:
    507
    Likes Received:
    3
    Charles,

    Would you consider adding these two functions?

    @SAFECHECK[var] returns 1 if there are any characters in the translated range within the expansion of %var%, else 0.

    @UNSAFECHECK[var] returns 1 if there are any characters which WOULD BE translated to safe characters (by @SAFEENV[var], according to the current translation map) within the expansion of %var%, else 0.
     
  2. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    Actually a single function with 4 different values would be sufficient:
    0 if all characters are inherently safe;
    add 1 if untranslated unsafe characters are present;
    add 2 if translated unsafe characters are present.

    Value 1 would mean at least one unsafe character is present, and no unsafe character is translated.
    Value 2 would mean at least one unsafe character is present, and all unsafe characters are translated.
    Value 3 would mean at least two unsafe characters are present, and least one not translated, and at least one that is translated.
     
  3. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,287
    Likes Received:
    39
    Or as separate functions which provide counts?
     
  4. dcantor

    Joined:
    May 29, 2008
    Messages:
    507
    Likes Received:
    3
    Any of the above would be nice, Charles.

    But Steve, the presence of, let's say, an %_amp doesn't mean that it was translated from an unsafe ampersand, so I would reword your description with
    Value 2 would mean that at least one character from the translated safe range 0xFF00-0xFF3E (is that right?) is present.
    Value 3 would mean that there is at least one unsafe character present and at least one from the translated safe range (no matter how it got there).
     
  5. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,287
    Likes Received:
    39
    And -- just checking -- you want to pass the name of a variable or expression to be evaluated, a la @SAFEEXP, rather than just a string?
     
  6. dcantor

    Joined:
    May 29, 2008
    Messages:
    507
    Likes Received:
    3
    Yes, exactly. I was thinking of a single variable as in @SAFEENV, but an expression as in @SAFEEXP would be even more useful. (A version that would take an actual string wouldn't hurt, of course.)
     
  7. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,287
    Likes Received:
    39
    I've uploaded a new build. I haven't done much testing of the new functions, so let me know whether they work as you think they should.
     
  8. dcantor

    Joined:
    May 29, 2008
    Messages:
    507
    Likes Received:
    3
    Wow. The descriptions indicate exactly what I think is needed (for my usage), and they look general enough to satisfy any need. I'll be testing shortly.

    (later)
    Tested (in my one usage, so far). Perfect.

    Sample:

    > echo %@countsafe["&X%_amp"]
    1
    > echo %@countunsafe["&X%_amp"]
    3
    > echo %@len["&X%_amp"]
    5

    Thanks, Charles.
     

Share This Page