Return value of findReplace.replace() always false on Replace All (fixed)

Return value of findReplace.replace() always false on Replace All (fixed)

9
NewbieNewbie
9

    Apr 29, 2014#1

    Hi, there:

    I've a script that will repeat till there's no more occurrence of a pattern. But recently I found it cannot complete it.
    The script just removes any spaces between "!", "?" or ".".

    It works when I do it manually by replace dialog box with parameter of "([!?.])\s+([!?.])" and "\1\2".

    But with UEStudio v14.00, the "do loop" of this script will just run once, because the return value of findReplace.replace() is always "false". And that is different from the older version (UE 14 or UES 6).

    Code: Select all

    function Srt_Norm() {
     var cnt;
     with (UltraEdit.activeDocument) {
     findReplace.replaceAll=true;
     findReplace.matchCase=true;
     findReplace.regExp=true;
    
     top();
     do {
     cnt = findReplace.replace("([!?.])\\s+([!?.])", "\\1\\2");
    // UltraEdit.outputWindow.write(cnt+"\r\n");
     } while (cnt);
     }
    }
    
    UltraEdit.insertMode();
    if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
    else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
    UltraEdit.unixReOn();
    UltraEdit.activeDocument.hexOff();
    Srt_Norm();
    
    I've temporary fixed the problem with following script, but it sucks. I'm sure that it's bug of UEStudio v14.10.

    Reason 1:
    The above script worked with older version of UE 14.xx and UES 6.xx.

    Reason 2:
    With option findReplace.replaceAll=true; the command findReplace.replace() returns always false, no matter there a match/replace occurs (in current version).

    Reason 3:
    With option findReplace.replaceAll=false; the command findReplace.replace(); returns true, if a match/replace occurs.
    (But, it will not warp to top(), so I have to add scripting command top(); at right places.)

    Code: Select all

     do {
     top();
     findReplace.replaceAll=false;
     cnt = findReplace.replace("([!?.])\\s+([!?.])", "\\1\\2");
     if (cnt) {
     findReplace.replaceAll=true;
     findReplace.replace("([!?.])\\s+([!?.])", "\\1\\2");
     }
    // UltraEdit.outputWindow.write(cnt+"\r\n");
     } while (cnt);
    
    Please help, thanks.

    6,675585
    Grand MasterGrand Master
    6,675585

      Apr 29, 2014#2

      It should be investigated if this issue with Replace All always returning false at least with Unix regular expression engine is indeed a bug of UE v21.10.0.1026 and UEStudio v14.10.0.1002 and in which version this bug occurred the first time. I will do that on weekend and report this issue to IDM support by email, except you do that already before. Interesting would be also if UltraEdit.activeDocument.isFound() or UltraEdit.activeDocument.isNotFound() after the replace command returns a different value than the replace command itself.
      Best regards from an UC/UE/UES for Windows user from Austria

      9
      NewbieNewbie
      9

        Apr 29, 2014#3

        No, I did not investigated that, because I only have UE 14 and UES 6 (from my former employer) and I myself licensed UEStudio @ 2013/09. So, I don't have anything else in between.

        And the value isFound() or isNotFound() report is synchronized with findReplace.replace()

        Hope that IDM will fix that quickly.

        6,675585
        Grand MasterGrand Master
        6,675585

          Apr 29, 2014#4

          I decided to immediately look on this issue and could reproduce the problem.

          As a bug can be fixed only if a user reports it by email to IDM support, I have sent a few minutes before following to IDM (shortened a little bit).

          Code: Select all

          The scripting command UltraEdit.activeDocument.findReplace.replace() used
          with option replaceAll=true returns always false even when at least one
          string was found and replaced. Also UltraEdit.activeDocument.isFound()
          used after the "Replace All" returns always false.
          
          I could reproduce this problem with Unix and Perl regular expression engine.
          I have not tested if this issue exists also with UltraEdit regexp engine or
          on non regexp "Replace All".
          
          The problem exists in UltraEdit v21.00.0.1027 to v21.10.0.1026 and
          UEStudio v14.10.10.1002. It can be reproduced with following script:
          
          
          UltraEdit.insertMode();
          if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
          else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
          UltraEdit.perlReOn();
          
          UltraEdit.outputWindow.showStatus=false;
          UltraEdit.outputWindow.clear();
          UltraEdit.outputWindow.showWindow(true);
          
          UltraEdit.newFile();
          UltraEdit.activeDocument.write(".\t !   .");
          UltraEdit.activeDocument.top();
          
          UltraEdit.activeDocument.findReplace.mode=0;
          UltraEdit.activeDocument.findReplace.matchWord=false;
          UltraEdit.activeDocument.findReplace.searchDown=true;
          UltraEdit.activeDocument.findReplace.searchInColumn=false;
          UltraEdit.activeDocument.findReplace.preserveCase=false;
          UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
          
          UltraEdit.activeDocument.findReplace.replaceAll=true;
          UltraEdit.activeDocument.findReplace.matchCase=true;
          UltraEdit.activeDocument.findReplace.regExp=true;
          
          var bRetVal;
          do {
             bRetVal = UltraEdit.activeDocument.findReplace.replace("([!?.])\\s+([!?.])", "\\1\\2");
             UltraEdit.outputWindow.write("Replace command returned "+bRetVal+".");
             if (UltraEdit.activeDocument.isFound())
             {
                UltraEdit.outputWindow.write("At least one string found and replaced.");
             }
             else
             {
                UltraEdit.outputWindow.write("Nothing found and replaced according to isFound().");
             }
          } while (bRetVal);
          
          
          The output window should contain after script execution:
          
             Replace command returned true.
             At least one string found and replaced.
             Replace command returned true.
             At least one string found and replaced.
             Replace command returned false.
             Nothing found and replaced according to isFound().
          
          This is the output of UE v20.00.0.1056 and UES v14.00.0.1012.
          
          The later versions of UE/UES write into output window:
          
             Replace command returned false.
             Nothing found and replaced according to isFound().
          
          The following macro doing the same as the script works also in
          currently latest versions of UltraEdit and UEStudio.
          
          InsertMode
          ColumnModeOff
          NewFile
          ". !   ."
          Top
          UnixReOn
          Loop 0
          Find MatchCase RegExp "([!?.])\s+([!?.])"
          Replace All "\1\2"
          IfNotFound
          ExitLoop
          EndIf
          EndLoop
          
          So this bug affects only scripts.
          Update: This problem was fixed with UltraEdit v21.20.0.1004.

          And I can offer also a better workaround for this problem for you.

          Code: Select all

          function Srt_Norm() {
             with (UltraEdit.activeDocument) {
          
                findReplace.mode=0;
                findReplace.matchWord=false;
                findReplace.searchDown=true;
                findReplace.searchInColumn=false;
                findReplace.preserveCase=false;
                findReplace.replaceInAllOpen=false;
                findReplace.replaceAll=true;
                findReplace.matchCase=true;
                findReplace.regExp=true;
          
                top();
                findReplace.replace("(?<=[!?.])\\s+(?=[!?.])", "");
             }
          }
          
          UltraEdit.insertMode();
          if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
          else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
          UltraEdit.perlReOn();
          UltraEdit.activeDocument.hexOff();
          Srt_Norm();
          A single Perl regular expression Replace All with a positive lookbehind and positive lookahead on every sequence of whitespaces removes those whitespaces, too.
          Best regards from an UC/UE/UES for Windows user from Austria

          9
          NewbieNewbie
          9

            May 05, 2014#5

            Thanks for the workaround and report the bug to IDM, Mofi.

            I'll try to translate my set of scripts to Perl regex, they were unix regex as that day the perl regex was stranger to me.

              Re: Return value of findReplace.replace() always false on Replace All

              May 05, 2014#6

              This bug is not yet fixed in the Newest version US 14.20.0.1003.