AutoHotkey Community

It is currently May 26th, 2012, 9:59 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 83 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next
Author Message
 Post subject:
PostPosted: October 14th, 2008, 7:24 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
But the pipe character is the delimiter, right? The encoding and decoding functions seem to specifically encode only the pipe (delimiter) and % (encoding character), and decode just those back to the same.:

Quote:
SA_Enc( Val )
{
StringReplace, Val, Val, `%, `%e, All ; e(ncoding char)
StringReplace, Val, Val, |, `%d, All ; d(elimeter char)
return Val
}

SA_Dec( Val )
{
StringReplace, Val, Val, `%d, |, All ; d(elimeter char)
StringReplace, Val, Val, `%e, `%, All ; e(ncoding char)
return Val
}

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 14th, 2008, 7:30 pm 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
bmcclure wrote:
Your data can contain the pipe character ... so pipes will be encoded and decoded correctly at each level.
Exactly, so you don't need to worry about passing anything strange into the functions, I'll be encoded properly and retrieved just as well. So, as long as you use my functions to access and modify the array, you should be fine putting pretty much anything in it.

Yes, it will support named indexes when I release the next version. No duplicate names will be allowed. A valid name is any string that is non-blank and is not a number. (pretty broad, huh? :P ) (still no worries about pipe chars in names, they're encoded too :) ) I'm also releasing a way of getting nested array values.

I've nearly got the rewrite done, but probably won't finish it till next week. It should not break any current application of SA.

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 14th, 2008, 7:36 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
:D *drool*

I can hardly wait for the rewrite with named indexes. It will make my Games and Tools arrays sooo much easier to work with in SteamLab!

Thanks for the cool functions!

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 14th, 2008, 7:42 pm 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
lol, you guys are fast! :D I'm three posts behind! :P

Right now, the pipe character IS the delimiter, and it's encoded whenever it's put into the array. I am seriously considering changing the delimiter and encoding characters to control chars. Like the EOT and ENQ chars. (asc 5 and 6) There would be no change in functionality, only that there is less chance for someone to pass a value with it inside.

Thanks for your support :)

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 14th, 2008, 7:57 pm 
Offline

Joined: December 13th, 2006, 7:16 am
Posts: 48
That's a good idea.
Something like '\0' (NUL) would basically never be inputted (or technically will always be inputted, but never put in the array), it would be kind of like strtok-ing in C. Though back when I was thinking about doing that the best one I came up with was BS (Backspace). BEL is also never used anymore. EOT (^d) is still used on unix systems and various input terminals, so it may cause some problems. Though, I dont think DOS (or Windows) uses it...


Last edited by olegbl on October 14th, 2008, 8:21 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 14th, 2008, 8:17 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
Can you even use nulls logically in AHK? I thought it stopped at the first null character found, even if it were in the middle of the string?

I've had to come up with functions that replace nulls to get AHK to read past them at all when I've had to read things like Bencoded files and Steam's settings file.

Maybe that wouldn't be an issue in SA, but since it just uses standard string functions, wouldn't the null characters still need to be replaced with something else to be able to return anything after the first one?

But I guess even if so, there are a lot of characters besides null that could be used.

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 14th, 2008, 8:21 pm 
Offline

Joined: December 13th, 2006, 7:16 am
Posts: 48
Well, that's the point of nulls, they now mean (though not originally) that the string is ended. Then again, considering AHK doesn't store strings as pointers, it might forget about anything after the NUL. If it doesn't however, then the null would be used as the delimiter. Such as in strsplit. I haven't tested this so I'm not sure they would work properly, but if they do, they would probably be the most appropriate character...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 14th, 2008, 8:29 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
I think you would not be able to use standard functions to retrieve values after the first null in an array however. For instance, once I import a file with nulls into it as a variable, AHK does keep the data after the first null (until after you use other functions which don't see that data and save back to the variable), but you can't retreive that data without first removing any nulls before it. At least, this was my experience previously, unless something has changed.

If there is an efficient way around this problem, or if I'm mistaken, then I think a null character would be an excellent choice.

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 14th, 2008, 9:10 pm 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
Yes. NULL is not even recognized as a param in ahk's commands/functions. So, for now I'll use BS and BEL chars. It shouldn't change anything, except maybe a bit less en/decoding.

I believe it is possible to work with strings past a null char using regex. I may do that someday, but it would have to be a v4 :P.

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 14th, 2008, 11:29 pm 
Offline

Joined: May 22nd, 2008, 12:57 am
Posts: 120
I’ll be looking forward to this update. I’d also be curious as to benchmarking the basic functions vs. a loop/parse statement. Seems like I end up doing way too many stringsplits and loop/parses in ahk, just to retrieve the results of one pseudo-array variable. Thanks again for this library.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Bug report
PostPosted: October 21st, 2008, 7:05 pm 
Offline

Joined: July 12th, 2008, 4:06 pm
Posts: 8
Thank you for sharing your work very greatful! It is vary easy to use, give me a lot of help.
When i ues , i found a problem with SA_Del() . Sample like that:
Code:
Ary1 = a|b|c
Ary2 = d|e|f

MsgBox % "Adding one array as an element in another:`nArray2:`t"
   . Ary2 "`nInside:`nArray1:`t"
   . Ary1 "`nBecome:`t"
   . Ary1 := SA_Set(Ary1,Ary2,4)

MsgBox % "Delet an element in the end of a Array:`n"
   . Ary1 := SA_Del(Ary1,4)

I found you lost think with StringGetPos return error.
The original code in SA_Del():
Code:
Dir = R

changed to:
Code:
rDir = R

The original code in SA_Del():
Code:
StringGetPos, lPos, Array, |, % lDir lIdx
   StringGetPos, rPos, Array, |, % rDir rIdx
   lStr := SubStr(Array, 1, lPos)
   rStr := SubStr(Array, rPos+2)

changed to:
Code:
StringGetPos, lPos, Array, |, % lDir lIdx
   StringGetPos, rPos, Array, |, % rDir rIdx
   If ErrorLevel
      rStr := ""
   Else
      rStr := SubStr(Array, rPos+2)
   lStr := SubStr(Array, 1, lPos)

And i also change the SA_Dec():
Code:
SA_Dec( Val )
{
   StringReplace, Val, Val, `%@*,  |, All ; d(elimeter char)
   StringReplace, Val, Val, `%$#, `%, All ; e(ncoding char)
   return Val
}

SA_Enc as the same. Because i worried "%d" may appear in the content of array itself.
Your code so smart make me shock!
It's the first post of me in here . I'm llook forward the greatest Array lib.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2008, 8:52 pm 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
lwjiee wrote:
And i also change the SA_Dec() ... SA_Enc as the same. Because i worried "%d" may appear in the content of array itself.
Your code so smart make me shock!
Thank you! I haven't been able to work on it for a couple days, but I have a new, improved version that I will probably release this weekend. It includes being able to get values in nested arrays, and using named indexes. Thanks for noting the errors, I will look them over, but the new version is a rewrite, so may not need these updates.

The encoding and decoding setup work flawlessly with whatever you throw at it, including "%d" or "%e". (ok, maybe not NULL, but I don't see how you could put that in the array anyway. :P ) So it is unnecessary to change it to unlikely strings.

A quick example of how it works:
Code:
SA_Set(array, "%d")
MsgBox %array%
SA_Set(array, "%e", 2)
MsgBox %array%

MsgBox % SA_Get(array)
MsgBox % SA_Get(array, 2)

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 22nd, 2008, 1:43 am 
Offline

Joined: July 29th, 2005, 5:32 pm
Posts: 179
infogulch wrote:
I have a new, improved version that I will probably release this weekend. It includes being able to get values in nested arrays, and using named indexes.
Hooray! Thanks for this.. it is extremely useful.

I especially look forward to seeing how your going to implement the named indexes. :D

_________________
.o0[ corey ]0o.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 22nd, 2008, 4:53 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
I especially look forward to using the named indexes :)

Getting a little tired of looping through arrays to find a particular value.

A find function, and named indexes, will eliminate the need to loop at all in most cases :D

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 22nd, 2008, 5:12 pm 
Offline

Joined: July 12th, 2008, 4:06 pm
Posts: 8
oh, great, it looks easy with 3D or nD arrays.

I want to ask you two question ,
question one ,why code like that:
Code:
SA_Del( ByRef Array, fmIdx, toIdx="" )

without ByRef, it still works..
question two ,why
Code:
SA_Get(SA_Get(array,n),m)

does't ,but
Code:
SA_Get(blank := SA_Get(array,n),m)

works
I'm confused with BuRef, like this
http://www.autohotkey.com/forum/viewtopic.php?t=36982
Thank you very much!
[/quote]


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 83 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: kenn, xXDarknessXx and 15 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group