- Timestamp:
- 11/18/09 02:34:38 (4 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/java/misc/hatenahaiku4j/branches/for-HTML-scraping/src/hatenahaiku4j/util/StringUtil.java
r35871 r35940 43 43 * @param str URLEncodeする文字列 44 44 * @return エンコードされた文字列 45 * @see <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLEncoder.html">http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLEncoder.html</a> 45 46 * @since v1.0.0 46 47 */ … … 48 49 String encoded = ""; 49 50 try { 50 // UTF-8でエンコードしてから半角スペース(+)を%20に変換する 51 encoded = URLEncoder.encode(str, Const.UTF8).replaceAll("\\+", "%20"); 52 } catch ( UnsupportedEncodingException e ) { 51 // UTF-8でエンコードしてから 52 // 「+」を「%20」に(半角スペース)、 53 // 「.」を「%2E」に、 54 // 「-」を「%2D」に、 55 // 「*」を「%2A」に、 56 // 「_」を「%5F」に変換する。 57 encoded = URLEncoder.encode(str, Const.UTF8) 58 .replaceAll("\\+", urlEncodeOther(" ")) 59 .replaceAll("\\.", urlEncodeOther(".")) 60 .replaceAll("-", urlEncodeOther("-")) 61 .replaceAll("\\*", urlEncodeOther("*")) 62 .replaceAll("_", urlEncodeOther("_")) 63 ; 64 } catch (UnsupportedEncodingException e) { 53 65 // ignore it 54 66 } 55 67 return encoded; 68 } 69 70 /** 71 * {@link URLEncoder#encode(String, String)}にて変換してくれない文字をエンコードする。 72 * 73 * @param str エンコードする文字列 74 * @since v1.1.4 75 * @return 変換後の文字列 76 */ 77 private static String urlEncodeOther(String str) { 78 try { 79 return "%" + String.format("%02x", str.getBytes(Const.UTF8)[0]).toUpperCase(); 80 } catch (UnsupportedEncodingException e) { 81 // ignore it 82 } 83 return ""; 56 84 } 57 85
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)