Created
January 9, 2018 09:43
-
-
Save RanolP/163594eb3065d16e32642d57ddc5bbd3 to your computer and use it in GitHub Desktop.
for B4TT3RY
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Test { | |
abstract class Text { | |
protected String value; | |
public Text(String value) { | |
this.value = value; | |
} | |
public abstract String get(); | |
} | |
class OriginalText extends Text{ | |
public KoreanText(String value) { | |
super(value); | |
} | |
@Override | |
public String get() { | |
return value; | |
} | |
} | |
class KoreanText extends Text{ | |
public KoreanText(String value) { | |
super(value); | |
} | |
@Override | |
public String get() { | |
return YourKoreanUtil.translate(value); | |
} | |
} | |
// Function defination | |
public List<Text> parse(String source) { | |
private List<Text> result = new ArrayList<>(); | |
char[] chars = source.toCharArray(); | |
StringBuilder korean = new StringBuilder(); | |
StringBuilder original = new StringBuilder(); | |
boolean bracket = false; | |
for(int i=0; i<chars.length; i++) { | |
char c = chars[i]; | |
if(c == '[' && chars.length > i + 1 && chars[i+1] == '[') { | |
i++; | |
if(korean.getLength() > 0) { | |
result.add(new KoreanText(korean.toString())); | |
korean.setLength(0); | |
} | |
bracket = true; | |
continue; | |
} | |
if(c == ']' && chars.length > i + 1 && chars[i+1] == ']') { | |
i++; | |
if(original.getLength() > 0) { | |
result.add(new OriginalText(original.toString())); | |
original.setLength(0); | |
} | |
bracket = false; | |
continue; | |
} | |
if(bracket) { | |
original.append(c); | |
} else { | |
korean.append(c); | |
} | |
} | |
if(bracket && original.getLength() > 0) { | |
result.add(new OriginalText(original.toString())); | |
} else if(korean.getLength() > 0) { | |
result.add(new KoreanText(korean.toString())); | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
날코딩함 ㅅㄱ