<commit_before>#ifndef CSTR_UTIL_H
#define CSTR_UTIL_H
#include <inttypes.h>
#include <time.h>
#include <zlib.h>
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
#include <math.h>
#include "kseq.h"
#include "kstring.h"
#include "compiler_util.h"
#include "logging_util.h"
#include "char_util.h"

#ifndef KSEQ_DEC_GZ
#define KSEQ_DEC_GZ
KSEQ_INIT(gzFile, gzread)
#endif

#ifndef MAX_BARCODE_LENGTH
#define MAX_BARCODE_LENGTH 30
#endif

#ifndef SEQBUF_SIZE
#define SEQBUF_SIZE 300
#endif

#ifdef __cplusplus
#include <string>
#include <sstream>
#include <fstream>
#include <vector>

namespace dlib {

/* sprintf's to the buffer in string.
 * If not long enough, everything breaks. Be careful!
*/
#define stringprintf(str, ...) str.resize(sprintf(const_cast<char *>(str.data()), ##__VA_ARGS__))

    std::vector<std::string> tokenize(const char *str, char c='\t');

    size_t safe_stringprintf(std::string& str, const char *fmt, ...);
    extern "C" char *rand_string(char *str, size_t size);

    static inline int strhd_thresh(std::string const& str1, std::string const& str2, size_t mmlim) {
        return strhd_thresh(str1.c_str(), str2.c_str(), mmlim);
    }

    static inline int strhd_thresh(const char *str1, const char *str2, size_t mmlim) {
        while(*str1) {
            if(*str1 != *str2)
                if(mmlim-- == 0)
                    return 0;
            ++str1, ++str2;
        }
        return 1;
    }

#endif

    /*
     * @func kfill_rc
     * :param: seq [kseq_t *] Input kseq object
     * :param: buffer [char *] String to copy into.
     * Fills a buffer with reverse-complemented fastq lines
     * (seq line through the end of the quality line,
     *  with a terminal newline and a null character)
     */
    static inline void kfill_rc(kseq_t *seq, char *buffer) {
        uint64_t i = seq->seq.l;
        char *seqp = seq->seq.s + i;
        // Add seq field.
        for(; i ; --i) *buffer++ = nuc_cmpl(*--seqp);
        // Add "\n+\n"
        *buffer++ = '\n'; *buffer++ = '+'; *buffer++ = '\n';
        // Add reversed quality
        i = seq->qual.l;
        seqp = seq->qual.s + i;
        for(; i ; --i) *buffer++ = *--seqp;
        // Terminate with newline and null character.<commit_msg>Added a fast_atoi that ignores delimiters (commas by default, or others, in case of European numbers....)<commit_after>#ifndef CSTR_UTIL_H
#define CSTR_UTIL_H
#include <inttypes.h>
#include <time.h>
#include <zlib.h>
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
#include <math.h>
#include "kseq.h"
#include "kstring.h"
#include "compiler_util.h"
#include "logging_util.h"
#include "char_util.h"

#ifndef KSEQ_DEC_GZ
#define KSEQ_DEC_GZ
KSEQ_INIT(gzFile, gzread)
#endif

#ifndef MAX_BARCODE_LENGTH
#define MAX_BARCODE_LENGTH 30
#endif

#ifndef SEQBUF_SIZE
#define SEQBUF_SIZE 300
#endif

#ifdef __cplusplus
#include <string>
#include <sstream>
#include <fstream>
#include <vector>

namespace dlib {

/* sprintf's to the buffer in string.
 * If not long enough, everything breaks. Be careful!
*/
#define stringprintf(str, ...) str.resize(sprintf(const_cast<char *>(str.data()), ##__VA_ARGS__))

    std::vector<std::string> tokenize(const char *str, char c='\t');

    size_t safe_stringprintf(std::string& str, const char *fmt, ...);
    extern "C" char *rand_string(char *str, size_t size);

    static inline int strhd_thresh(std::string const& str1, std::string const& str2, size_t mmlim) {
        return strhd_thresh(str1.c_str(), str2.c_str(), mmlim);
    }

    static inline int strhd_thresh(const char *str1, const char *str2, size_t mmlim) {
        while(*str1) {
            if(*str1 != *str2)
                if(mmlim-- == 0)
                    return 0;
            ++str1, ++str2;
        }
        return 1;
    }

    /*
     * Fast, signed atoi.
     */
    CONST static inline int fast_delim_atoi(char *str, char delim=',')
    {
        int ret = 0;
        int sign = 1;
        switch(*str) {
            // While retuurn the wrong value if *str is ',': don't start a number with ,!
            case '-': sign = -1; break;
            case '+': break;
            default: ret = *str - '0';
        }
        ++str;
        while(*str) {
            if(*str != delim)
                ret = ret*10 + (*str++ - '0');
            else ++str; // Ignore it
        }
        return ret * sign;
    }


#endif

    /*
     * @func kfill_rc
     * :param: seq [kseq_t *] Input kseq object
     * :param: buffer [char *] String to copy into.
     * Fills a buffer with reverse-complemented fastq lines
     * (seq line through the end of the quality line,
     *  with a terminal newline and a null character)
     */
    static inline void kfill_rc(kseq_t *seq, char *buffer) {
        uint64_t i = seq->seq.l;
        char *seqp = seq->seq.s + i;
        // Add seq field.
        for(; i ; --i) *buffer++ = nuc_cmpl(*--seqp);
        // Add "\n+\n"
        *buffer++ = '\n'; *buffer++ = '+'; *buffer++ = '\n';
        // Add reversed quality
        i = seq->qual.l;
        seqp = seq->qual.s + i;
        for(; i ; --i) *buffer++ = *--seqp;
        // Terminate with newline and null character.
{'fraction_non_alphanumeric': 0.1453420950908388, 'fraction_numerical': 0.009470429068419018, 'mean_word_length': 2.5060975609756095, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6758614', 'n_tokens_mistral': 1876, 'n_tokens_neox': 1814, 'n_words': 514}