<commit_before>/*! \file */ //Copyright 2011-2017 <NAME>; All Rights Reserved

#if defined __link
#include <sys/stat.h>
#endif

#include "fs/Stat.hpp"

using namespace fs;
#if defined __link
Stat::Stat(bool is_local) {
	memset(&m_stat, 0, sizeof(m_stat));
	m_is_local = is_local;
}
#else

Stat::Stat() {
	memset(&m_stat, 0, sizeof(m_stat));
}
#endif


bool Stat::is_directory() const {
#if defined __link
	if( m_is_local ){
		return (m_stat.st_mode & S_IFMT) == S_IFDIR;
	}
#endif
	return (m_stat.st_mode & Stat::FORMAT) == Stat::DIRECTORY;
}

bool Stat::is_file() const {
#if defined __link
	if( m_is_local ){
		return (m_stat.st_mode & S_IFMT) == S_IFREG;
	}
#endif
	return (m_stat.st_mode & Stat::FORMAT) == Stat::REGULAR;
}

bool Stat::is_device() const {
	return is_block_device() || is_character_device();

}

bool Stat::is_block_device() const {
#if defined __link
	if( m_is_local ){
		return (m_stat.st_mode & S_IFMT) == S_IFBLK;
	}
#endif
	return (m_stat.st_mode & (Stat::FORMAT)) == Stat::BLOCK;
}

bool Stat::is_character_device() const {
#if defined __link
	if( m_is_local ){
		return (m_stat.st_mode & S_IFMT) == S_IFCHR;
	}
#endif
	return (m_stat.st_mode & (Stat::FORMAT)) == Stat::CHARACTER;
}

bool Stat::is_socket() const {
#if defined __link
	if( m_is_local ){
#if !defined __win32
		return (m_stat.st_mode & S_IFMT) == S_IFSOCK;
#else
		return false;
#endif
	}
#endif
	return (m_stat.st_mode & Stat::FORMAT) == Stat::FILE_SOCKET;
}


u32 Stat::size() const {
	return m_stat.st_size;
}

bool Stat::is_executable() const {
	return false;
}

const var::String Stat::suffix(
		const var::String & path
		){
	size_t pos = path.rfind('.');

	if( pos == var::String::npos ){
		return var::String();
	}

	return path.create_sub_string(
				var::String::Position(pos+1)
				);
}

const var::String Stat::name(
		const var::String & path
		){
	size_t pos = path.rfind('/');

	if( pos == var::String::npos ){
		return path;
	}

	return path.create_sub_string(
				var::String::Position(pos+1)
				);
}

const var::String Stat::parent_directory(
		const var::String & path
		){
	size_t pos = path.find('/');

	if( pos == var::String::npos ){
		return var::String();
	}

	return path.create_sub_string(
				var::String::Position(0),
				var::String::Length(pos)
				);
}

const var::String Stat::base_name(
		const var::String & path
		){
	var::String result = name(path);
	size_t pos = result.rfind('.');
	if( pos == var::String::npos ){
		return result;
	}<commit_msg>fixed parent_directory()<commit_after>/*! \file */ //Copyright 2011-2017 <NAME>; All Rights Reserved

#if defined __link
#include <sys/stat.h>
#endif

#include "fs/Stat.hpp"

using namespace fs;
#if defined __link
Stat::Stat(bool is_local) {
	memset(&m_stat, 0, sizeof(m_stat));
	m_is_local = is_local;
}
#else

Stat::Stat() {
	memset(&m_stat, 0, sizeof(m_stat));
}
#endif


bool Stat::is_directory() const {
#if defined __link
	if( m_is_local ){
		return (m_stat.st_mode & S_IFMT) == S_IFDIR;
	}
#endif
	return (m_stat.st_mode & Stat::FORMAT) == Stat::DIRECTORY;
}

bool Stat::is_file() const {
#if defined __link
	if( m_is_local ){
		return (m_stat.st_mode & S_IFMT) == S_IFREG;
	}
#endif
	return (m_stat.st_mode & Stat::FORMAT) == Stat::REGULAR;
}

bool Stat::is_device() const {
	return is_block_device() || is_character_device();

}

bool Stat::is_block_device() const {
#if defined __link
	if( m_is_local ){
		return (m_stat.st_mode & S_IFMT) == S_IFBLK;
	}
#endif
	return (m_stat.st_mode & (Stat::FORMAT)) == Stat::BLOCK;
}

bool Stat::is_character_device() const {
#if defined __link
	if( m_is_local ){
		return (m_stat.st_mode & S_IFMT) == S_IFCHR;
	}
#endif
	return (m_stat.st_mode & (Stat::FORMAT)) == Stat::CHARACTER;
}

bool Stat::is_socket() const {
#if defined __link
	if( m_is_local ){
#if !defined __win32
		return (m_stat.st_mode & S_IFMT) == S_IFSOCK;
#else
		return false;
#endif
	}
#endif
	return (m_stat.st_mode & Stat::FORMAT) == Stat::FILE_SOCKET;
}


u32 Stat::size() const {
	return m_stat.st_size;
}

bool Stat::is_executable() const {
	return false;
}

const var::String Stat::suffix(
		const var::String & path
		){
	size_t pos = path.rfind('.');

	if( pos == var::String::npos ){
		return var::String();
	}

	return path.create_sub_string(
				var::String::Position(pos+1)
				);
}

const var::String Stat::name(
		const var::String & path
		){
	size_t pos = path.rfind('/');

	if( pos == var::String::npos ){
		return path;
	}

	return path.create_sub_string(
				var::String::Position(pos+1)
				);
}

const var::String Stat::parent_directory(
		const var::String & path
		){
	size_t pos = path.rfind('/');

	if( pos == var::String::npos ){
		return var::String();
	}

	return path.create_sub_string(
				var::String::Position(0),
				var::String::Length(pos)
				);
}

const var::String Stat::base_name(
		const var::String & path
		){
	var::String result = name(path);
	size_t pos = result.rfind('.');
	if( pos == var::String::npos ){
		return result;
	}
{'fraction_non_alphanumeric': 0.16962127316680098, 'fraction_numerical': 0.00684931506849315, 'mean_word_length': 4.46806167400881, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4844309', 'n_tokens_mistral': 2064, 'n_tokens_neox': 1950, 'n_words': 425}