Java I18n and Unicode - PowerPoint PPT Presentation

About This Presentation
Title:

Java I18n and Unicode

Description:

But what about when you are talking to someone else? Different ... Pattern.compile (pattern, CANON_EQ); http://www.regular-expressions.info/unicode.html ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 6
Provided by: Goog606
Category:
Tags: compile | i18n | java | unicode

less

Transcript and Presenter's Notes

Title: Java I18n and Unicode


1
Java I18n and Unicode
  • JaxJug lightning talk
  • 4/15/09

2
Java I18n   
  • Native support for Unicode
  • Localization
  • Create properties files
  • Locale object
  • ResourceBundles
  • Other locale-dependent data

3
Issues
  • But what about when you are talking to someone
    else?
  • Different encodings
  • BE and LE
  • String s new String(buffer, "UTF8")
  • s.getBytes("UTF8")
  • public String parseMessage(byte buffer)
  •       StringBuffer buffer new StringBuffer()
  •       try
  •           InputStreamReader is  new InputStreamRe
    ader(new ByteArrayInputStream(buffer), "UTF-16LE")
    )
  •           BufferedReader br new
    BufferedReader(is)
  •           int ch
  •           while ((ch br.read() ! -1)
  •               buffer.append((char)ch)
  •           
  •           br.close()
  •           return buffer.toString()
  •         catch (IOException e)
  •           e.printStackTrace()

4
Converting Unicode
  • import java.io.
  • public class UnicodeFormatter
  • static public String byteToHex(byte b)
  • // Returns hex String representation of byte b
  • char hexDigit
  • '0', '1', '2', '3', '4', '5', '6', '7',
  • '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
  • char array hexDigit(b gtgt 4) 0x0f,
  • hexDigitb 0x0f
  • return new String(array)
  • static public String charToHex(char c)
  • // Returns hex String representation of char c
  • byte hi (byte) (c gtgtgt 8)
  • byte lo (byte) (c 0xff)
  • return byteToHex(hi) byteToHex(lo)

5
Regular Expressions and Unicode
  • What is a character?
  • Ñ  
  • \u00F1 
  • OR 
  • \u006E \u0303
  • Matching graphemes - .
  • Canonical equivalence
  • Pattern.compile (pattern, CANON_EQ)
  • http//www.regular-expressions.info/unicode.html
Write a Comment
User Comments (0)
About PowerShow.com