Skip to content

Commit

Permalink
add custom printf, fix clang build
Browse files Browse the repository at this point in the history
  • Loading branch information
UtoECat committed Feb 1, 2024
1 parent bf6ea1e commit e012766
Show file tree
Hide file tree
Showing 8 changed files with 1,674 additions and 5 deletions.
2 changes: 1 addition & 1 deletion base/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ functions/libraries/systems all over the place :
- locale-independent strtod()

# todo
- Locale and implementation-independent vsnprintf() :p
- ~~Locale and implementation-independent vsnprintf() :p~~(done)
5 changes: 3 additions & 2 deletions base/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#pragma once
#include <string>
#include <stdexcept>
#include "external/printf.h"

namespace pb {

Expand Down Expand Up @@ -101,12 +102,12 @@ namespace pb {
template<typename ... Args>
bool format_v(std::string& result, const std::string& format, Args ... args ) {
result.clear();
int size_s = snprintf( nullptr, 0, format.c_str(), args... );
int size_s = snprintf_( nullptr, 0, format.c_str(), args... );
if( size_s < 0 ) return false; // error here?

auto size = static_cast<size_t>(size_s + 1); // Extra space for '\0'
result.resize(size);
auto vv = snprintf( &result[0], size, format.c_str(), args... );
auto vv = snprintf_( &result[0], size, format.c_str(), args... );
return (vv > 0);
}

Expand Down
1 change: 1 addition & 0 deletions engine/meta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ namespace pb {
if (v == map.end()) {
v = map.emplace_hint(v, nullptr);
}
return v.value();
}
};

Expand Down
Loading

0 comments on commit e012766

Please sign in to comment.