001
014
015 package com.liferay.portal.kernel.util;
016
017
020 public class CSVUtil {
021
022 public static String encode(Object obj) {
023 return encode(String.valueOf(obj));
024 }
025
026 public static String encode(String s) {
027 if (s == null) {
028 return null;
029 }
030
031 if ((s.indexOf(CharPool.COMMA) < 0) &&
032 (s.indexOf(CharPool.QUOTE) < 0) &&
033 (s.indexOf(CharPool.NEW_LINE) < 0) &&
034 (s.indexOf(CharPool.RETURN) < 0)) {
035
036 return s;
037 }
038
039 s = StringUtil.replace(s, StringPool.QUOTE, StringPool.DOUBLE_QUOTE);
040
041 return StringPool.QUOTE.concat(s.concat(StringPool.QUOTE));
042 }
043
044 }