splitStringIntoVector now takes various length separators
This commit is contained in:
parent
9b16c645ac
commit
6dbd4c7ced
@ -21,11 +21,15 @@ namespace gz {
|
|||||||
*
|
*
|
||||||
* @section main_installation Installation
|
* @section main_installation Installation
|
||||||
* @subsection main_i_linux Linux
|
* @subsection main_i_linux Linux
|
||||||
* - Make a clone of this repo: `git clone --recursive https://github.com/MatthiasQuintern/gz-cpp-util`
|
* - Make a clone of this repo: `git clone https://github.com/MatthiasQuintern/gz-cpp-util`
|
||||||
* - Build and install: `cd src && make && make install`
|
* - Build and install: `cd src && make && make DESTDIR=/usr/local install`
|
||||||
* @subsection main_i_arch Arch Linux (ABS)
|
* @subsection main_i_arch Arch Linux (ABS)
|
||||||
* - Download PKGBUILD: `wget https://raw.github.com/MatthiasQuintern/gz-cpp-util/main/PKGBUILD`
|
* - Download PKGBUILD: `wget https://raw.github.com/MatthiasQuintern/gz-cpp-util/main/PKGBUILD`
|
||||||
* - Build and install with the Arch Build System: `makepkg -si`
|
* - Build and install with the Arch Build System: `makepkg -si`
|
||||||
|
* @subsection main_i_windows Windows
|
||||||
|
* I do not delevop on windows, but you'll figure it out.
|
||||||
|
* The only platform specific code is the color support of the logger, which wont work properly on windows (I will address that in the future).
|
||||||
|
* It should compile with mvsc.
|
||||||
*
|
*
|
||||||
* @subsection main_i_usage Usage
|
* @subsection main_i_usage Usage
|
||||||
* - Add `-lgzutil` to your linker flags
|
* - Add `-lgzutil` to your linker flags
|
||||||
|
15
src/Makefile
15
src/Makefile
@ -15,14 +15,14 @@ OBJECTS = $($(notdir SRC):%.cpp=$(OBJECT_DIR)/%.o)
|
|||||||
OBJECT_DIRS = $(OBJECT_DIR) $(foreach dir,$(SRCDIRS), $(OBJECT_DIR)/$(dir))
|
OBJECT_DIRS = $(OBJECT_DIR) $(foreach dir,$(SRCDIRS), $(OBJECT_DIR)/$(dir))
|
||||||
DEPENDS = ${OBJECTS:.o=.d}
|
DEPENDS = ${OBJECTS:.o=.d}
|
||||||
|
|
||||||
CXXFLAGS += $(IFLAGS)
|
CXXFLAGS += $(IFLAGS)
|
||||||
|
|
||||||
.PHONY: install debug run clean docs
|
.PHONY: install debug run clean docs test
|
||||||
#
|
#
|
||||||
# BUILDING
|
# BUILDING
|
||||||
#
|
#
|
||||||
default: $(LIB)
|
default: $(LIB)
|
||||||
echo $(OBJECTS)
|
@echo $(OBJECTS)
|
||||||
|
|
||||||
# with debug flags
|
# with debug flags
|
||||||
debug: CXXFLAGS += -g # -DDEBUG
|
debug: CXXFLAGS += -g # -DDEBUG
|
||||||
@ -47,6 +47,7 @@ install: $(LIB) $(HEADER_INST)
|
|||||||
@{ [ -z "$(DESTDIR)" ] && echo "Please set the DESTDIR variable (probably to /usr or /usr/local)" && exit 1; } || true
|
@{ [ -z "$(DESTDIR)" ] && echo "Please set the DESTDIR variable (probably to /usr or /usr/local)" && exit 1; } || true
|
||||||
install -D -m 755 $< $(DESTDIR)/lib/$(subst ../,,$<)
|
install -D -m 755 $< $(DESTDIR)/lib/$(subst ../,,$<)
|
||||||
install -D -m 755 ../gen_enum_str.py $(DESTDIR)/bin/gen-enum-str
|
install -D -m 755 ../gen_enum_str.py $(DESTDIR)/bin/gen-enum-str
|
||||||
|
-rm $(HEADER_INST)
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
@{ [ -z "$(DESTDIR)" ] && echo "Please set the DESTDIR variable (probably to /usr or /usr/local)" && exit 1; } || true
|
@{ [ -z "$(DESTDIR)" ] && echo "Please set the DESTDIR variable (probably to /usr or /usr/local)" && exit 1; } || true
|
||||||
@ -62,6 +63,13 @@ $(OBJECT_DIR)/%.stamp: %.hpp $(OBJECT_DIR)
|
|||||||
@touch $@
|
@touch $@
|
||||||
@chmod 777 $@
|
@chmod 777 $@
|
||||||
|
|
||||||
|
#
|
||||||
|
# TESTING
|
||||||
|
#
|
||||||
|
test: CXXFLAGS += -DGZ_UTIL_TESTING
|
||||||
|
test: default
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# EXTRAS
|
# EXTRAS
|
||||||
#
|
#
|
||||||
@ -70,5 +78,6 @@ clean:
|
|||||||
-rm -rf $(OBJECT_DIR)
|
-rm -rf $(OBJECT_DIR)
|
||||||
-rm $(LIB)
|
-rm $(LIB)
|
||||||
|
|
||||||
|
|
||||||
docs:
|
docs:
|
||||||
doxygen .doxygen_config
|
doxygen .doxygen_config
|
||||||
|
21
src/log.cpp
21
src/log.cpp
@ -102,7 +102,9 @@ namespace gz {
|
|||||||
Log::Log(std::shared_ptr<LogResources>&& resources_, bool showLog, const std::string& prefix, Color prefixColor)
|
Log::Log(std::shared_ptr<LogResources>&& resources_, bool showLog, const std::string& prefix, Color prefixColor)
|
||||||
: resources(std::move(resources_)), showLog(showLog), prefixColor(prefixColor), prefix(prefix)
|
: resources(std::move(resources_)), showLog(showLog), prefixColor(prefixColor), prefix(prefix)
|
||||||
{
|
{
|
||||||
|
if (!this->prefix.empty()) {
|
||||||
|
this->prefix += ": ";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -160,18 +162,21 @@ namespace gz {
|
|||||||
void Log::writeLog() {
|
void Log::writeLog() {
|
||||||
std::ofstream file(logFile(), std::ios_base::app);
|
std::ofstream file(logFile(), std::ios_base::app);
|
||||||
if (file.is_open()) {
|
if (file.is_open()) {
|
||||||
for (std::string message : logLines()) {
|
for (size_t i = 0; i < iter(); i++) {
|
||||||
file << message;
|
file << logLines()[i];
|
||||||
|
}
|
||||||
|
iter() = 0;
|
||||||
|
if (showLog) {
|
||||||
|
getTime();
|
||||||
|
std::string message = time();
|
||||||
|
message += "Written log to file: " + logFile() + "\n";
|
||||||
|
std::cout << message;
|
||||||
}
|
}
|
||||||
getTime();
|
|
||||||
std::string message = time();
|
|
||||||
message += "Written log to file: " + logFile() + "\n";
|
|
||||||
/* file << message; */
|
|
||||||
if (showLog) { std::cout << message; }
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::cout << COLORS[RED] << "LOG ERROR: " << COLORS[RESET] << "Could not open file '" << logFile() << "'." << '\n';
|
std::cout << COLORS[RED] << "LOG ERROR: " << COLORS[RESET] << "Could not open file '" << logFile() << "'." << '\n';
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace gz
|
} // namespace gz
|
||||||
|
17
src/log.hpp
17
src/log.hpp
@ -7,9 +7,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#ifndef LOG_NO_SUBLOGS
|
|
||||||
#define LOG_SUBLOGS
|
#define LOG_SUBLOGS
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef LOG_SUBLOGS
|
#ifdef LOG_SUBLOGS
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -182,7 +180,7 @@ class Log {
|
|||||||
*/
|
*/
|
||||||
Log(LogCreateInfo&& createInfo);
|
Log(LogCreateInfo&& createInfo);
|
||||||
#ifdef LOG_SUBLOGS
|
#ifdef LOG_SUBLOGS
|
||||||
Log createSublog(bool showLog, const std::string& prefix, Color prefixColor);
|
Log createSublog(bool showLog, const std::string& prefix, Color prefixColor=gz::Color::RESET);
|
||||||
private:
|
private:
|
||||||
Log(std::shared_ptr<LogResources>&& resources, bool showLog, const std::string& prefix, Color prefixColor);
|
Log(std::shared_ptr<LogResources>&& resources, bool showLog, const std::string& prefix, Color prefixColor);
|
||||||
public:
|
public:
|
||||||
@ -355,7 +353,7 @@ class Log {
|
|||||||
bool showTime_;
|
bool showTime_;
|
||||||
Color timeColor_;
|
Color timeColor_;
|
||||||
/// Stores the current time in yyyy-mm-dd hh:mm:ss format
|
/// Stores the current time in yyyy-mm-dd hh:mm:ss format
|
||||||
char[LOG_TIMESTAMP_CHAR_COUNT] time_;
|
char time_[LOG_TIMESTAMP_CHAR_COUNT];
|
||||||
|
|
||||||
// getters
|
// getters
|
||||||
std::vector<std::string>& logLines() { return logLines_; };
|
std::vector<std::string>& logLines() { return logLines_; };
|
||||||
@ -369,8 +367,13 @@ class Log {
|
|||||||
|
|
||||||
bool& showTime() { return showTime_; };
|
bool& showTime() { return showTime_; };
|
||||||
Color& timeColor() { return timeColor_; };
|
Color& timeColor() { return timeColor_; };
|
||||||
std::string& time() { return time_; };
|
char* time() { return time_; };
|
||||||
#endif
|
#endif
|
||||||
|
/**
|
||||||
|
* @brief Write the log to the logfile
|
||||||
|
* @details
|
||||||
|
* Opens the file in append mode and writes the strings in logLines from 0 to iter to it. Sets iter to 0.
|
||||||
|
*/
|
||||||
void writeLog();
|
void writeLog();
|
||||||
|
|
||||||
bool showLog;
|
bool showLog;
|
||||||
@ -401,7 +404,7 @@ class Log {
|
|||||||
logLines()[iter()] = time();
|
logLines()[iter()] = time();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logLines().clear();
|
logLines()[iter()].clear();
|
||||||
}
|
}
|
||||||
argsBegin().emplace_back(logLines()[iter()].size());
|
argsBegin().emplace_back(logLines()[iter()].size());
|
||||||
logLines()[iter()] += prefix;
|
logLines()[iter()] += prefix;
|
||||||
@ -439,7 +442,7 @@ class Log {
|
|||||||
logLines()[iter()] = std::string(time());
|
logLines()[iter()] = std::string(time());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logLines().clear();
|
logLines()[iter()].clear();
|
||||||
}
|
}
|
||||||
argsBegin().emplace_back(logLines()[iter()].size());
|
argsBegin().emplace_back(logLines()[iter()].size());
|
||||||
logLines()[iter()] += prefix;
|
logLines()[iter()] += prefix;
|
||||||
|
@ -39,7 +39,7 @@ std::vector<T> splitStringInVector(const std::string_view& s, const std::string&
|
|||||||
if (!(skipEmptyStrings and posStart == posEnd)) {
|
if (!(skipEmptyStrings and posStart == posEnd)) {
|
||||||
v.emplace_back(T(s.begin() + posStart, s.begin() + posEnd));
|
v.emplace_back(T(s.begin() + posStart, s.begin() + posEnd));
|
||||||
}
|
}
|
||||||
posStart = posEnd + 1;
|
posStart = posEnd + separator.size();
|
||||||
posEnd = s.find(separator, posStart);
|
posEnd = s.find(separator, posStart);
|
||||||
}
|
}
|
||||||
// last element
|
// last element
|
||||||
|
Loading…
Reference in New Issue
Block a user