org.apache.commons.codec.language.Caverphone1.java Source code

Java tutorial

Introduction

Here is the source code for org.apache.commons.codec.language.Caverphone1.java

Source

package org.apache.commons.codec.language;

import com.crumby.impl.crumby.UnsupportedUrlFragment;
import com.crumby.impl.danbooru.DanbooruImageFragment;
import com.crumby.impl.ehentai.HentaiSubGalleryFragment;
import java.util.Locale;

public class Caverphone1 extends AbstractCaverphone {
    private static final String SIX_1 = "111111";

    public String encode(String source) {
        String txt = source;
        if (txt == null || txt.length() == 0) {
            return SIX_1;
        }
        return (txt.toLowerCase(Locale.ENGLISH).replaceAll("[^a-z]", UnsupportedUrlFragment.DISPLAY_NAME)
                .replaceAll("^cough", "cou2f").replaceAll("^rough", "rou2f").replaceAll("^tough", "tou2f")
                .replaceAll("^enough", "enou2f").replaceAll("^gn", "2n").replaceAll("mb$", "m2")
                .replaceAll("cq", "2q").replaceAll("ci", "si").replaceAll("ce", "se").replaceAll("cy", "sy")
                .replaceAll("tch", "2ch").replaceAll("c", "k").replaceAll("q", "k").replaceAll("x", "k")
                .replaceAll("v", "f").replaceAll("dg", "2g").replaceAll("tio", "sio").replaceAll("tia", "sia")
                .replaceAll("d", "t").replaceAll("ph", "fh").replaceAll("b", "p").replaceAll("sh", "s2")
                .replaceAll("z", DanbooruImageFragment.BREADCRUMB_NAME).replaceAll("^[aeiou]", "A")
                .replaceAll("[aeiou]", "3").replaceAll("3gh3", "3kh3").replaceAll("gh", "22")
                .replaceAll(HentaiSubGalleryFragment.BREADCRUMB_NAME, "k").replaceAll("s+", "S")
                .replaceAll("t+", "T").replaceAll("p+", "P").replaceAll("k+", "K").replaceAll("f+", "F")
                .replaceAll("m+", "M").replaceAll("n+", "N").replaceAll("w3", "W3").replaceAll("wy", "Wy")
                .replaceAll("wh3", "Wh3").replaceAll("why", "Why").replaceAll("w", "2").replaceAll("^h", "A")
                .replaceAll("h", "2").replaceAll("r3", "R3").replaceAll("ry", "Ry").replaceAll("r", "2")
                .replaceAll("l3", "L3").replaceAll("ly", "Ly").replaceAll("l", "2").replaceAll("j", "y")
                .replaceAll("y3", "Y3").replaceAll("y", "2").replaceAll("2", UnsupportedUrlFragment.DISPLAY_NAME)
                .replaceAll("3", UnsupportedUrlFragment.DISPLAY_NAME) + SIX_1).substring(0, SIX_1.length());
    }
}