RegExp | (OR) gives undefined in CS 5.1

A Listing of Confirmed Scripting Bugs and Anomalies - Open to all but only moderators can post

Moderators: Tom, Kukurykus

User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

RegExp | (OR) gives undefined in CS 5.1

Post by Kukurykus »

Code: Select all

"DSC3.putDouble(sTT('warpPerspectiveOther'), 0.000000)".replace(/(\.0+|[^a-z\d+\.]*(\d+[1-9]+)0*)(\))/gi, '$2$3')
The above code result: DSC3.putDouble(sTT('warpPerspectiveOther'), 0undefined)
while in CS2 it was OKEY so: DSC3.putDouble(sTT('warpPerspectiveOther'), 0)


In case there is other number than 0.000000 so for ex. 1.111111 that following code or regex (/(\.0+|[^a-z\d+\.]*(\d+[1-9]+)0*)(\)) read it, is OK.
When I tried to change order, so use: /(\[^a-z\d+\.]*(\d+[1-9]+)0*|.0+)(\))/gi, '$2$3' the result was bad too.


The only thing I could do was to make two separate RegExp codes and each of them use separately with other .replace() method. This way I got:

Code: Select all

"DSC3.putDouble(sTT('warpPerspectiveOther'), 0.000000)".replace(/([^a-z\d+\.]*(\d+[1-9]+)0*)(\))/gi, '$2$3').replace(/\.0+/gi, '')
It can be done also by:

Code: Select all

"DSC3.putDouble(sTT('warpPerspectiveOther'), 0.000000)".replace(/(\.0+|[^a-z\d+\.]*(\d+[1-9]+)0*)(\))/gi, '$2$3').replace(/(\d)undefined/g, '$1')
but it's not the point of course to loop twice some long ScriptListener code, and after all it's doubled .replace() so... bug is bug.


Can anyone find other workaround that will be used in one RegExp of one .replace() method ?
pixxxelschubser
Posts: 26
Joined: Mon Aug 01, 2016 8:59 pm

Re: RegExp | (OR) gives undefined in CS 5.1

Post by pixxxelschubser »

Hmmh?
I don't know if I understood you right.
And I don't understand the reasons for that what you want.
And furthermore I think your Regex is much to complicated (and not really correct).

Sorry for my bad english.
But perhaps this helps a little:

Code: Select all

var variableForRegex = "DSC3.putDouble(sTT('warpPerspectiveOther'), 0.00000)".replace(/((\d)(undefined|\.0+))/, '$2');
$.writeln(variableForRegex);
variableForRegex = "DSC3.putDouble(sTT('warpPerspectiveOther'), 0undefined)".replace(/((\d)(undefined|\.0+))/, '$2');
$.writeln(variableForRegex);
variableForRegex = "DSC3.putDouble(sTT('warpPerspectiveOther'), 0)".replace(/((\d)(undefined|\.0+))/, '$2');
$.writeln(variableForRegex);
variableForRegex = "DSC3.putDouble(sTT('warpPerspectiveOther'), 0.000000)".replace(/((\d)(undefined|\.0+))/, '$2');
$.writeln(variableForRegex);
variableForRegex = "DSC3.putDouble(sTT('warpPerspectiveOther'), 1.000000)".replace(/((\d)(undefined|\.0+))/, '$2');
$.writeln(variableForRegex);
variableForRegex = "DSC3.putDouble(sTT('warpPerspectiveOther'), 1.234567)".replace(/((\d)(undefined|\.0+))/, '$2');
$.writeln(variableForRegex);
variableForRegex = "DSC3.putDouble(sTT('warpPerspectiveOther'), 2.000000)".replace(/((\d)(undefined|\.0+))/, '$2');
$.writeln(variableForRegex);
variableForRegex = "DSC3.putDouble(sTT('warpPerspectiveOther'), 2.345678)".replace(/((\d)(undefined|\.0+))/, '$2');
$.writeln(variableForRegex);
Are this all cases which are possible?
:?:


But perhaps this is already a simple solution for your problem:

Code: Select all

var variableForRegex = "DSC3.putDouble(sTT('warpPerspectiveOther'), 0.00000)".replace(/\.0+/, '');
$.writeln(variableForRegex);
variableForRegex = "DSC3.putDouble(sTT('warpPerspectiveOther'), 0)".replace(/\.0+/, '');
$.writeln(variableForRegex);
variableForRegex = "DSC3.putDouble(sTT('warpPerspectiveOther'), 0.000000)".replace(/\.0+/, '');
$.writeln(variableForRegex);
variableForRegex = "DSC3.putDouble(sTT('warpPerspectiveOther'), 1.000000)".replace(/\.0+/, '');
$.writeln(variableForRegex);
variableForRegex = "DSC3.putDouble(sTT('warpPerspectiveOther'), 1.234567)".replace(/\.0+/, '');
$.writeln(variableForRegex);
variableForRegex = "DSC3.putDouble(sTT('warpPerspectiveOther'), 2.000000)".replace(/\.0+/, '');
$.writeln(variableForRegex);
variableForRegex = "DSC3.putDouble(sTT('warpPerspectiveOther'), 2.345678)".replace(/\.0+/, '');
$.writeln(variableForRegex);
;)
pixxxelschubser
Posts: 26
Joined: Mon Aug 01, 2016 8:59 pm

Re: RegExp | (OR) gives undefined in CS 5.1

Post by pixxxelschubser »

@Kukurykus,
are you still there?

:?:
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: RegExp | (OR) gives undefined in CS 5.1

Post by Kukurykus »

I'm sorry I didn't respond in no time only I saw your answer. I had to do it but first wanted to finish some code related to that problem I posted here. Give me time to today evening and I'll come with my thoughts...

I'm creating now very useful code changing Action Manager code it can be very readable for people who are both experienced users of Script Listener as well as those who just started programming and are lost with that how that looks like. After I'll do separate topic with that new Script I hope most of them can now see ScriptListener codes are looking more friendly and understanadable to use it for personal further changes.

It's why I play with RegExp and can find methods it work fast, but unfortunatelly I see there are many bugs. Meantime can you tell me did you try that code of me in newest (or just) CC Photoshop edition?
pixxxelschubser
Posts: 26
Joined: Mon Aug 01, 2016 8:59 pm

Re: RegExp | (OR) gives undefined in CS 5.1

Post by pixxxelschubser »

Kukurykus wrote:… Meantime can you tell me did you try that code of me in newest (or just) CC Photoshop edition?
It does no matter. Both codes work with PS CS5 and also with PS CC.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: RegExp | (OR) gives undefined in CS 5.1

Post by Kukurykus »

So here's one of the simplest example what I found doesn't work in CS 5(1) and CS 6 (and I think in CS 3 and CS 4), but worked fine in CS 2:

Code: Select all

".1".replace(/(\.0)|(\.1)/g, '$1$2')	//	CS6 result is: undefined.1 but CS2 result is: .1

Code: Select all

".0".replace(/(\.0)|(\.1)/g, '$1$2')	//	CS6 result is:  .0undefined but CS2 result is: .0

To make sure I'm right I checked how it works in some JavaScript editors. Everywhere it was like in CS2, and that is correct because that | character means OR, so when one condition isn't fulfiled then it's not displayed by undefined but only the second is called and vice versa.

If I wanted to fix above examples I had to write this:

Code: Select all

".1".replace(/(\.0)|(\.1)/g, '$1$2').replace(/undefined(\.\d)/g, '$1')

Code: Select all

".0".replace(/(\.0)|(\.1)/g, '$1$2').replace(/(\.\d)undefined/g, '$1')
It's only workaround, so someone doing it must be really careful if there are some undefined words in the code he doesn't want to 'remove'


I tried all your regexp implement to my code but if I didn't miss anything any of them didn't solve the problem. Of course maybe there is some way, but from the above it seems it's a bug. My point wasn't to delete by RegExp all trailing zeros from after coma (1.000000 -> 1, 5.010000 -> 5.01, 0.100400 -> 0.1004). Like you see when there are only zeros after coma then only a digit without following coma stays as result. When there are some number over zero after coma then there stays leading number from before coma, a coma and all numbers from after coma (without last zeros). It's what my code was designed for. If there is:

Code: Select all

"DSC3.putDouble(sTT('warpPerspectiveOther'), 0.000000)"	//	it should give: 0 (no coma)

Code: Select all

"DSC3.putDouble(sTT('warpPerspectiveOther'), 0.0005200)"	//	it should give: 0.00052
Exapmlary snippet and CS2 result (global mode of regex):

Code: Select all

desc26.putUnitDouble( idHrzn, idPxl, 155.000000 );	//	155
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc26.putUnitDouble( idVrtc, idPxl, 134.000100 ); // 134.0001
var idPnt = charIDToTypeID( "Pnt " );
desc24.putObject( idFwd, idPnt, desc26 );
var idBwd = charIDToTypeID( "Bwd " );
var desc27 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc27.putUnitDouble( idHrzn, idPxl, 151.003972 ); // 151,003972
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc27.putUnitDouble( idVrtc, idPxl, 135.000010 ); // 135.00001

Exapmlary snippet and CS6 result (global mode of regex):

Code: Select all

desc26.putUnitDouble( idHrzn, idPxl, 155.000000 );	//	155undefined
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc26.putUnitDouble( idVrtc, idPxl, 134.000100 ); // *
var idPnt = charIDToTypeID( "Pnt " );
desc24.putObject( idFwd, idPnt, desc26 );
var idBwd = charIDToTypeID( "Bwd " );
var desc27 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc27.putUnitDouble( idHrzn, idPxl, 151.003972 ); // *
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc27.putUnitDouble( idVrtc, idPxl, 135.000010 );// *

// correct in case if first of two conditions isnt only for zero after comas, otherwise it would be somenumber.undefined
So 4 next lines including a number without: .000000, 00, '', 0 while for example in CS6 the result are mixed with undefined