From 150a9d0475fd1e4fc86b3000ba1b9c99e6511a30 Mon Sep 17 00:00:00 2001 From: Avik Sengupta Date: Thu, 28 Apr 2005 14:03:28 +0000 Subject: [PATCH] Refactored git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353656 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hssf/record/FooterRecord.java | 17 +---------- .../apache/poi/hssf/record/HeaderRecord.java | 18 +----------- src/java/org/apache/poi/util/StringUtil.java | 28 +++++++++++++++++++ 3 files changed, 30 insertions(+), 33 deletions(-) diff --git a/src/java/org/apache/poi/hssf/record/FooterRecord.java b/src/java/org/apache/poi/hssf/record/FooterRecord.java index 06a1497e8..7926d6446 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 9af6297f8..684e26090 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 cf84496ac..6de79210a 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; + } + } }