<commit_before>// Copyright (c) 2009-2010 <NAME>
// Copyright (c) 2009-2016 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

/**
 * Utilities for converting data from/to strings.
 */
#ifndef BITCOIN_UTIL_STRENCODINGS_H
#define BITCOIN_UTIL_STRENCODINGS_H

#include <attributes.h>

#include <cstdint>
#include <string>
#include <vector>

#define BEGIN(a) ((char *)&(a))
#define END(a) ((char *)&((&(a))[1]))
#define UBEGIN(a) ((uint8_t *)&(a))
#define UEND(a) ((uint8_t *)&((&(a))[1]))
#define ARRAYLEN(array) (sizeof(array) / sizeof((array)[0]))

/** Used by SanitizeString() */
enum SafeChars {
    //! The full set of allowed chars
    SAFE_CHARS_DEFAULT,
    //! BIP-0014 subset
    SAFE_CHARS_UA_COMMENT,
    //! Chars allowed in filenames
    SAFE_CHARS_FILENAME,
    //! Chars allowed in URIs (RFC 3986)
    SAFE_CHARS_URI,
};

/**
 * Remove unsafe chars. Safe chars chosen to allow simple messages/URLs/email
 * addresses, but avoid anything even possibly remotely dangerous like & or >
 * @param[in] str    The string to sanitize
 * @param[in] rule   The set of safe chars to choose (default: least
 * restrictive)
 * @return           A new string without unsafe chars<commit_msg>[backport#15139] util: remove unused [U](BEGIN|END) macros<commit_after>// Copyright (c) 2009-2010 <NAME>
// Copyright (c) 2009-2016 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

/**
 * Utilities for converting data from/to strings.
 */
#ifndef BITCOIN_UTIL_STRENCODINGS_H
#define BITCOIN_UTIL_STRENCODINGS_H

#include <attributes.h>

#include <cstdint>
#include <string>
#include <vector>

#define ARRAYLEN(array) (sizeof(array) / sizeof((array)[0]))

/** Used by SanitizeString() */
enum SafeChars {
    //! The full set of allowed chars
    SAFE_CHARS_DEFAULT,
    //! BIP-0014 subset
    SAFE_CHARS_UA_COMMENT,
    //! Chars allowed in filenames
    SAFE_CHARS_FILENAME,
    //! Chars allowed in URIs (RFC 3986)
    SAFE_CHARS_URI,
};

/**
 * Remove unsafe chars. Safe chars chosen to allow simple messages/URLs/email
 * addresses, but avoid anything even possibly remotely dangerous like & or >
 * @param[in] str    The string to sanitize
 * @param[in] rule   The set of safe chars to choose (default: least
 * restrictive)
 * @return           A new string without unsafe chars
{'fraction_non_alphanumeric': 0.12296060485475527, 'fraction_numerical': 0.02347791484281735, 'mean_word_length': 3.9488188976377954, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, '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': '4704297', 'n_tokens_mistral': 880, 'n_tokens_neox': 806, 'n_words': 258}