AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Validating Function and Variable Names
Goto page 1, 2  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
trik



Joined: 15 Jul 2007
Posts: 1320

PostPosted: Wed Feb 24, 2010 12:48 pm    Post subject: Validating Function and Variable Names Reply with quote

Code:
vfv(n) { ; vfv(n) : n - Name of function or variable : true if valid else false
   Return !RegExMatch(n, "^[^#$0-9@-\[\]_a-z-]{1,253}$")
}


Usage:

Code:
s := "#$0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]_abcdefghijklmnopqrstuvwxyz8593751111111111111111111111111111111111111111111111111111"
   
#$0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]_abcdefghijklmnopqrstuvwxyz8593751111111111111111111111111111111111111111111111111111(x) {
   Return x
}

%s% := s

MsgBox % vfv(s) . "`r`n" . %s%("abc")
MsgBox % vfv(v) . "`r`n" . %s%


As you can see, the parameters for a function name are equal to that of a variable.
_________________
Religion is false. >_>


Last edited by trik on Thu Feb 25, 2010 1:32 pm; edited 10 times in total
Back to top
View user's profile Send private message
Tuncay n-l-i mobile
Guest





PostPosted: Wed Feb 24, 2010 1:09 pm    Post subject: Reply with quote

good to have. I may use that at my project. But i do not like the name of the function. I prefer more "isValidName()".

At home i take a more detail look at this.
Back to top
trik



Joined: 15 Jul 2007
Posts: 1320

PostPosted: Wed Feb 24, 2010 1:11 pm    Post subject: Reply with quote

Tuncay n-l-i mobile wrote:
But i do not like the name of the function. I prefer more "isValidName()".


You are more than welcome to change the function name to whatever you wish, but I prefer ValidFunctionOrVariable(Name). I shortened to vfv(n).
_________________
Religion is false. >_>
Back to top
View user's profile Send private message
dR*
Guest





PostPosted: Wed Feb 24, 2010 3:32 pm    Post subject: Reply with quote

Code:
 vfv(n) { ; vfv(n) : n - Name of function or variable : true if valid else false
   Return !RegExMatch(n, "[^#0-\[\]-]{1,253}") ; Would it be faster without the logical-not and circumflex?
}

msgbox % vfv( "ya;:as" ) ? "YES" : "NO"


fails.

try using more precise needles such as \x30-\x39 and such

greets
dR
Back to top
trik



Joined: 15 Jul 2007
Posts: 1320

PostPosted: Wed Feb 24, 2010 3:38 pm    Post subject: Reply with quote

dR* wrote:
Code:
 vfv(n) { ; vfv(n) : n - Name of function or variable : true if valid else false
   Return !RegExMatch(n, "[^#0-\[\]-]{1,253}") ; Would it be faster without the logical-not and circumflex?
}

msgbox % vfv( "ya;:as" ) ? "YES" : "NO"


fails.

try using more precise needles such as \x30-\x39 and such

greets
dR


I thought I cut those characters out while I was making the RegEx.. I will fix it in a few minutes.


Edit: Updated function to the following:

Code:
vfv(n) { ; vfv(n) : n - Name of function or variable : true if valid else false
   Return !RegExMatch(n, "[^#0-9@-\[\]-]{1,253}")
}

_________________
Religion is false. >_>
Back to top
View user's profile Send private message
dr*
Guest





PostPosted: Wed Feb 24, 2010 4:28 pm    Post subject: Reply with quote

still fails
Code:
msgbox % vfv( "y{es}no" ) ? "YES" : "NO"
Back to top
trik



Joined: 15 Jul 2007
Posts: 1320

PostPosted: Wed Feb 24, 2010 4:45 pm    Post subject: Reply with quote

Code:
35 48 49 50 51 52 53 54 55 56 57 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 93 95 97 98 99
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 128 129 130 131 132 133 134 135 136 137
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 161 162 163 164 165 166 167 168 169 170 171
172 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255


That is what I sift through to find bad ranges. I hope you can understand why I keep missing some. Laughing

Updated the code to:

Code:
vfv(n) { ; vfv(n) : n - Name of function or variable : true if valid else false
   Return !RegExMatch(n, "[^#0-9@-\[\]_a-z---]{1,253}")
   ; Hex needle: [^\x23\x30-\x39\x40-\x5b\x5d\x5f\x61-\x7a\x80-\x9f\xa1-\xac\xae-\xff]{1,253}
}

_________________
Religion is false. >_>
Back to top
View user's profile Send private message
dr*
Guest





PostPosted: Wed Feb 24, 2010 5:17 pm    Post subject: Reply with quote

Code:
msgbox % vfv( "$YEAH" ) ? "YES" : "NO"


fail
Back to top
trik



Joined: 15 Jul 2007
Posts: 1320

PostPosted: Wed Feb 24, 2010 5:18 pm    Post subject: Reply with quote

dr* wrote:
Code:
msgbox % vfv( "$YEAH" ) ? "YES" : "NO"


fail


>_>

Code:
vfv(n) { ; vfv(n) : n - Name of function or variable : true if valid else false
   Return !RegExMatch(n, "[^#$0-9@-\[\]_a-z---]{1,253}")
   ; Hex needle: [^\x23\x24\x30-\x39\x40-\x5b\x5d\x5f\x61-\x7a\x80-\x9f\xa1-\xac\xae-\xff]{1,253}
}

_________________
Religion is false. >_>
Back to top
View user's profile Send private message
dR*
Guest





PostPosted: Wed Feb 24, 2010 5:18 pm    Post subject: Reply with quote

ANSI Table
http://www.mmvisual.de/Hilfe/BinTerm/T044.htm
Back to top
trik



Joined: 15 Jul 2007
Posts: 1320

PostPosted: Wed Feb 24, 2010 5:23 pm    Post subject: Reply with quote

dR* wrote:
ANSI Table
http://www.mmvisual.de/Hilfe/BinTerm/T044.htm


An ANSI table does not know which characters AutoHotkey does or does not allow into its functions and variables.
_________________
Religion is false. >_>
Back to top
View user's profile Send private message
Guest






PostPosted: Wed Feb 24, 2010 5:25 pm    Post subject: HORIZ SCROLLING SUCKS Reply with quote

OMG...I now have a widescreen monitor & this thread STILL gives me horiz scrolling!...aaaahhhh!
Back to top
trik



Joined: 15 Jul 2007
Posts: 1320

PostPosted: Wed Feb 24, 2010 5:26 pm    Post subject: Re: HORIZ SCROLLING SUCKS Reply with quote

Anonymous wrote:
OMG...I now have a widescreen monitor & this thread STILL gives me horiz scrolling!...aaaahhhh!


I would break the lines, but then the function in the example would not work. Anyway, it looks just fine to me in 1024x1280 and 768x1366.
_________________
Religion is false. >_>
Back to top
View user's profile Send private message
Guest






PostPosted: Wed Feb 24, 2010 5:59 pm    Post subject: Re: HORIZ SCROLLING SUCKS Reply with quote

trik wrote:
I would break the lines...

...a really simple solution is to add about 5 lines (comment lines or blank lines) to the code so it auto-collapses...(a better solution requires me editing the sites code.js)...

trik wrote:
Anyway, it looks just fine to me...

...that's not possible...

trik wrote:
...in 1024x1280 and 768x1366.

...did you swap the numbers?...or is your monitor really in portrait?...(which would make you have more horiz scrolling)? Mine is 1280x720 & has horiz scrolling (1280 is horiz/x, 720 is vertical/y)...
Back to top
trik



Joined: 15 Jul 2007
Posts: 1320

PostPosted: Wed Feb 24, 2010 6:01 pm    Post subject: Re: HORIZ SCROLLING SUCKS Reply with quote

Anonymous wrote:
...did you swap the numbers?...or is your monitor really in portrait?...(which would make you have more horiz scrolling)? Mine is 1280x720 & has horiz scrolling (1280 is horiz/x, 720 is vertical/y)...


Shocked Whoops. Embarassed I did swap them, yes.
_________________
Religion is false. >_>
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group