<commit_before>// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
// See the LICENSE file
// Portions Copyright (c) Athena Dev Teams

#ifndef _STRLIB_H_
#define _STRLIB_H_

#include "../common/cbasetypes.h"
#include <stdarg.h>

#ifndef __USE_GNU
	#define __USE_GNU  // required to enable strnlen on some platforms
	#include <string.h>
	#undef __USE_GNU
#else
	#include <string.h>
#endif

#ifdef WIN32
	#define HAVE_STRTOK_R
	#define strtok_r(s,delim,save_ptr) _strtok_r((s),(delim),(save_ptr))
	char *_strtok_r(char* s1, const char* s2, char** lasts);
#endif

/// Bitfield determining the behaviour of sv_parse and sv_split.
typedef enum e_svopt {
	// default: no escapes and no line terminator
	SV_NOESCAPE_NOTERMINATE = 0,
	// Escapes according to the C compiler.
	SV_ESCAPE_C = 1,
	// Line terminators
	SV_TERMINATE_LF = 2,
	SV_TERMINATE_CRLF = 4,
	SV_TERMINATE_CR = 8,
	// If sv_split keeps the end of line terminator, instead of replacing with '\0'
	SV_KEEP_TERMINATOR = 16
} e_svopt;

/// Other escape sequences supported by the C compiler.
#define SV_ESCAPE_C_SUPPORTED "abtnvfr\?\"'\\"

/// Parse state.
/// The field is [start,end[
struct s_svstate {
	const char* str; //< string to parse
	int len; //< string length
	int off; //< current offset in the string
	int start; //< where the field starts
	int end; //< where the field ends
	enum e_svopt opt; //< parse options
	char delim; //< field delimiter
	bool done; //< if all the text has been parsed
};


/// StringBuf - dynamic string
struct StringBuf {
	char *buf_;
	char *ptr_;
	unsigned int max_;
};
typedef struct StringBuf StringBuf;

struct strlib_interface {
	char *(*jstrescape) (char* pt);
	char *(*jstrescapecpy) (char* pt, const char* spt);
	int (*jmemescapecpy) (char* pt, const char* spt, int size);
	int (*remove_control_chars) (char* str);
	char *(*trim) (char* str);
	char *(*normalize_name) (char* str,const char* delims);
	const char *(*stristr) (const char *haystack, const char *needle);
		
#if !(defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) && !defined(HAVE_STRNLEN)
	size_t (*strnlen) (const char* string, size_t maxlen);
#endif
	
#if defined(WIN32) && defined(_MSC_VER) && _MSC_VER <= 1200
	uint64 (*strtoull) (const char* str, char** endptr, int base);
#endif<commit_msg>Modified strlib interface to be compliant with hpmhooks<commit_after>// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
// See the LICENSE file
// Portions Copyright (c) Athena Dev Teams

#ifndef _STRLIB_H_
#define _STRLIB_H_

#include "../common/cbasetypes.h"
#include <stdarg.h>

#ifndef __USE_GNU
	#define __USE_GNU  // required to enable strnlen on some platforms
	#include <string.h>
	#undef __USE_GNU
#else
	#include <string.h>
#endif

#ifdef WIN32
	#define HAVE_STRTOK_R
	#define strtok_r(s,delim,save_ptr) _strtok_r((s),(delim),(save_ptr))
	char *_strtok_r(char* s1, const char* s2, char** lasts);
#endif

/// Bitfield determining the behaviour of sv_parse and sv_split.
typedef enum e_svopt {
	// default: no escapes and no line terminator
	SV_NOESCAPE_NOTERMINATE = 0,
	// Escapes according to the C compiler.
	SV_ESCAPE_C = 1,
	// Line terminators
	SV_TERMINATE_LF = 2,
	SV_TERMINATE_CRLF = 4,
	SV_TERMINATE_CR = 8,
	// If sv_split keeps the end of line terminator, instead of replacing with '\0'
	SV_KEEP_TERMINATOR = 16
} e_svopt;

/// Other escape sequences supported by the C compiler.
#define SV_ESCAPE_C_SUPPORTED "abtnvfr\?\"'\\"

/// Parse state.
/// The field is [start,end[
struct s_svstate {
	const char* str; //< string to parse
	int len; //< string length
	int off; //< current offset in the string
	int start; //< where the field starts
	int end; //< where the field ends
	enum e_svopt opt; //< parse options
	char delim; //< field delimiter
	bool done; //< if all the text has been parsed
};


/// StringBuf - dynamic string
struct StringBuf {
	char *buf_;
	char *ptr_;
	unsigned int max_;
};
typedef struct StringBuf StringBuf;

struct strlib_interface {
	char *(*jstrescape) (char* pt);
	char *(*jstrescapecpy) (char* pt, const char* spt);
	int (*jmemescapecpy) (char* pt, const char* spt, int size);
	int (*remove_control_chars) (char* str);
	char *(*trim) (char* str);
	char *(*normalize_name) (char* str,const char* delims);
	const char *(*stristr) (const char *haystack, const char *needle);
		
	/* only used when '!(defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) && !defined(HAVE_STRNLEN)', needs to be defined at all times however  */
	size_t (*strnlen) (const char* string, size_t maxlen);

	/* only used when 'defined(WIN32) && defined(_MSC_VER) && _MSC_VER <= 1200', needs to be defined at all times however  */
	uint64 (*strtoull) (const char* str, char** endptr, int base);
{'fraction_non_alphanumeric': 0.12614143130176259, 'fraction_numerical': 0.011042684221703122, 'mean_word_length': 4.250836120401337, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 11, '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': '4397912', 'n_tokens_mistral': 1774, 'n_tokens_neox': 1684, 'n_words': 566}