Skip to content

Instantly share code, notes, and snippets.

@RanolP
Created January 9, 2018 09:43
Show Gist options
  • Save RanolP/163594eb3065d16e32642d57ddc5bbd3 to your computer and use it in GitHub Desktop.
Save RanolP/163594eb3065d16e32642d57ddc5bbd3 to your computer and use it in GitHub Desktop.
for B4TT3RY
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;
}
}
@RanolP
Copy link
Author

RanolP commented Jan 9, 2018

날코딩함 ㅅㄱ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment