Index: src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java =================================================================== RCS file: /home/cvspublic/ant/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java,v retrieving revision 1.20 diff -u -r1.20 Translate.java --- src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java 10 Feb 2003 14:14:05 -0000 1.20 +++ src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java 25 Jun 2003 16:14:56 -0000 @@ -510,49 +510,65 @@ int stLength = startToken.length(); int etLength = endToken.length(); while ((line = in.readLine()) != null) { - int startIndex = -1; - int endIndex = -1; -outer: while (true) { - startIndex = line.indexOf(startToken, endIndex + etLength); - if (startIndex < 0 || - startIndex + stLength >= line.length()) { - break; - } - endIndex = line.indexOf(endToken, startIndex + stLength); - if (endIndex < 0) { - break; - } - String matches = line.substring(startIndex + stLength, - endIndex); - //If there is a white space or = or :, then - //it isn't to be treated as a valid key. - for (int k = 0; k < matches.length(); k++) { - char c = matches.charAt(k); - if (c == ':' || - c == '=' || - Character.isSpaceChar(c)) { - endIndex = endIndex - 1; - continue outer; - } - } - String replace = null; - replace = (String) resourceMap.get(matches); - //If the key hasn't been loaded into resourceMap, - //use the key itself as the value also. - if (replace == null) { - log("Warning: The key: " + matches - + " hasn't been defined.", - Project.MSG_DEBUG); - replace = matches; - } - line = line.substring(0, startIndex) - + replace - + line.substring(endIndex + etLength); - endIndex = startIndex + replace.length() + etLength; - if (endIndex + etLength >= line.length()) { - break; - } - } + // 2003-02-21 new replace algorithme by tbee (tbee@tbee.org) + // because it wasn't able to replace something like "@aaa;@bbb;" + + // is there a startToken + // and there is still stuff following the startToken + int startIndex = line.indexOf(startToken); + while ( startIndex >= 0 && (startIndex+startToken.length()) <= line.length() ) + { + // the new value, this needs to be here + // because it is required to calculate the next position to search from + // at the end of the loop + String replace = null; + + // we found a starttoken, is there an endtoken following? + // start at token+tokenlength because start and end token may be indentical + int endIndex = line.indexOf(endToken, startIndex + startToken.length()); + if (endIndex < 0) startIndex += 1; + else + { + // grab the token + String token = line.substring(startIndex + startToken.length(), endIndex); + + // If there is a white space or = or :, then + // it isn't to be treated as a valid key. + boolean validToken = true; + for (int k = 0; k < token.length() && validToken; k++) + { + char c = token.charAt(k); + if ( c == ':' + || c == '=' + || Character.isSpaceChar(c) + ) + { + validToken = false; + } + } + if (!validToken) startIndex += 1; + else + { + // find the replace string + if (resourceMap.containsKey(token)) replace = (String)resourceMap.get(token); + else replace = token; + + + // generate the new line + line = line.substring(0, startIndex) + + replace + + line.substring(endIndex + endToken.length()); + + // set start position for next search + startIndex += replace.length(); + } + } + + // find next starttoken + startIndex = line.indexOf(startToken, startIndex); + } + + out.write(line); out.newLine(); }