format()
This commit is contained in:
parent
72352994f7
commit
58b62eb3a8
2
dependencies/kerep
vendored
2
dependencies/kerep
vendored
@ -1 +1 @@
|
|||||||
Subproject commit dd5788f72a909b602592da7861ba717d529be9f3
|
Subproject commit 0e370b31ba98ec85720a4a5295b995348c247d3c
|
||||||
@ -1,8 +1,6 @@
|
|||||||
#include "UsefulException.hpp"
|
#include "UsefulException.hpp"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace GraphC {
|
|
||||||
|
|
||||||
UsefulException_::UsefulException_(std::string _message, std::string _file, std::string _func, int _line_n)
|
UsefulException_::UsefulException_(std::string _message, std::string _file, std::string _func, int _line_n)
|
||||||
: message(_message), file(_file), function(_func), line_n(_line_n)
|
: message(_message), file(_file), function(_func), line_n(_line_n)
|
||||||
{
|
{
|
||||||
@ -15,5 +13,3 @@ UsefulException_::UsefulException_(std::string _message, std::string _file, std:
|
|||||||
char const* UsefulException_::what() const noexcept {
|
char const* UsefulException_::what() const noexcept {
|
||||||
return complete_text.c_str();
|
return complete_text.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@ -3,8 +3,6 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace GraphC {
|
|
||||||
|
|
||||||
#define UsefulException(MSG) UsefulException_(MSG, __FILE__, __func__, __LINE__)
|
#define UsefulException(MSG) UsefulException_(MSG, __FILE__, __func__, __LINE__)
|
||||||
|
|
||||||
class UsefulException_ : public std::exception {
|
class UsefulException_ : public std::exception {
|
||||||
@ -19,5 +17,3 @@ public:
|
|||||||
|
|
||||||
virtual char const* what() const noexcept;
|
virtual char const* what() const noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
66
src/format.cpp
Normal file
66
src/format.cpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include "UsefulException.hpp"
|
||||||
|
#include "../dependencies/kerep/src/base/base.h"
|
||||||
|
|
||||||
|
std::string format(const std::string format_str, size_t args_count, ...){
|
||||||
|
va_list vl;
|
||||||
|
va_start(vl, args_count);
|
||||||
|
std::stringstream ss;
|
||||||
|
|
||||||
|
for(size_t i = 0; i < format_str.length(); i++){
|
||||||
|
char c = format_str[i];
|
||||||
|
|
||||||
|
// format specifier
|
||||||
|
if(c == '%'){
|
||||||
|
c = format_str[++i];
|
||||||
|
bool l = false;
|
||||||
|
while(c == 'l'){
|
||||||
|
l = true;
|
||||||
|
c = format_str[++i];
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(c){
|
||||||
|
case 'u':
|
||||||
|
if(l) ss<<(u64)va_arg(vl, u64);
|
||||||
|
else ss<<(u32)va_arg(vl, u32);
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
case 'd':
|
||||||
|
if(l) ss<<(i64)va_arg(vl, i64);
|
||||||
|
else ss<<(i32)va_arg(vl, i32);
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
// f32 is promoted to f64 when passed through '...'
|
||||||
|
ss<<(f64)va_arg(vl, f64);
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
ss<<(void*)va_arg(vl, void*);
|
||||||
|
break;
|
||||||
|
case 'x':
|
||||||
|
if(l) ss<<std::hex<<(u64)va_arg(vl, u64);
|
||||||
|
else ss<<std::hex<<(u32)va_arg(vl, u32);
|
||||||
|
break;
|
||||||
|
case 's': {
|
||||||
|
const char* cptr = va_arg(vl,char*);
|
||||||
|
if(cptr != nullptr)
|
||||||
|
ss<<cptr;
|
||||||
|
else ss<<"<nullptr>";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'c':
|
||||||
|
ss<<(char)va_arg(vl,int);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw UsefulException("invalid format cpecifier");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// regular character
|
||||||
|
else ss<<c;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_end(vl);
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
3
src/format.hpp
Normal file
3
src/format.hpp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#include <string>
|
||||||
|
|
||||||
|
std::string format(const std::string format_str, size_t args_count, ...);
|
||||||
@ -12,7 +12,7 @@ ImFont* _ImFont_LoadEmbedded(const void* data, int data_size, const char* font_n
|
|||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
font_size *= dpi;
|
font_size *= dpi;
|
||||||
ImFontConfig font_cfg = ImFontConfig();
|
ImFontConfig font_cfg = ImFontConfig();
|
||||||
sprintf_s(font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), "%s, %.0fpx", font_name, font_size);
|
ksprintf(font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), "%s, %.0fpx", font_name, font_size);
|
||||||
return io.Fonts->AddFontFromMemoryCompressedTTF(data, data_size, font_size, &font_cfg);
|
return io.Fonts->AddFontFromMemoryCompressedTTF(data, data_size, font_size, &font_cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
#include "../../dependencies/SDL2/include/SDL.h"
|
#include "../../dependencies/SDL2/include/SDL.h"
|
||||||
#include "../../dependencies/SDL2/include/SDL_opengl.h"
|
#include "../../dependencies/SDL2/include/SDL_opengl.h"
|
||||||
#include "../../dependencies/imgui/imgui.h"
|
#include "../../dependencies/imgui/imgui.h"
|
||||||
|
#include "../format.hpp"
|
||||||
#include "NodeEditor.hpp"
|
#include "NodeEditor.hpp"
|
||||||
#include "imgui_extensions.hpp"
|
#include "imgui_extensions.hpp"
|
||||||
#include "fonts.hpp"
|
#include "fonts.hpp"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user