2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.common;
10 import com.google.common.annotations.Beta;
11 import com.google.common.base.CharMatcher;
12 import java.util.AbstractMap.SimpleEntry;
13 import java.util.Map.Entry;
14 import org.eclipse.jdt.annotation.NonNullByDefault;
15 import org.eclipse.jdt.annotation.Nullable;
18 * Utility class for handling various naming conventions mentioned in YANG and related specifications.
20 * @author Robert Varga
24 public final class YangNames {
26 * A {@link CharMatcher} matching the first character of a YANG {@code identifier} ABNF production,
27 * {@code (ALPHA / "_")}.
29 public static final CharMatcher IDENTIFIER_START =
30 CharMatcher.inRange('A', 'Z').or(CharMatcher.inRange('a', 'z').or(CharMatcher.is('_'))).precomputed();
32 * A {@link CharMatcher} NOT matching second and later characters of a YANG {@code identifier} ABNF production,
33 * {@code (ALPHA / DIGIT / "_" / "-" / ".")}.
35 public static final CharMatcher NOT_IDENTIFIER_PART =
36 IDENTIFIER_START.or(CharMatcher.inRange('0', '9')).or(CharMatcher.anyOf("-.")).negate().precomputed();
43 * Parse a file name according to rules outlined in https://tools.ietf.org/html/rfc6020#section-5.2. Input string
44 * should be the base path with file extension stripped.
46 * @param baseName file base name
47 * @return A tuple containing the module name and parsed revision, if present.
48 * @throws NullPointerException if {@code baseName} is null
50 public static Entry<String, @Nullable String> parseFilename(final String baseName) {
51 final int zavinac = baseName.lastIndexOf('@');
53 return new SimpleEntry<>(baseName, null);
56 return new SimpleEntry<>(baseName.substring(0, zavinac), baseName.substring(zavinac + 1));