Understanding old JAVA code

Asked

Viewed 35 times

1

I have a code here at the company and I need to understand what it really does. By the method Name I found that it removed the characters outside the UTF-8 pattern or something like that, giving an analysis I saw that it does not exactly anything in the string I step. I need someone to explain to me what this code really does or give me some hint about it so I can judge whether I remove or create something better.

public static String replaceUTF8(String text) {
    String[] REPLACES = {"a", "e", "i", "o", "u", "c"};
    Pattern[] PATTERNS = new Pattern[REPLACES.length];
    PATTERNS[0] = Pattern.compile("[?????]", Pattern.CASE_INSENSITIVE);
    PATTERNS[1] = Pattern.compile("[????]", Pattern.CASE_INSENSITIVE);
    PATTERNS[2] = Pattern.compile("[????]", Pattern.CASE_INSENSITIVE);
    PATTERNS[3] = Pattern.compile("[?????]", Pattern.CASE_INSENSITIVE);
    PATTERNS[4] = Pattern.compile("[????]", Pattern.CASE_INSENSITIVE);
    PATTERNS[5] = Pattern.compile("[?]", Pattern.CASE_INSENSITIVE);
    String result = text;
    for (int i = 0; i < PATTERNS.length; i++) {
        Matcher matcher = PATTERNS[i].matcher(result);
        result = matcher.replaceAll(REPLACES[i]);
    }
    return result;
}

NOTE : It is an old code and is used in various places of the system, I need to really understand why of existence and if it will not affect if I remove or modify it.

  • Are these questions correct? There is no point to something like this.

  • As @Gustavocinque said, there is no point. I believe they had the lyrics áéíóúç inside these regex and the programmer decided to ignore this method by simply changing regex to ?. The only thing this method does is to transform the ? in a, something like.

  • That’s exactly it, the code changes all the ?for a and does nothing else... What a thing, no?

  • Thanks for the help, I think that was really it, the programmer when he decided to leave the method aside just put the questions, funny ? the problem is that it is called on the whole system = loss of performance

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.