Optimized string formatting

dev
anulax1225 ago%!(EXTRA string=1 year)
parent 149f511822
commit ccfe4fe72c
  1. 14
      bakara/src/bakara/core/string_fmt.h

@ -1,12 +1,11 @@
#include <string>
#include <sstream>
#include <iostream>
#pragma once
#include <bkpch.h>
#include <type_traits>
#include <exception>
#include <algorithm>
#include <cctype>
namespace Bk {
void format_impl(std::stringstream& ss, const char* format) {
inline void format_impl(std::stringstream& ss, const char* format) {
while (*format) {
if (*format == '%' && *++format != '%') // %% == % (not a format directive)
throw std::invalid_argument("not enough arguments !\n");
@ -47,9 +46,10 @@ namespace Bk {
}
template <typename... Args>
std::string format(const char* fmt, Args... args) {
inline std::string format(const char* fmt, Args... args) {
std::stringstream ss;
format_impl(ss, fmt, args...);
return ss.str();
}
}

Loading…
Cancel
Save