Java String Normalize normalizeRepositoryName(String input)

Here you can find the source of normalizeRepositoryName(String input)

Description

normalize Repository Name

License

Apache License

Declaration

public static String normalizeRepositoryName(String input) 

Method Source Code


//package com.java2s;
/*//from   ww  w .  j  ava  2 s  .c om
 * Copyright 2015 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.text.Normalizer;

import java.util.regex.Pattern;

public class Main {
    private static final String EMPTY_STRING = "";
    private static final Pattern repoP1 = Pattern.compile("[^\\p{L}\\p{Nd}\\x2D\\x2E]");
    private static final Pattern repoP2 = Pattern.compile("[^\\x00-\\x7f\\x2D\\x2E]");
    private static final Pattern repoP3 = Pattern.compile("[\\x2D\\x2E][\\x2D\\x2E]{1,}+");

    public static String normalizeRepositoryName(String input) {
        // Remove leading and/or trailing '.' and '-'
        if (input.startsWith(".") || input.startsWith("-"))
            input = normalizeRepositoryName(input.substring(1));
        if (input.endsWith(".") || input.endsWith("-"))
            input = normalizeRepositoryName(input.substring(0, input.length() - 1));
        // Repository operations are not too frequent so instantiate corresponding matchers on demand
        return repoP3.matcher(repoP2
                .matcher(repoP1.matcher(Normalizer.normalize(input, Normalizer.Form.NFD)).replaceAll(EMPTY_STRING))
                .replaceAll(EMPTY_STRING)).replaceAll(EMPTY_STRING);
    }
}

Related

  1. normalizeEnglishIdentifier(String id)
  2. normalizeFieldNameOrPath(final String nameOrPath)
  3. normalizeIndex(String input, String[] indexList)
  4. normalizeMatchup(final String matchup)
  5. normalizePackageNamePart(String name)
  6. normalizeSearchString(String src)
  7. normalizeString(String input)
  8. normalizeString(String str)
  9. normalizeString(String token)