All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openbase.jul.processing.StringProcessor Maven / Gradle / Ivy

package org.openbase.jul.processing;

/*
 * #%L
 * JUL Processing
 * %%
 * Copyright (C) 2015 - 2018 openbase.org
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * .
 * #L%
 */

import java.io.File;

/**
 *
 * * @author Divine Divine
 */
public class StringProcessor {

    public enum Alignment {
        LEFT,
        CENTER,
        RIGHT
    }

    public static String insertSpaceBetweenCamelCase(String input) {
        String output = "";
        String[] split = input.split("(? 0; i--) {
            spaces += " ";
        }
        switch (textAlignment) {
            case RIGHT:
                return spaces + input;
            case CENTER:
                final int half_spaces_size = (lenght - input.length()) / 2;
                return spaces.substring(0, half_spaces_size - 1) + input + spaces.substring(half_spaces_size, spaces.length());
            case LEFT:
            default:
                return input + spaces;
        }
    }

    public static String transformToIdString(String input) {
        input = removeDoubleWhiteSpaces(input);
        input = input.replaceAll("ä", "ae");
        input = input.replaceAll("ö", "oe");
        input = input.replaceAll("ü", "ue");
        input = input.replaceAll("ß", "ss");
        input = input.replaceAll("[^0-9a-zA-Z-_]+", "_");

        // cleanup
        input = input.replaceAll("[_]+", "_");
        if (input.startsWith("_")) {
            input = input.substring(1, input.length());
        }
        if (input.endsWith("_")) {
            input = input.substring(0, input.length() - 1);
        }
        return input;
    }

    /**
     * Method normalizes a string into a simple file name by removing duplicated path limiters.
     * @param filename the file name origin
     * @return the normalized file name.
     */
    public static String transformToNormalizedFileName(final String filename) {
        return new File(filename).getPath();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy