MCPcopy Create free account
hub / github.com/DiUS/java-faker / FakerIDN

Class FakerIDN

src/main/java/com/github/javafaker/service/FakerIDN.java:8–32  ·  view source on GitHub ↗

Created by tshick on 10/30/16.

Source from the content-addressed store, hash-verified

6 * Created by tshick on 10/30/16.
7 */
8public class FakerIDN {
9 /**
10 * {@link IDN#toASCII(String)} is too picky for our needs. It was throwing exceptions for fa.yml and
11 * he.yml as they're Bidi languages and something was causing them to die. This is kind of a brute force
12 * fix but it appears to fix the issue.
13 */
14 public static final String toASCII(String in) {
15 try {
16 return IDN.toASCII(in);
17 } catch (Exception e) {
18 // let's continue with the character by character encoding hack.
19 }
20 final StringBuilder sb = new StringBuilder();
21 for (int i=0;i<in.length();i++) {
22 try {
23 sb.append(IDN.toASCII(in.substring(i, i + 1)));
24 }
25 catch (Exception e) {}
26 }
27 if (sb.length() == 0) {
28 throw new RuntimeException("Unable to convert " + in + " to ASCII");
29 }
30 return sb.toString();
31 }
32}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected