<commit_before>#pragma once
#ifndef liuzianglib_File
#define liuzianglib_File
#include <string>
#include "DC_ERROR.h"
//Version 2.4.2
//20170330

#define ERROR_CANTOPENFILE DC::DC_ERROR(filename,"CAN NOT OPEN FILE", -1)
#define ERROR_CANTGETSIZE DC::DC_ERROR(filename,"CAN NOT GET FILE SIZE", -1)

namespace DC {

	namespace File {
		//ĳЩptrõذ汾
		//ʧ쳣

		class file_ptr final {//Cļָڵİװ
			                  //ͨif(file_ptr)ķʽжfile_ptrǷѾ
			                  //ʹʱֶfclose(file_ptr::get())ⲻᵼδΪ
			                  //֧ƶ
			                  //ĳЩʱʹôĹ1(VSڴ鿴еġ())ڴûлգⲻڴй©
		public:
			file_ptr() :fp(nullptr) {}

			file_ptr(FILE* input) :fp(input) {}

			file_ptr(const file_ptr&) = delete;

			file_ptr(file_ptr&& input)noexcept {
				clear();
				this->fp = input.fp;
				input.fp = nullptr;
			}

			~file_ptr() {
				clear();
			}

			file_ptr& operator=(const file_ptr&) = delete;

			file_ptr& operator=(file_ptr&& input)noexcept {
				clear();
				this->fp = input.fp;
				input.fp = nullptr;
				return *this;
			}

			operator bool() {
				if (fp == NULL || fp == nullptr) return false;
				return true;
			}

			inline FILE* get() {
				return fp;
			}

			inline void reset(FILE* input) {
				clear();
				fp = input;
			}

		private:
			inline void clear() {
				if (fp == NULL || fp == nullptr) return;
				fclose(fp);
			}

		private:
			FILE *fp;
		};

		inline void del(const std::string& filename)noexcept {
			remove(filename.c_str());
		}
		
		inline bool exists(const std::string& filename)noexcept {
			file_ptr ptr(fopen(filename.c_str(), "r"));
			return (bool)ptr;
		}

		inline bool exists(const std::string& filename, file_ptr& inputptr)noexcept {//ͬʱжǷںǷܴ
			file_ptr ptr(fopen(filename.c_str(), "r"));
			inputptr = std::move(ptr);
			return (bool)inputptr;
		}

		std::size_t getSize(const std::string& filename) {//ȡļ
			file_ptr ptr;
			if (!exists(filename, ptr)) throw ERROR_CANTOPENFILE;
			fseek(ptr.get(), 0L, SEEK_END);
			const auto& rv = ftell(ptr.get());
			if (rv < 0) throw ERROR_CANTGETSIZE;
			return rv;//з޷ŲƥԺԣѾִ
		}

		std::string read(const std::string& filename) {
			file_ptr ptr;
			if (!exists(filename, ptr)) throw ERROR_CANTOPENFILE;
			std::string returnvalue;
			auto&& ch = fgetc(ptr.get());
			while (ch != EOF) {
				returnvalue.push_back(ch);
				ch = fgetc(ptr.get());
			}
			return returnvalue;
		}

		bool write(const std::string& filename, const std::string& write)noexcept {//д
			file_ptr ptr(fopen(filename.c_str(), "w"));
			if (!ptr) return false;
			if (fprintf(ptr.get(), "%s", write.c_str()) == -1) return false;
			return true;
		}

		bool writeAppend(const std::string& filename, const std::string& write)noexcept {
			file_ptr ptr(fopen(filename.c_str(), "a"));
			if (!ptr) return false;
			if (fprintf(ptr.get(), "%s", write.c_str()) == -1) return false;
			return true;
		}

	}

}

#endif<commit_msg>liuzianglib beta 2.4.2V16,20170417<commit_after>#pragma once
#ifndef liuzianglib_File
#define liuzianglib_File
#include <string>
#include "DC_ERROR.h"
//Version 2.4.2V16
//20170417

#define ERROR_CANTOPENFILE DC::DC_ERROR(filename,"CAN NOT OPEN FILE", -1)
#define ERROR_CANTGETSIZE DC::DC_ERROR(filename,"CAN NOT GET FILE SIZE", -1)

namespace DC {

	namespace File {
		//ĳЩptrõذ汾
		//ʧ쳣

		class text;
		class binary;

		class file_ptr final {//Cļָڵİװ
							  //ͨif(file_ptr)ķʽжfile_ptrǷѾ
							  //ʹʱֶfclose(file_ptr::get())ⲻᵼδΪ
							  //֧ƶ
							  //ĳЩʱʹôĹ1(VSڴ鿴еġ())ڴûлգⲻڴй©
		public:
			file_ptr() :fp(nullptr) {}

			file_ptr(FILE* input) :fp(input) {}

			file_ptr(const file_ptr&) = delete;

			file_ptr(file_ptr&& input)noexcept {
				clear();
				this->fp = input.fp;
				input.fp = nullptr;
			}

			~file_ptr() {
				clear();
			}

			file_ptr& operator=(const file_ptr&) = delete;

			file_ptr& operator=(file_ptr&& input)noexcept {
				clear();
				this->fp = input.fp;
				input.fp = nullptr;
				return *this;
			}

			operator bool()const {
				if (fp == NULL || fp == nullptr) return false;
				return true;
			}

			inline FILE* get()const {
				return fp;
			}

			inline void reset(FILE* input) {
				clear();
				fp = input;
			}

		private:
			inline void clear() {
				if (fp == NULL || fp == nullptr) return;
				fclose(fp);
			}

		private:
			FILE *fp;
		};

		inline void del(const std::string& filename)noexcept {
			remove(filename.c_str());
		}

		inline bool exists(const std::string& filename)noexcept {
			file_ptr ptr(fopen(filename.c_str(), "r"));
			return (bool)ptr;
		}

		template<typename FLAG>
		inline bool exists(const std::string& filename, file_ptr& inputptr)noexcept;

		template<>
		inline bool exists<text>(const std::string& filename, file_ptr& inputptr)noexcept {//ͬʱжǷںǷܴ
			file_ptr ptr(fopen(filename.c_str(), "r"));
			inputptr = std::move(ptr);
			return (bool)inputptr;
		}

		template<>
		inline bool exists<binary>(const std::string& filename, file_ptr& inputptr)noexcept {//ͬʱжǷںǷܴ
			file_ptr ptr(fopen(filename.c_str(), "rb"));
			inputptr = std::move(ptr);
			return (bool)inputptr;
		}

		std::size_t getSize(const std::string& filename) {//ȡļ
			file_ptr ptr;
			if (!exists<text>(filename, ptr)) throw ERROR_CANTOPENFILE;
			fseek(ptr.get(), 0L, SEEK_END);
			const auto& rv = ftell(ptr.get());
			if (rv < 0) throw ERROR_CANTGETSIZE;
			return rv;//з޷ŲƥԺԣѾִ
		}

		template<typename FLAG = text>
		std::string read(const std::string& filename) {
			static_assert(std::is_same<std::decay_t<FLAG>, text>::value || std::is_same<std::decay_t<FLAG>, binary>::value, "flag illegal");
			file_ptr ptr;
			if (!exists<FLAG>(filename, ptr)) throw ERROR_CANTOPENFILE;
			std::string returnvalue;
			auto&& ch = fgetc(ptr.get());
			while (ch != EOF) {
				returnvalue.push_back(ch);
				ch = fgetc(ptr.get());
			}
			return returnvalue;
		}

		template<typename FLAG = text>
		bool write(const std::string& filename, const std::string& write)noexcept;

		template<>
		bool write<text>(const std::string& filename, const std::string& write)noexcept {//д
			file_ptr ptr(fopen(filename.c_str(), "w"));
			if (!ptr) return false;
			if (fprintf(ptr.get(), "%s", write.c_str()) == -1) return false;
			return true;
		}

		template<>
		bool write<binary>(const std::string& filename, const std::string& write)noexcept {//д
			file_ptr ptr(fopen(filename.c_str(), "wb"));
			if (!ptr) return false;
			if (fwrite(write.c_str(), 1, write.size(), ptr.get()) == -1) return false;
			return true;
		}

		template<typename FLAG = text>
		bool writeAppend(const std::string& filename, const std::string& write)noexcept;

		template<>
		bool writeAppend<text>(const std::string& filename, const std::string& write)noexcept {
			file_ptr ptr(fopen(filename.c_str(), "a"));
			if (!ptr) return false;
			if (fprintf(ptr.get(), "%s", write.c_str()) == -1) return false;
			return true;
		}

		template<>
		bool writeAppend<binary>(const std::string& filename, const std::string& write)noexcept {
			file_ptr ptr(fopen(filename.c_str(), "ab"));
			if (!ptr) return false;
			if (fwrite(write.c_str(), 1, write.size(), ptr.get()) == -1) return false;
			return true;
		}

	}

}

#endif
{'fraction_non_alphanumeric': 0.16035477967056175, 'fraction_numerical': 0.007743207095593411, 'mean_word_length': 3.4567126725219572, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 31, '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': '1576079', 'n_tokens_mistral': 3162, 'n_tokens_neox': 2685, 'n_words': 593}