diff --git a/Format/format.h b/Format/format.h new file mode 100644 index 0000000..6d43acc --- /dev/null +++ b/Format/format.h @@ -0,0 +1,92 @@ +static_assert( __cplusplus > 2020'99 ); + +#pragma once + +#include + +#include + +#include +#include +#include + +#include + +namespace Alepha::Hydrogen::Format ::detail:: format_m +{ + inline namespace exports {} + + namespace exports::inline literals + { + std::string operator ""_format ( const char *p, std::size_t sz ); + } + + inline std::string + exports::literals::operator ""_format ( const char *const p, const std::size_t sz ) + { + const std::string_view s{ p, p + sz }; + if( s.empty() ) return std::string{ s }; + + const auto indent= Alepha::Utility::evaluate <=[&] + { + 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 ) ) + { + 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(); + } +} + +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; +} 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