Analysis of the Unicode entity encoding and conversion code by using corner stone

Source: Internet
Author: User

This article briefly introduces the code for converting the unicode entity encoding of html by using corner stone. When developing a browser using corner stone, we need to convert the unicode entity encoding of html to display it normally.

How to convert the unicode entity encoding in html by using corner stone

During the development of the j2's browser, we need to convert the unicode entity encoding of html for normal display. See the following code:

 
 
  1. <Ahrefahref = "http://wap.monternet.com/"> back to mxnet </a> <br/>
  2.  

The method is as follows:

 
 
  1. PrivatestaticStringdecodeUnicode (finalStringdataStr ){
  2. Intstart = 0;
  3. Intend = 0;
  4. FinalStringBufferbuffer = newStringBuffer ();
  5. While (start>-1 ){
  6. Intsystem = 10; // hexadecimal
  7. If (start = 0 ){
  8. Intt = dataStr. indexOf ("&#");
  9. If (start! = T) start = t;
  10. }
  11. End = dataStr. indexOf (";", start + 2 );
  12. StringcharStr = "";
  13. If (end! =-1 ){
  14. CharStr = dataStr. substring (start + 2, end );
  15.  
  16. // Judge the base
  17. Chars = charStr. charAt (0 );
  18. If (s = 'X' | s = 'X '){
  19. System = 16;
  20. CharStrcharStr = charStr. substring (1 );
  21. }
  22. }
  23. // Conversion
  24. Try {
  25. Charletter = (char) Integer. parseInt (charStr, system );
  26. Buffer. append (newCharacter (letter). toString ());
  27. } Catch (numberformateffectione ){
  28. E. printStackTrace ();
  29. }
  30.  
  31. // Process non-unicode characters between the current unicode Character and the next unicode Character
  32. Start = dataStr. indexOf ("& #", end );
  33. If (start-end> 1 ){
  34. Buffer. append (dataStr. substring (end + 1, start ));
  35. }
  36.  
  37. // Process the last non-unicode Character
  38. If (start =-1 ){
  39. Intlength = dataStr. length ();
  40. If (end + 1! = Length ){
  41. Buffer. append (dataStr. substring (end + 1, length ));
  42. }
  43. }
  44. }
  45. Returnbuffer. toString ();
  46. }
  47.  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.