[jbosstools-commits] JBoss Tools SVN: r43450 - in trunk/common: tests/org.jboss.tools.common.test/src/org/jboss/tools/common/test and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Wed Sep 5 20:50:31 EDT 2012


Author: dgolovin
Date: 2012-09-05 20:50:31 -0400 (Wed, 05 Sep 2012)
New Revision: 43450

Modified:
   trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/StringUtil.java
   trunk/common/tests/org.jboss.tools.common.test/src/org/jboss/tools/common/test/CommonAllTests.java
Log:
code cleanup and tests for common classes

Modified: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/StringUtil.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/StringUtil.java	2012-09-06 00:36:53 UTC (rev 43449)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/StringUtil.java	2012-09-06 00:50:31 UTC (rev 43450)
@@ -7,7 +7,7 @@
  * 
  * Contributors: 
  * Red Hat, Inc. - initial API and implementation 
- ******************************************************************************/ 
+ ******************************************************************************/
 
 package org.jboss.tools.common.util;
 
@@ -17,24 +17,28 @@
  * @author Victor V. Rubezhny
  */
 public class StringUtil {
-/**
+	
+	private static final char QUOT = '\"';
+	private static final char APO = '\'';
+
+	/**
 	 * Cuts of the starting and ending quotes from a given text value
 	 * 
-	 * @param Quoted text value
-	 * @return Non-quoted text value 
+	 * @param Quoted
+	 *            text value
+	 * @return Non-quoted text value
 	 */
-	public static String trimQuotes(String value) {
-		if(value == null)
-			return null;
+	public static String trimQuotes(String result) {
 
-		if(value.startsWith("'") || value.startsWith("\"")) {  //$NON-NLS-1$ //$NON-NLS-2$
-			value = value.substring(1);
-		} 
-		
-		if(value.endsWith("'") || value.endsWith("\"")) { //$NON-NLS-1$ //$NON-NLS-2$
-			value = value.substring(0, value.length() - 1);
+		int start = 0, end = result.length();
+		char first = result.charAt(start);
+		char last = result.charAt(end - 1);
+		if (first == APO || first == QUOT) {
+			start++;
 		}
-		return value;
+		if (last == APO || last == QUOT) {
+			end--;
+		}
+		return result.substring(start, end);
 	}
-
 }

Modified: trunk/common/tests/org.jboss.tools.common.test/src/org/jboss/tools/common/test/CommonAllTests.java
===================================================================
--- trunk/common/tests/org.jboss.tools.common.test/src/org/jboss/tools/common/test/CommonAllTests.java	2012-09-06 00:36:53 UTC (rev 43449)
+++ trunk/common/tests/org.jboss.tools.common.test/src/org/jboss/tools/common/test/CommonAllTests.java	2012-09-06 00:50:31 UTC (rev 43450)
@@ -17,6 +17,7 @@
 import org.jboss.tools.common.reporting.test.ProblemReportingHelperTest;
 import org.jboss.tools.common.util.test.BeanUtilTest;
 import org.jboss.tools.common.util.test.HttpUtilTest;
+import org.jboss.tools.common.util.test.StringUtilTest;
 import org.jboss.tools.common.xml.test.SAXValidatorTest;
 import org.jboss.tools.common.xml.test.XMLUtilitiesTest;
 import org.jboss.tools.common.zip.test.ZipAllTests;
@@ -36,6 +37,7 @@
 		suite.addTestSuite(MessagesTest.class);
 		suite.addTestSuite(MethodNotImplementedExceptionTest.class);
 		suite.addTestSuite(BeanUtilTest.class);
+		suite.addTestSuite(StringUtilTest.class);
 		return suite;
 	}
 }
\ No newline at end of file



More information about the jbosstools-commits mailing list