Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.*;

public class Main {
    private static final Map<Character, Character> H2Z = new HashMap<Character, Character>();

    public static String toZenkakuCase(String str) {
        int f = str.length();
        StringBuilder buffer = new StringBuilder(str);

        for (int i = 0; i < f; i++) {
            char c = str.charAt(i);

            if (H2Z.containsKey(c)) {
                buffer.setCharAt(i, H2Z.get(c));
            } else if (c == 0x0020) {
                buffer.setCharAt(i, '\u3000');
            } else if (c <= 0x007E && 0x0021 <= c) {
                buffer.setCharAt(i, (char) (c + 0xFEE0));
            }

            if ((0x304B <= c && c <= 0x3062 && (c % 2 == 1)) || (0x30AB <= c && c <= 0x30C2 && (c % 2 == 1))
                    || (0x3064 <= c && c <= 0x3069 && (c % 2 == 0))
                    || (0x30C4 <= c && c <= 0x30C9 && (c % 2 == 0))) {
                char d = buffer.charAt(i + 1);
                buffer.setCharAt(i, (char) (c + ((d == '\u309B') ? 1 : 0)));
                if (c != buffer.charAt(i)) {
                    buffer = buffer.deleteCharAt(i + 1);
                    f--;
                }
                continue;
            }

            if ((0x306F <= c && c <= 0x307D && (c % 3 == 0)) || (0x30CF <= c && c <= 0x30DD && (c % 3 == 0))) {
                char d = buffer.charAt(i + 1);
                buffer.setCharAt(i, (char) (c + ((d == '\u309B') ? 1 : ((d == '\u309C') ? 2 : 0))));
                if (c != buffer.charAt(i)) {
                    buffer = buffer.deleteCharAt(i + 1);
                    f--;
                }
                continue;
            }

        }

        return buffer.toString();
    }
}