[cvs] expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc StringUtil.java

JCorporate Ltd jcorp at jcorp2.servlets.net
Sat Jun 5 20:10:42 PDT 2004


Update of /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc
In directory jcorp2.servlets.net:/tmp/cvs-serv10842/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc

Modified Files:
	StringUtil.java 
Log Message:
add unquote() feature


Index: StringUtil.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc/StringUtil.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** StringUtil.java	22 May 2004 00:44:19 -0000	1.25
--- StringUtil.java	6 Jun 2004 03:10:39 -0000	1.26
***************
*** 1469,1471 ****
--- 1469,1499 ----
      }
  
+     /**
+      * remove surrounding quote marks (either "" or ''), only if quotes are at both the beginning and end of the string
+      * @param s string for testing
+      * @return string which has surrounding quotes, if any, removed
+      */
+     public static String unquote(String s) {
+         String result = s;
+         if ( startsAndEnds(s, "\"") || startsAndEnds(s, "'") ) {
+             result = s.substring(1, s.length() - 1);
+         }
+ 
+         return result;
+     }
+ 
+ 
+     /**
+      * determine whether a string both starts and ends with the given substring
+      * @param s string to look at
+      * @param search substring to search for
+      * @return true if string is surrounded by search string
+ 
+      */
+     public static boolean startsAndEnds(String s, String search) {
+         if ( s!= null && s.length() >= 2 && s.startsWith(search) && s.endsWith(search)) return true;
+ 
+         return false;
+     }
+ 
  } /* StringUtil */



More information about the cvs mailing list