You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by Avik Sengupta <av...@itellix.com> on 2005/04/28 16:11:19 UTC

Detect unicode

We currently have two methods to detect unicode characters. Which is
better? Primarily on performance. I want to consolidated. There might be
other such code scattered! 

	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;
	}
	
	 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;
	    }
	  }
-- 


---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/


Re: Detect unicode

Posted by an...@superlinksoftware.com.
I'm betting on the latter.  I think the former is legacy code from when 
we supported 1.22 or something.

Avik Sengupta wrote:
> We currently have two methods to detect unicode characters. Which is
> better? Primarily on performance. I want to consolidated. There might be
> other such code scattered! 
> 
> 	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;
> 	}
> 	
> 	 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;
> 	    }
> 	  }


---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/