From: Avik Sengupta Date: Thu, 28 Apr 2005 14:03:28 +0000 (+0000) Subject: Refactored X-Git-Tag: BEFORE_RICHTEXT~111 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=578f37b196a8ce7a88aa3f93f06f1829023408d3;p=poi.git Refactored git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353656 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hssf/record/FooterRecord.java b/src/java/org/apache/poi/hssf/record/FooterRecord.java index 06a1497e8b..7926d64467 100644 --- a/src/java/org/apache/poi/hssf/record/FooterRecord.java +++ b/src/java/org/apache/poi/hssf/record/FooterRecord.java @@ -107,21 +107,6 @@ public class FooterRecord return ((field_2_unicode_flag & 0xFF) == 1); } - /** - * check the parameter has multibyte character - * - * @param value string to check - * @return boolean result - * true:string has at least one multibyte character - */ - private static boolean hasMultibyte(String value){ - if( value == null )return false; - for(int i = 0 ; i < value.length() ; i++ ){ - char c = value.charAt(i); - if(c > 0xFF )return true; - } - return false; - } /** * set the length of the footer string @@ -146,7 +131,7 @@ public class FooterRecord { field_3_footer = footer; field_2_unicode_flag = - (byte) (hasMultibyte(field_3_footer) ? 1 : 0); + (byte) (StringUtil.hasMultibyte(field_3_footer) ? 1 : 0); } /** diff --git a/src/java/org/apache/poi/hssf/record/HeaderRecord.java b/src/java/org/apache/poi/hssf/record/HeaderRecord.java index 9af6297f8b..684e260908 100644 --- a/src/java/org/apache/poi/hssf/record/HeaderRecord.java +++ b/src/java/org/apache/poi/hssf/record/HeaderRecord.java @@ -107,22 +107,6 @@ public class HeaderRecord return ((field_2_unicode_flag & 0xFF) == 1); } - /** - * check the parameter has multibyte character - * - * @param value string to check - * @return boolean result - * true:string has at least one multibyte character - */ - private static boolean hasMultibyte(String value){ - if( value == null )return false; - for(int i = 0 ; i < value.length() ; i++ ){ - char c = value.charAt(i); - if(c > 0xFF )return true; - } - return false; - } - /** * set the length of the header string * @@ -146,7 +130,7 @@ public class HeaderRecord { field_3_header = header; field_2_unicode_flag = - (byte) (hasMultibyte(field_3_header) ? 1 : 0); + (byte) (StringUtil.hasMultibyte(field_3_header) ? 1 : 0); } /** diff --git a/src/java/org/apache/poi/util/StringUtil.java b/src/java/org/apache/poi/util/StringUtil.java index cf84496ac7..6de79210a1 100644 --- a/src/java/org/apache/poi/util/StringUtil.java +++ b/src/java/org/apache/poi/util/StringUtil.java @@ -303,4 +303,32 @@ public class StringUtil { public static String getPreferredEncoding() { return ENCODING; } + + /** + * check the parameter has multibyte character + * + * @param value string to check + * @return boolean result + * true:string has at least one multibyte character + */ + public static boolean hasMultibyte(String value){ + if( value == null )return false; + for(int i = 0 ; i < value.length() ; i++ ){ + char c = value.charAt(i); + if(c > 0xFF )return true; + } + return false; + } + + /** + * @param format + * @return true if format is Unicode. + */ + public static boolean isUnicodeFormat(final String format) { + try { + return !format.equals(new String(format.getBytes("ISO-8859-1"), "ISO-8859-1")); + } catch (UnsupportedEncodingException e) { + return true; + } + } }