<commit_before>/*
 * StringView.h
 *
 *  Created on: Jun 20, 2016
 *      Author: balszun
 */

#ifndef LIBS_MART_COMMON_EXPERIMENTAL_STRINGVIEW_H_
#define LIBS_MART_COMMON_EXPERIMENTAL_STRINGVIEW_H_
#pragma once

/* ######## INCLUDES ######### */
/* Standard Library Includes */
#include <algorithm>
#include <cstring>
#include <memory>
#include <ostream>
#include <string>
#include <type_traits>

/* Proprietary Library Includes */

/* Project Includes */
#include "ArrayViewAdaptor.h"

namespace mart {

class StringView : public ArrayViewAdaptor<const char, StringView> {
public:
	// type defs
	using CharT		  = char;
	using traits_type = std::char_traits<CharT>;

	static constexpr size_type npos = size_type( -1 );

public:
	/* #### CTORS #### */
	constexpr StringView() noexcept = default;

	StringView( const std::string& other ) noexcept
		: _start( other.data() )
		, _size( other.size() )
	{
	}

	constexpr StringView( const char* other, size_type size ) noexcept
		: _start( other )
		, _size( size )
	{
	}

	static StringView fromZString( const char* other ) { return {other, std::strlen( other )}; }

	// NOTE: Use only for string literals!!!
	template <size_t N>
	constexpr StringView( const char ( &other )[N] ) noexcept
		: _start( other )
		, _size( N - 1 )
	{
	}
<commit_msg>[StringView] Allow construction from single character<commit_after>/*
 * StringView.h
 *
 *  Created on: Jun 20, 2016
 *      Author: balszun
 */

#ifndef LIBS_MART_COMMON_EXPERIMENTAL_STRINGVIEW_H_
#define LIBS_MART_COMMON_EXPERIMENTAL_STRINGVIEW_H_
#pragma once

/* ######## INCLUDES ######### */
/* Standard Library Includes */
#include <algorithm>
#include <cstring>
#include <memory>
#include <ostream>
#include <string>
#include <type_traits>

/* Proprietary Library Includes */

/* Project Includes */
#include "ArrayViewAdaptor.h"

namespace mart {

class StringView : public ArrayViewAdaptor<const char, StringView> {
public:
	// type defs
	using CharT		  = char;
	using traits_type = std::char_traits<CharT>;

	static constexpr size_type npos = size_type( -1 );

public:
	/* #### CTORS #### */
	constexpr StringView() noexcept = default;

	StringView( const std::string& other ) noexcept
		: _start( other.data() )
		, _size( other.size() )
	{
	}

	constexpr StringView( const char* other, size_type size ) noexcept
		: _start( other )
		, _size( size )
	{
	}

	static StringView fromZString( const char* other ) { return {other, std::strlen( other )}; }

	// NOTE: Use only for string literals!!!
	template <size_t N>
	constexpr StringView( const char ( &other )[N] ) noexcept
		: _start( other )
		, _size( N - 1 )
	{
	}

	constexpr StringView(const char &other) noexcept
		: _start(&other)
		, _size(1)
	{
	}

{'fraction_non_alphanumeric': 0.13775322283609576, 'fraction_numerical': 0.006261510128913444, 'mean_word_length': 4.114877589453861, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '3679050', 'n_tokens_mistral': 1004, 'n_tokens_neox': 953, 'n_words': 250}