AutoHotkey Community

It is currently May 27th, 2012, 6:43 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 741 posts ]  Go to page Previous  1 ... 29, 30, 31, 32, 33, 34, 35 ... 50  Next
Author Message
 Post subject:
PostPosted: August 8th, 2011, 10:58 pm 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
Oooooh I just had an idea. Never mind what I just said lol.

If splitting by characters, then pass an array. (like Franke said)

BUT if the parameter is a number instead then split the string with number-characters per index.


Code:
string := "abc 12 xy_zwk cd_ahk"
StrSplit(string, [" ","_"]) ; yields: ["abc","12","xy",zwk","cd","ahk"]
StrSplit(string, 4)  ; yields: ["abc ", "12 xy", "_zwk", " cd_", "ahk"]

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 8th, 2011, 11:14 pm 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
I was thinking that "delim" and ["delim"] would be equivalent. If you want to use multiple delimiters you can put them in an array. Otherwise just use the one and only delimiter as a literal string / variable containing a string.

It's the most consistent way I can think of. That is assuming multi-character delimiters are going to be allowed at all.

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 9th, 2011, 12:49 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Frankie wrote:
It allows the most flexibility with minimal negative effects.
StrSplit(String, [SingleDelimiterString]) is just as flexible. It's just a matter of which would be more commonly used: a list of delimiting characters or a single delimiting string.
infogulch wrote:
I think the Delimiters param should allow two values: a string or an array.
That was my intention, as implied by my previous post.
Quote:
This allows the current syntax to remain intact
This is not of particular concern for the v2 alpha.
Quote:
BUT if the parameter is a number instead then split the string with number-characters per index.
I thought of that too, which is why I didn't add that little bit of extra code to convert numeric parameters to strings. But would it really be useful enough?

Another issue is the OmitList parameter: for performance and convenience, it might be best to leave it as is, but it might seem inconsistent.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 9th, 2011, 1:48 am 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
Lexikos wrote:
Quote:
BUT if the parameter is a number instead then split the string with number-characters per index.
I thought of that too, which is why I didn't add that little bit of extra code to convert numeric parameters to strings. But would it really be useful enough?
I often limit output to less than 80 characters. A StrSplit of every 79 characters and then joining them back together with `n between each line would do the trick. Join can be done very easily.
Code:
for key, val in StrSplit(Data, 79, "`n`r") ; Each 79 characters
   if Key < 50 ; Limit to 50 lines
      Out .= val "`n"


Quote:
Another issue is the OmitList parameter: for performance and convenience, it might be best to leave it as is, but it might seem inconsistent.
I can't think of any cases why I'd want to omit strings of characters.

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 9th, 2011, 4:10 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Frankie wrote:
I often limit output to less than 80 characters.
Thanks for the example. That's very practical.
Quote:
Join can be done very easily.
Even so, it makes sense to provide StrJoin() as a built-in function. Since it can be easily added later without breaking anything, it might wait until after the first stable release.
Quote:
I can't think of any cases why I'd want to omit strings of characters.
My point was that one parameter accepting an array and the other parameter accepting a list of characters as a string would be inconsistent. Requiring OmitList to be an array like [A_Space, A_Tab] would be more consistent but less efficient. (I'll probably just go with the easiest approach: leave OmitList exactly the way it is.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 9th, 2011, 3:02 pm 
Offline

Joined: February 5th, 2007, 12:19 pm
Posts: 192
Location: Osnabrück, Germany
Frankie wrote:
I often limit output to less than 80 characters.
Here's a small wordwrap function:
Code:
wordwrap(text,linelength:=35){
 for key, val in StrSplit(text, A_Space, "`n`r")
 {
  if out <> ""
   le := "`n"
  if key=1
   line := val
  else if (!mod(StrLen(line),linelength) or (StrLen(line)=0))
  { 
   Out .= le line
   line := val
  }
  else if ((mod(StrLen(line),linelength )+ StrLen(val) +1 ) > linelength)
  {
   out .= le line 
   line := val
  }
  else       
   line .=  " " val
 }
 return out
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 10th, 2011, 7:25 pm 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
infogulch wrote:
Well obviously one can [strike]split a string[/strike] word wrap with custom code, I thought that was self-evident enough not to mention but I guess not... :roll:
Deja-vu or is it just me?

Can we please skip all the "here's a function that does that" posts already? If someone mentions an example, they probably already have a custom function to do it.

Sometimes it's nice when the language you're using does some of the more simple and obvious things for you (faster I might add) without having to code it up and test it yourself, every time.


Lexikos: I would leave omitchars as is, I can't think of an example where I would want to omit strings, not just characters.
And I like the length-split idea. :)

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 10th, 2011, 8:59 pm 
Offline

Joined: February 5th, 2007, 12:19 pm
Posts: 192
Location: Osnabrück, Germany
infogulch wrote:
Can we please skip all the "here's a function that does that" posts already?

Sorry.. I don't do it again!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 10th, 2011, 10:18 pm 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
infogulch wrote:
Can we please skip all the "here's a function that does that" posts already?
Agreed. I'll do my best to remember.

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 14th, 2011, 4:50 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
I just noticed new Class returns a new object even if __New is defined but couldn't be called because required parameters were omitted. Should it be changed so that new fails in that case?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 14th, 2011, 5:15 am 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
Lexikos wrote:
Should it be changed so that new fails in that case?
Yes it should be changed. If you have some code in your __New function that's critical to class function (regardless of personal preferences) it should always run.

I get confused with class and prototype syntaxes existing at the same time. Is it possible to determine that new CN() is defined with a minimum of one argument, and thus should give an error? If I had to guess I'd (sadly) say it isn't.

The other side of this would be creating descendant objects dynamically. You did say "even if _New is defined." Well what if it isn't? Would the rules be different to allow the following? Or the same for the sake of consistency?
Code:
oFirst := {Prop: "Look at my property!"}
oCopy := new oFirst()
oCopy.Prop := "I have a different value.  I'm my very own object!"

Msgbox % oFirst.Prop
Msgbox % oCopy.Prop
Msgbox % oCopy.base = oFirst ; true in 1.1.01.00

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 14th, 2011, 7:58 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Frankie wrote:
I get confused with class and prototype syntaxes existing at the same time.
I've said this before: one is syntax, and the other is functionality. Class syntax "can be used to construct a base object" or in other words, a class is a prototype. If the apparent duality bothers you, just choose one way and stick with it.
Quote:
Is it possible to determine that new CN() is defined with a minimum of one argument,
Yes.
Code:
MsgBox % CN.__New.MinParams  ; Includes the implicit "this" param.
MsgBox % IsFunc(CN.__New)  ; Can be given a function name OR reference.
class CN {
    __New(param) {
        ;...
    }
}

Quote:
Well what if it isn't?
That is a different case to the specific one described in my previous post, and therefore would not be affected by the proposed change.

Your example is equivalent to this:
Code:
class oFirst
{
    static Prop := "Look at my property!"
}
oCopy := new oFirst()
... except that static initializers are always evaluated before the auto-execute section, and oFirst.__Class contains the string "oFirst". Would you want new oFirst() to fail in that case, since __New is not defined? (You don't need to answer that.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2011, 2:58 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
v2.0-a017-5157e3d:
  • Merged v1.1.02.03.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2011, 12:36 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
v2.0-a018-38235ab:
  • Merged v1.1.03.00.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 7th, 2011, 1:24 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
v2.0-a019-b56df88:
  • Merged v1.1.04 (WIP).

I have more planned for v1.1.04, so it's not released yet. See the commit history for a full list of changes. The highlight of this release is try/catch/throw, coded mostly by fincs and reviewed by myself. It affects a large number of commands, so watch out for bugs.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 741 posts ]  Go to page Previous  1 ... 29, 30, 31, 32, 33, 34, 35 ... 50  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, jepjep24, Yahoo [Bot] and 16 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