ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build NameUtil.java
Date Mon, 10 Jun 2002 06:31:06 GMT
donaldp     2002/06/09 23:31:06

  Added:       buildtools/src/java/org/apache/myrmidon/build NameUtil.java
  Log:
  Add start of utility class in
  
  Revision  Changes    Path
  1.1                  jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/NameUtil.java
  
  Index: NameUtil.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.myrmidon.build;
  
  /**
   * A Utility class for working with names and converting between
   * "styles" (ie CamelCase to xml-style etc). Some examples of different
   * styles follow;
   *
   * <p><b>CamelCase</b>: thisIsCamelCase, noticeThatTheres, HumpsInDaWords</p>
   * <p><b>Xml-style</b>: this-is-xml-style, notice-lots-of-dashes</p>
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/10 06:31:06 $
   */
  public class NameUtil
  {
      /**
       * Private constructor to block insantiation.
       */
      private NameUtil()
      {
      }
  
      /**
       * Strip a postfix if it is present.
       * Case is ignored when checking postfix.
       *
       * @param value the initial string value
       * @param postfix the postfix to strip if present
       * @return the string value sans postfix (if present)
       */
      public static String stripPostfix( final String value,
                                         final String postfix )
      {
          final String ucValue = value.toUpperCase();
          final String ucPostfix = postfix.toUpperCase();
          if( ucValue.endsWith( ucPostfix ) )
          {
              final int size = postfix.length();
              return value.substring( 0, size );
          }
          else
          {
              return value;
          }
      }
  
      /**
       * Convert string from CamelCase to XML style.
       *
       * @param value the camel case string
       * @return the xml-style string
       */
      public static String toXMLStyle( final String value )
      {
          final int size = value.length();
          final StringBuffer sb = new StringBuffer( (int)(size * 1.5) );
  
          for( int i = 0; i < size; i++ )
          {
              final char ch = value.charAt( i );
              if( Character.isUpperCase( ch ) )
              {
                  sb.append( '-' );
                  sb.append( Character.toLowerCase( ch ) );
              }
              else
              {
                  sb.append( ch );
              }
          }
  
          return sb.toString();
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message