From 6d60639b1cd2186f3536082fec980e2ea147c09b Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Thu, 4 Apr 2024 18:12:54 -0400 Subject: [PATCH 1/4] Move some docs to a docs dir. This lets me have a dir named `Format`, which I want. --- Format => docs/Format | 0 README.doxygen => docs/README.doxygen | 0 Style => docs/Style | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename Format => docs/Format (100%) rename README.doxygen => docs/README.doxygen (100%) rename Style => docs/Style (100%) diff --git a/Format b/docs/Format similarity index 100% rename from Format rename to docs/Format diff --git a/README.doxygen b/docs/README.doxygen similarity index 100% rename from README.doxygen rename to docs/README.doxygen diff --git a/Style b/docs/Style similarity index 100% rename from Style rename to docs/Style From 4cec1a72993b9c4cc571c4277ec90c52ef4aa541 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Thu, 4 Apr 2024 18:18:11 -0400 Subject: [PATCH 2/4] Started work on some formatting primitives. Things like markdown and indent fixing in UDLs. --- Format.dir/format.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Format.dir/format.h diff --git a/Format.dir/format.h b/Format.dir/format.h new file mode 100644 index 0000000..678d03f --- /dev/null +++ b/Format.dir/format.h @@ -0,0 +1,40 @@ +static_assert( __cplusplus > 2020'99 ); + +#pragma once + +#include + +#include + +namespace Alepha::Hydrogen::Format ::detail:: format_m +{ + inline namespace exports + { + std::string operator ""_format ( const char *p, std::size_t sz ); + } + + inline std::string + exports::operator ""_format ( const char *const p, const std::size_t sz ) + { + std::string s{ p, p + s }; + + if( s.empty() ) return s; + std::size_t indent= 0; + if( s.at( 0 ) == '\n' ) + { + s= s.substr( 1 ); + while( s.at( 0 ) == ' ' ) + { + ++indent; + s= s.substr( 1 ); + } + } + + + } +} + +namespace Alepha::Hydrogen::Format::inline exports::inline format_m +{ + using namespace detail::format_m::exports; +} From aee670f15af25911ebc9606065a1c89f6848a817 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Thu, 4 Apr 2024 22:56:46 -0400 Subject: [PATCH 3/4] Format is a dir. --- {Format.dir => Format}/format.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {Format.dir => Format}/format.h (100%) diff --git a/Format.dir/format.h b/Format/format.h similarity index 100% rename from Format.dir/format.h rename to Format/format.h From 26d9ff52a0f06d6defce29770758eacbd8b17dca Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Fri, 5 Apr 2024 00:55:53 -0400 Subject: [PATCH 4/4] Formatting literals. --- Format/format.h | 74 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 63 insertions(+), 11 deletions(-) diff --git a/Format/format.h b/Format/format.h index 678d03f..6d43acc 100644 --- a/Format/format.h +++ b/Format/format.h @@ -4,33 +4,80 @@ static_assert( __cplusplus > 2020'99 ); #include +#include + #include +#include +#include + +#include namespace Alepha::Hydrogen::Format ::detail:: format_m { - inline namespace exports + inline namespace exports {} + + namespace exports::inline literals { std::string operator ""_format ( const char *p, std::size_t sz ); } inline std::string - exports::operator ""_format ( const char *const p, const std::size_t sz ) + exports::literals::operator ""_format ( const char *const p, const std::size_t sz ) { - std::string s{ p, p + s }; + const std::string_view s{ p, p + sz }; + if( s.empty() ) return std::string{ s }; - if( s.empty() ) return s; - std::size_t indent= 0; - if( s.at( 0 ) == '\n' ) + const auto indent= Alepha::Utility::evaluate <=[&] { - s= s.substr( 1 ); - while( s.at( 0 ) == ' ' ) + if( s.at( 0 ) != '\n' ) return 0uz; + const auto view= s.substr( 1 ); + std::size_t rv= 0; + for( const char ch: s.substr( 1 ) ) { - ++indent; - s= s.substr( 1 ); + if( ch == '\n' ) { rv= 0; continue; } + if( not isspace( ch ) ) break; + ++rv; + } + + return rv; + }; + std::cerr << "See indent at " << indent << std::endl; + + std::istringstream iss{ std::string{ s } }; + if( indent ) iss.get(); + std::ostringstream oss; + + std::size_t count= 0; + bool skipping= indent; + while( iss ) + { + const char ch= iss.get(); + + if( skipping ) + { + if( not isspace( ch ) ) + { + oss << ch; + skipping= false; + } + else if( ++count == indent ) + { + skipping= false; + } + } + else + { + oss.put( ch ); + + if( ch == '\n' ) + { + skipping= true; + count= 0; + } } } - + return std::move( oss ).str(); } } @@ -38,3 +85,8 @@ namespace Alepha::Hydrogen::Format::inline exports::inline format_m { using namespace detail::format_m::exports; } + +namespace Alepha::Hydrogen::Format::inline exports::inline literals::inline format_literals +{ + using namespace format_m::literals; +}