Browse Source

Make <replace> work for multibyte character sets.

PR: 1208
Submitted by:	AKIMOTO, Hiroki <akky@bigfoot.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269005 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 24 years ago
parent
commit
f8f5fb01a4
1 changed files with 10 additions and 6 deletions
  1. +10
    -6
      src/main/org/apache/tools/ant/taskdefs/Replace.java

+ 10
- 6
src/main/org/apache/tools/ant/taskdefs/Replace.java View File

@@ -285,13 +285,17 @@ public class Replace extends MatchingTask {
BufferedWriter bw = new BufferedWriter(new FileWriter(temp)); BufferedWriter bw = new BufferedWriter(new FileWriter(temp));


// read the entire file into a char[] // 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; 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 // create a String so we can use indexOf


Loading…
Cancel
Save