umagesh     2002/11/21 13:35:41

  Modified:    .        WHATSNEW
               src/main/org/apache/tools/ant/taskdefs/optional/i18n
                        Translate.java
  Log:
  Allow start and end tokens to be multiple characters long.
  
  PR: 13939
  
  Submitted by: "Don Brown" <[EMAIL PROTECTED]>
  
  Revision  Changes    Path
  1.325     +3 -0      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.324
  retrieving revision 1.325
  diff -u -r1.324 -r1.325
  --- WHATSNEW  20 Nov 2002 10:10:13 -0000      1.324
  +++ WHATSNEW  21 Nov 2002 21:35:40 -0000      1.325
  @@ -61,6 +61,9 @@
   
   Other changes:
   --------------
  +* The start and end tokens for <translate> may now be longer than a 
  +  single character.
  +
   * <setproxy> lets you set the username and password for proxies that want 
authentication
   
   * <loadproperties> has a new encoding attribute.
  
  
  
  1.17      +13 -23    
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java
  
  Index: Translate.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Translate.java    25 Jul 2002 15:21:15 -0000      1.16
  +++ Translate.java    21 Nov 2002 21:35:41 -0000      1.17
  @@ -74,7 +74,7 @@
   /**
    * Translates text embedded in files using Resource Bundle files.
    *
  - * @author Magesh Umasankar
  + * @author Magesh Umasankar, Don Brown
    */
   public class Translate extends MatchingTask {
   
  @@ -256,23 +256,11 @@
                                        getLocation());
           }
   
  -        if (startToken.length() != 1) {
  -            throw new BuildException(
  -                "The starttoken attribute must be a single character.",
  -                getLocation());
  -        }
  -
           if (endToken == null) {
               throw new BuildException("The endtoken attribute must be set.",
                                        getLocation());
           }
   
  -        if (endToken.length() != 1) {
  -            throw new BuildException(
  -                "The endtoken attribute must be a single character.",
  -                getLocation());
  -        }
  -
           if (bundleLanguage == null) {
               Locale l = Locale.getDefault();
               bundleLanguage  = l.getLanguage();
  @@ -391,7 +379,7 @@
        */
       private void processBundle(final String bundleFile, final int i,
                                  final boolean checkLoaded) throws 
BuildException {
  -        final File propsFile = new File(bundleFile + ".properties");
  +        final File propsFile = getProject().resolveFile(bundleFile + 
".properties");
           FileInputStream ins = null;
           try {
               ins = new FileInputStream(propsFile);
  @@ -520,23 +508,25 @@
                           BufferedReader in
                               = new BufferedReader(new InputStreamReader(fis, 
srcEncoding));
                           String line;
  +                        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 + 1);
  +                                startIndex = line.indexOf(startToken, 
endIndex + etLength);
                                   if (startIndex < 0 ||
  -                                    startIndex + 1 >= line.length()) {
  +                                    startIndex + stLength >= line.length()) {
                                       break;
                                   }
  -                                endIndex = line.indexOf(endToken, startIndex 
+ 1);
  +                                endIndex = line.indexOf(endToken, startIndex 
+ stLength);
                                   if (endIndex < 0) {
                                       break;
                                   }
  -                                String matches = line.substring(startIndex + 
1,
  +                                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.
  +                                //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 == ':' ||
  @@ -558,9 +548,9 @@
                                   }
                                   line = line.substring(0, startIndex)
                                       + replace
  -                                    + line.substring(endIndex + 1);
  -                                endIndex = startIndex + replace.length() + 1;
  -                                if (endIndex + 1 >= line.length()) {
  +                                    + line.substring(endIndex + etLength);
  +                                endIndex = startIndex + replace.length() + 
etLength;
  +                                if (endIndex + etLength >= line.length()) {
                                       break;
                                   }
                               }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to