You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2001/05/03 14:54:36 UTC

cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Replace.java

bodewig     01/05/03 05:54:35

  Modified:    src/main/org/apache/tools/ant/taskdefs Replace.java
  Log:
  Make <replace> work for multibyte character sets.
  
  PR: 1208
  Submitted by:	AKIMOTO, Hiroki <ak...@bigfoot.com>
  
  Revision  Changes    Path
  1.12      +10 -6     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Replace.java
  
  Index: Replace.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Replace.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Replace.java	2001/01/19 15:04:11	1.11
  +++ Replace.java	2001/05/03 12:54:33	1.12
  @@ -285,13 +285,17 @@
               BufferedWriter bw = new BufferedWriter(new FileWriter(temp));
   
               // read the entire file into a char[]
  -            int fileLength = (int)(src.length());
  -            char[] tmpBuf = new char[fileLength];
  -            int numread = 0;
  +            //   size of work buffer may be bigger than needed
  +            //   when multibyte characters exist in the source file
  +            int fileLengthInBytes = (int)(src.length());
  +            char[] tmpBuf = new char[fileLengthInBytes];
  +            int readChar = 0;
               int totread = 0;
  -            while (numread != -1 && totread < fileLength) {
  -                numread = br.read(tmpBuf,totread,fileLength);
  -                totread += numread;
  +            while (true) {
  +                readChar = br.read();
  +                if (readChar < 0) { break; }
  +                tmpBuf[totread] = (char)readChar;
  +                totread++;
               }
   
               // create a String so we can use indexOf