Android String Camel Case snakify(String original)

Here you can find the source of snakify(String original)

Description

snakify

Declaration

public static String snakify(String original) 

Method Source Code

//package com.java2s;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static String snakify(String original) {
        if (original == null || original.length() == 0)
            return "";

        StringBuilder builder = new StringBuilder();
        Pattern p = Pattern.compile("[A-Z][a-z0-9]+");
        Matcher m = p.matcher(original);
        String word;//from   w w w .j a  va  2  s. co m
        while (m.find()) {
            word = m.group();
            builder.append(word.toLowerCase());
            if (!m.hitEnd()) {
                builder.append('_');
            }
        }
        if (builder.length() == 0) {
            return original.toLowerCase();
        }
        return builder.toString();
    }
}

Related

  1. camelify(String original)
  2. decamelize(final String s)