|
| 1 | +/* |
| 2 | + * Copyright 2016 DiffPlug |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.diffplug.spotless.cpp; |
| 17 | + |
| 18 | +import java.util.Arrays; |
| 19 | +import java.util.Collections; |
| 20 | +import java.util.List; |
| 21 | +import java.util.stream.Collectors; |
| 22 | + |
| 23 | +/** Common utilities for C/C++ */ |
| 24 | +public class CppDefaults { |
| 25 | + //Prevent instantiation |
| 26 | + private CppDefaults() {}; |
| 27 | + |
| 28 | + public static final List<String> FILE_FILTER = Collections.unmodifiableList( |
| 29 | + Arrays.asList("c", "h", "C", "cpp", "cxx", "cc", "c++", "h", "hpp", "hh", "hxx", "inc") |
| 30 | + .stream().map(s -> { |
| 31 | + return "**/*." + s; |
| 32 | + }).collect(Collectors.toList())); |
| 33 | + |
| 34 | + /** |
| 35 | + * Default delimiter expression shall cover most valid and common starts of C/C++ declarations and definitions. |
| 36 | + * Furthermore it shall not conflict with terms commonly used within license headers. |
| 37 | + * Note that the longest match is selected. Hence "using namespace foo" is preferred over "namespace foo". |
| 38 | + */ |
| 39 | + public static final String DELIMITER_EXPR = Arrays.asList( |
| 40 | + "#define", "#error", "#if", "#ifdef", "#ifndef", "#include", "#pragma", "#undef", |
| 41 | + "asm", "class", "namespace", "struct", "typedef", "using namespace", |
| 42 | + "const", "extern", "mutable", "signed", "unsigned", "volatile", |
| 43 | + "auto", "char", "double", "float", "int", "long", "void", |
| 44 | + "char16_t", "char32_t", "char64_t", |
| 45 | + "int8_t", "int16_t", "int32_t", "int64_t", |
| 46 | + "__int8_t", "__int16_t", "__int32_t", "__int64_t", |
| 47 | + "uint8_t", "uint16_t", "uint32_t", "uint64_t") |
| 48 | + .stream().map(s -> { |
| 49 | + return "(?<![0-9a-zA-Z]+)" + s.replaceAll("#", "\\\\#").replaceAll(" ", "[\\\\n\\\\s]+") + "[\\*\\s\\n]+"; |
| 50 | + }).collect(Collectors.joining("|")); |
| 51 | + |
| 52 | +} |
0 commit comments