Re: [FlexJS] String.match()

2017-07-21 Thread Harbs
lists.apache.org displays it fine: https://lists.apache.org/thread.html/ec0b951752140ad0cd56319b9629cc4a7e097487fd47c84649ffc352@%3Cdev.flex.apache.org%3E

Re: [FlexJS] String.match()

2017-07-21 Thread Alex Harui
My email totally mangled your post. Anyway, if you think you've got code that is equivalent to Flash's String.match, that's good enough for now. If folks find issues later we can improve on the utility function. If you want to alter the compiler output, see how I handled Array.sortOn in Function

Re: [FlexJS] String.match()

2017-07-20 Thread Harbs
No. We thought that the “?” found the string in Flash. It does not. trace("https://www.google.com/search?q=dogs".match("?")); trace("https://www.google.com/search?q=dogs".search("?")); trace("https://www.google.com/search?q=dogs".indexOf("?")); outputs: null -1 29 > On Jul 21, 2017, at 12:00 AM

Re: [FlexJS] String.match()

2017-07-20 Thread Alex Harui
I think I'm still confused. My current thinking is that in Flash there are strings you can pass in that are "invalid RegExp" that will still find matches in a string. Isn't that what Yishay showed? IOW, passing in just "?" in Flash will find question marks in a string but is an error in JS becau

Re: [FlexJS] String.match()

2017-07-20 Thread piotrz
Harbs, Your second thought in my opinion is better solution. My daily job is in .NET/WPF and in C# following code var str = "m?o"; Regex reg = new Regex("?"); var match = reg.Match(str); Will throw "ArgumentException A regular expression parsing error occurred.", so there is no possibility to p

Re: [FlexJS] String.match()

2017-07-20 Thread Harbs
After all this discussion, I’m having second thoughts about this whole thing. What’s the point of using an invalid RegExp that will not match anything? I think the JS behavior makes more sense than the Flash behavior. If a RegExp is invalid, it should throw an error rather than never matching an

Re: [FlexJS] String.match()

2017-07-20 Thread Harbs
new RegExp({}) returns: /[object Object]/ I think the wrapping that I did in the code I already committed is correct: try{return input.match(pattern);} catch (e:Error){return null;} If the try fails, that means the RegExp is an invalid expression and will not match anything in Flash. In that ca

Re: [FlexJS] String.match()

2017-07-20 Thread Alex Harui
I'm confused. Doesn't Yishay's example use syntax that Harbs claimed threw an error? Anyway, I can believe the three steps Harbs listed are correct for JS since step 1 might just happen via implicit type coercion. I suppose someone could test it by seeing if JS handles "new RegExp({})"; But sinc

Re: [FlexJS] String.match()

2017-07-20 Thread Harbs
Right. That’s why I was suggesting wrapping the call in a try/catch and returning null/-1 from the catch. Additionally, the array returned from String.match() is a non-standard one. It has input and index properties. > On Jul 20, 2017, at 8:52 PM, yishayw wrote: > > I think there would still

Re: [FlexJS] String.match()

2017-07-20 Thread yishayw
I think there would still be a difference between flash and js because the flash implementation (counter to AS3 documentation) always returns null when an invalid regex is passed as a string. So according to your suggested implementation for Var s: String = "m?o"; Var a:Array = s.match("?") a is

Re: [FlexJS] String.match()

2017-07-20 Thread Harbs
> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fhelp.ado >>>> be >>>> >>>> .com%2Fen_US%2FFlashPlatform%2Freference%2Factionscript%2F3%2FString.htm >>>> l% >>>> >>>> 23match&data=02%7C01%7C%7C66b63f8

Re: [FlexJS] String.match()

2017-07-20 Thread Alex Harui
a=02%7C01%7C%7C66b63f8228ab4f80a39408d4cf66f9a9%7Cfa7b1b5a7b3 >>>44 >>> >>>38794aed2c178decee1%7C0%7C0%7C636361488561328745&sdata=CbWB8sk4vOv1vId9a >>>T7 >>> WkDjQrkqarHU2aAAoWw9UBNA%3D&reserved=0() >>> >>> From: Harbs<

Re: [FlexJS] String.match()

2017-07-20 Thread Harbs
7C636361488561328745&sdata=CbWB8sk4vOv1vId9aT7 >> WkDjQrkqarHU2aAAoWw9UBNA%3D&reserved=0() >> >> From: Harbs<mailto:harbs.li...@gmail.com> >> Sent: Thursday, July 20, 2017 9:40 AM >> To: dev@flex.apache.org<mailto:dev@flex.apache.org> >> Subje

Re: [FlexJS] String.match()

2017-07-20 Thread Alex Harui
> >From: Harbs<mailto:harbs.li...@gmail.com> >Sent: Thursday, July 20, 2017 9:40 AM >To: dev@flex.apache.org<mailto:dev@flex.apache.org> >Subject: Re: [FlexJS] String.match() > >Both Flash and JS engines automatically convert to RegExp. I had not >realized that at

RE: [FlexJS] String.match()

2017-07-20 Thread Yishay Weiss
Good catch. I was misled by the docs [1]. [1] http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/String.html#match() From: Harbs<mailto:harbs.li...@gmail.com> Sent: Thursday, July 20, 2017 9:40 AM To: dev@flex.apache.org<mailto:dev@flex.apache.org> Subject:

Re: [FlexJS] String.match()

2017-07-20 Thread Harbs
Yes. trace is stripped out in release. (We still need to remove the dead code, but that will happen too.) > On Jul 20, 2017, at 9:37 AM, piotrz wrote: > > Hi Harbs, > > I'm not so convinced by the trace. Maybe something from your debugger to > have everything in debug. Does trace stripped out

Re: [FlexJS] String.match()

2017-07-19 Thread piotrz
Hi Harbs, I'm not so convinced by the trace. Maybe something from your debugger to have everything in debug. Does trace stripped out in release version of JS? Thanks, Piotr - Apache Flex PMC piotrzarzyck...@gmail.com -- View this message in context: http://apache-flex-development.247

Re: [FlexJS] String.match()

2017-07-19 Thread Harbs
Both Flash and JS engines automatically convert to RegExp. I had not realized that at first. It seems that the only difference between the Flash engine and JS engines is what happens when constructing a RegExp object from invalid input. Flash matches nothing, while JS throws an error. By just

Re: [FlexJS] String.match()

2017-07-19 Thread Alex Harui
It looks like they just trace a warning instead of trying to convert to a RegExp. Is that what we want to do? Or should we add code that converts a string to regex? Thoughts? -Alex On 7/19/17, 4:32 AM, "Harbs" wrote: >I added the utility functions. I think they can be very simple. > >> On Jul

Re: [FlexJS] String.match()

2017-07-19 Thread Harbs
I added the utility functions. I think they can be very simple. > On Jul 19, 2017, at 9:30 AM, Alex Harui wrote: > > Unless we are absolutely sure that everybody will need the code generated > by the compiler, having the compiler call a framework function makes it > easier for an app developer t

Re: [FlexJS] String.match()

2017-07-18 Thread Alex Harui
Unless we are absolutely sure that everybody will need the code generated by the compiler, having the compiler call a framework function makes it easier for an app developer to make any adjustments to that code. It is easier to monkey-patch a utility function than find-and-replace some sequence of

Re: [FlexJS] String.match()

2017-07-18 Thread Harbs
Here seems to be the explanation for that: new RegExp("?”) In Flash, this creates a RegExp object. In JS, it throws an “Invalid regular expression” error. > On Jul 18, 2017, at 9:38 PM, Harbs wrote: > > The “?” case seems to be an outlier.

Re: [FlexJS] String.match()

2017-07-18 Thread yishayw
Alex Harui-2 wrote > By > calling new utility functions, the developer has control over the > conversion. I don't understand that point. Do you mean an app developer? -- View this message in context: http://apache-flex-development.247.n4.nabble.com/FlexJS-String-match-tp63392p63405.html

Re: [FlexJS] String.match()

2017-07-18 Thread Harbs
Calling language functions at first seemed unnecessarily expensive to me. I just did a bit of research, and it looks like I was wrong about replacing search with indexOf. That will only work for simple string searches. str.search(“.”) will always return 0 unless the string is empty, because the

Re: [FlexJS] String.match()

2017-07-18 Thread Alex Harui
This feels like something that the compiler should just call Language.stringMatch and Language.stringSearch (or standalone equivalents). I'm not clear that we should always modify the string. By calling new utility functions, the developer has control over the conversion. -Alex On 7/18/17, 4:11

Re: [FlexJS] String.match()

2017-07-18 Thread Harbs
The same issue applies to String.search(), although it might make sense to replace String.search() with String.indexOf() if the parameter is a string. > On Jul 18, 2017, at 12:36 PM, yishayw wrote: > > In flash String.match() can take either a string or a regex. In JS it's > always considered t