diff --git a/include/logger.h b/include/logger.h new file mode 100644 index 0000000..3a926ae --- /dev/null +++ b/include/logger.h @@ -0,0 +1,42 @@ +#ifndef _LOGGER_H_ +#define _LOGGER_H_ + +#include +#include +#include +#include + +class logger +{ +private: + std::atomic _isLogging; + std::stringstream _logLine; + +public: + logger(); + void log(const char* s); + + template void log(const char* s, const T& value, const Args&... args) + { + if(!_isLogging) + { + _isLogging.store(true); + _logLine.str(""); + } + + while (*s) + { + if (*s == '%' && *++s != '%') + { + _logLine << value; + return log(s, args...); + } + _logLine << *s++; + } + throw std::runtime_error("extra arguments provided"); + } +}; + +extern logger ulog; + +#endif // _LOGGER_H_ diff --git a/src/asm/linux/x86_64/ustring_asm.s b/src/asm/linux/x86_64/ustring_asm.s index d03bc5f..db97f71 100644 --- a/src/asm/linux/x86_64/ustring_asm.s +++ b/src/asm/linux/x86_64/ustring_asm.s @@ -30,38 +30,44 @@ npos = -1 _asm_ucs4_strstr: - xor r8, r8 + push r12 mov r9d, dword [rdx] + mov rax, rdx + lea r8, [rdi + rsi*4] + lea r10, [rdx + rcx*4] strstr_try_next_symbol: - cmp r9d, dword [rdi + r8*4] + cmp r9d, dword [rdi] je strstr_init_counter - inc r8 - cmp rsi, r8 + add rdi, 4 + cmp rdi, r8 jne strstr_try_next_symbol + pop r12 mov rax, 0 ret strstr_init_counter: - xor r10, r10 + mov rdx, rax + mov r12, rdi strstr_symbol_found: - inc r10 - cmp r10, rcx + add rdx, 4 + cmp rdx, r10 je strstr_the_end - lea rax, [r8 + r10] - mov r11d, dword [rdi + rax*4] - cmp r11d, dword [rdx + r10*4] + add r12, 4 + mov r11d, dword [r12] + cmp r11d, dword [rdx] je strstr_symbol_found - inc r8 + add rdi, 4 jmp strstr_try_next_symbol strstr_the_end: - lea rax, [rdi + r8*4] + pop r12 + mov rax, rdi ret diff --git a/src/logger.cpp b/src/logger.cpp new file mode 100644 index 0000000..bfd1b4a --- /dev/null +++ b/src/logger.cpp @@ -0,0 +1,30 @@ +#include "logger.h" +#include +#include + +logger ulog; + +logger::logger(): _isLogging(ATOMIC_FLAG_INIT) +{ +} + +void logger::log(const char *s) +{ + if(!_isLogging) + { + _isLogging.store(true); + _logLine.str(""); + } + + while (*s) + { + if (*s == '%' && *++s != '%') + throw std::runtime_error("invalid format string: missing arguments"); + _logLine << *s++; + } + + std::cout << _logLine.str() << std::endl; + + _isLogging.store(false); +} + diff --git a/test/main.cpp b/test/main.cpp index 011da48..4488b54 100755 --- a/test/main.cpp +++ b/test/main.cpp @@ -1,5 +1,6 @@ #include "ustring.h" #include "utf.h" +#include "logger.h" #include #include #include @@ -562,6 +563,6 @@ TEST(Ustring, replace_string) int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); }