Loading ...
Sorry, an error occurred while loading the content.
 

TEXT.REPLACE bug

Expand Messages
  • cantarellus
    I believe thare is a bug int the TEXT.REPLACE procedure. First the syntax should be: TEXT.REPLACE{} and not TEXT.REPLACE() since using curly brackets doesn t
    Message 1 of 1 , Jan 16, 2009
      I believe thare is a bug int the TEXT.REPLACE procedure.

      First the syntax should be:
      TEXT.REPLACE{} and not TEXT.REPLACE() since using curly brackets doesn't
      fire exception and is supported by the code in the TextToken.java file

      if (aTok.hasMoreElements())
      {
      action = aTok.nextToken();
      if (action.startsWith("REPLACE"))
      {
      // Make sure that any "." in the token itself stay
      together
      while (action.charAt(action.length() - 1) != '}')
      {
      action += "." + aTok.nextToken();
      }
      }
      }

      But reading the code further there seem to be a bit mess (added some
      comments in the code to better explain:

      // TEXT.REPLACEALL(regex,newtext) or
      // TEXT.REPLACEFIRST(regex,newtext)
      else if (action.startsWith("REPLACE"))
      {
      final String replaceType = action.substring(7,
      action.indexOf('{'));
      String args =
      action.substring(action.indexOf('{') + 1,
      action.length() - 1);
      int patternEnd = 0;
      // WHY NOT USING SPLIT INSTEAD OF THIS CODE A BIT COMPLICATED?
      for (;;)
      {
      patternEnd = args.indexOf(',', patternEnd);
      if (patternEnd <= 0)
      {
      break;
      }
      if (args.charAt(patternEnd - 1) != '\\')
      {
      break;
      }
      String temp = args.substring(0, patternEnd - 1);
      args = temp + args.substring(patternEnd, args.length());
      }
      if (patternEnd <= 0)
      {
      Logging.errorPrint("Invalid REPLACE token");
      }
      String pattern = args.substring(0, patternEnd);
      //HERE I DO NOT UNDERSTAND WHY OF THESE SUBSTITUTIONS (MAYBE IS NOT
      POSSIBLE TO USE ( OR ) WITHIN a REGEXP
      pattern =
      pattern.replaceAll("__LP__",
      "\\(").replaceAll("__RP__",
      "\\)").replaceAll("__PLUS__", "+");
      // ALSO THESE ARE NOT IMMEDIATE
      final String replacement =
      args.substring(patternEnd +
      1).trim().replaceFirst("^\"",
      "").replaceFirst("\"$", "");
      if (replaceType.equalsIgnoreCase("ALL"))
      {
      retString = retString.replaceAll(pattern, replacement);
      }
      else if (replaceType.equalsIgnoreCase("FIRST"))
      {
      // THIS IS WRONG SHOULD BE REPLACEFIRST AND NOT ALL
      retString = retString.replaceAll(pattern, replacement);
      }
      }


      In any case I'm not managing to replace anything with this function some
      doc could be useful.
      Thanks



      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.