<commit_before>package utils

/*
 * Copyright (c) 2009-2018. Authors: see NOTICE file.
 *
 * Licensed under the GNU Lesser General Public License, Version 2.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.gnu.org/licenses/lgpl-2.1.txt
 *
 * 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.
 */

/**
 * User: lrollus
 * Date: 17/10/12
 * GIGA-ULg
 * Utility class to deals with file
 */
class FilesUtils {

    /**
     * Get the extension of a filename
     */
    public static def getExtensionFromFilename = {filename ->
        def returned_value = ""
        def m = (filename =~ /(\.[^\.]*)$/)
        if (m.size() > 0) returned_value = ((m[0][0].size() > 0) ? m[0][0].substring(1).trim().toLowerCase() : "");
        return returned_value
    }

    /**
     * Convert the current filename to a valide filename (without bad char like '@','+',...)
     * All bad char are replaced with '_'
     * @param file File
     * @return Correct filename for this file
     */
    public static String correctFileName(def originalFilename) {
        String newFilename = originalFilename
        newFilename = newFilename.replace(" ", "_")
        newFilename = newFilename.replace("(", "_")
        newFilename = newFilename.replace(")", "_")
        newFilename = newFilename.replace("+", "_")
        newFilename = newFilename.replace("*", "_")
        newFilename = newFilename.replace("/", "_")
        newFilename = newFilename.replace("@", "_")
        newFilename = newFilename.replace("'", "_")
        newFilename = newFilename.replace('"', "_")
        newFilename = newFilename.replace('$', "_")
        newFilename = newFilename.replace('€', "_")
        newFilename = newFilename.replace('£', "_")
        newFilename = newFilename.replace('°', "_")
        newFilename = newFilename.replace('`', "_")
        newFilename = newFilename.replace('[', "_")
        newFilename = newFilename.replace(']', "_")
        return newFilename
    }

}<commit_msg>add # and ? as escaped character in filename<commit_after>package utils

/*
 * Copyright (c) 2009-2018. Authors: see NOTICE file.
 *
 * Licensed under the GNU Lesser General Public License, Version 2.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.gnu.org/licenses/lgpl-2.1.txt
 *
 * 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.
 */

/**
 * User: lrollus
 * Date: 17/10/12
 * GIGA-ULg
 * Utility class to deals with file
 */
class FilesUtils {

    static String[] badChars = [" " , "(" , ")" , "+" , "*" , "/" , "@" , "'" , '"' , '$' , '€' , '£' , '°' , '`' , '[' , ']', '#', '?']
    /**
     * Get the extension of a filename
     */
    public static def getExtensionFromFilename = {filename ->
        def returned_value = ""
        def m = (filename =~ /(\.[^\.]*)$/)
        if (m.size() > 0) returned_value = ((m[0][0].size() > 0) ? m[0][0].substring(1).trim().toLowerCase() : "");
        return returned_value
    }

    /**
     * Convert the current filename to a valide filename (without bad char like '@','+',...)
     * All bad char are replaced with '_'
     * @param file File
     * @return Correct filename for this file
     */
    public static String correctFileName(def originalFilename) {
        String newFilename = originalFilename
        for(String badChar : badChars) {
            newFilename = newFilename.replace(badChar, "_")
        }
        return newFilename
    }

}
{'fraction_non_alphanumeric': 0.1412278573161854, 'fraction_numerical': 0.012132977432661975, 'mean_word_length': 2.7920883164673413, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2118301', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1139, 'n_words': 379}