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
|
||||
* @subsection main_i_linux Linux
|
||||
* - Make a clone of this repo: `git clone --recursive https://github.com/MatthiasQuintern/gz-cpp-util`
|
||||
* - Build and install: `cd src && make && make install`
|
||||
* - Make a clone of this repo: `git clone https://github.com/MatthiasQuintern/gz-cpp-util`
|
||||
* - Build and install: `cd src && make && make DESTDIR=/usr/local install`
|
||||
* @subsection main_i_arch Arch Linux (ABS)
|
||||
* - Download PKGBUILD: `wget https://raw.github.com/MatthiasQuintern/gz-cpp-util/main/PKGBUILD`
|
||||
* - 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
|
||||
* - 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))
|
||||
DEPENDS = ${OBJECTS:.o=.d}
|
||||
|
||||
CXXFLAGS += $(IFLAGS)
|
||||
CXXFLAGS += $(IFLAGS)
|
||||
|
||||
.PHONY: install debug run clean docs
|
||||
.PHONY: install debug run clean docs test
|
||||
#
|
||||
# BUILDING
|
||||
#
|
||||
default: $(LIB)
|
||||
echo $(OBJECTS)
|
||||
@echo $(OBJECTS)
|
||||
|
||||
# with debug flags
|
||||
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
|
||||
install -D -m 755 $< $(DESTDIR)/lib/$(subst ../,,$<)
|
||||
install -D -m 755 ../gen_enum_str.py $(DESTDIR)/bin/gen-enum-str
|
||||
-rm $(HEADER_INST)
|
||||
|
||||
uninstall:
|
||||
@{ [ -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 $@
|
||||
@chmod 777 $@
|
||||
|
||||
#
|
||||
# TESTING
|
||||
#
|
||||
test: CXXFLAGS += -DGZ_UTIL_TESTING
|
||||
test: default
|
||||
|
||||
|
||||
#
|
||||
# EXTRAS
|
||||
#
|
||||
@ -70,5 +78,6 @@ clean:
|
||||
-rm -rf $(OBJECT_DIR)
|
||||
-rm $(LIB)
|
||||
|
||||
|
||||
docs:
|
||||
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)
|
||||
: resources(std::move(resources_)), showLog(showLog), prefixColor(prefixColor), prefix(prefix)
|
||||
{
|
||||
|
||||
if (!this->prefix.empty()) {
|
||||
this->prefix += ": ";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -160,18 +162,21 @@ namespace gz {
|
||||
void Log::writeLog() {
|
||||
std::ofstream file(logFile(), std::ios_base::app);
|
||||
if (file.is_open()) {
|
||||
for (std::string message : logLines()) {
|
||||
file << message;
|
||||
for (size_t i = 0; i < iter(); i++) {
|
||||
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 {
|
||||
std::cout << COLORS[RED] << "LOG ERROR: " << COLORS[RESET] << "Could not open file '" << logFile() << "'." << '\n';
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
} // namespace gz
|
||||
|
17
src/log.hpp
17
src/log.hpp
@ -7,9 +7,7 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#ifndef LOG_NO_SUBLOGS
|
||||
#define LOG_SUBLOGS
|
||||
#endif
|
||||
|
||||
#ifdef LOG_SUBLOGS
|
||||
#include <memory>
|
||||
@ -182,7 +180,7 @@ class Log {
|
||||
*/
|
||||
Log(LogCreateInfo&& createInfo);
|
||||
#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:
|
||||
Log(std::shared_ptr<LogResources>&& resources, bool showLog, const std::string& prefix, Color prefixColor);
|
||||
public:
|
||||
@ -355,7 +353,7 @@ class Log {
|
||||
bool showTime_;
|
||||
Color timeColor_;
|
||||
/// 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
|
||||
std::vector<std::string>& logLines() { return logLines_; };
|
||||
@ -369,8 +367,13 @@ class Log {
|
||||
|
||||
bool& showTime() { return showTime_; };
|
||||
Color& timeColor() { return timeColor_; };
|
||||
std::string& time() { return time_; };
|
||||
char* time() { return time_; };
|
||||
#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();
|
||||
|
||||
bool showLog;
|
||||
@ -401,7 +404,7 @@ class Log {
|
||||
logLines()[iter()] = time();
|
||||
}
|
||||
else {
|
||||
logLines().clear();
|
||||
logLines()[iter()].clear();
|
||||
}
|
||||
argsBegin().emplace_back(logLines()[iter()].size());
|
||||
logLines()[iter()] += prefix;
|
||||
@ -439,7 +442,7 @@ class Log {
|
||||
logLines()[iter()] = std::string(time());
|
||||
}
|
||||
else {
|
||||
logLines().clear();
|
||||
logLines()[iter()].clear();
|
||||
}
|
||||
argsBegin().emplace_back(logLines()[iter()].size());
|
||||
logLines()[iter()] += prefix;
|
||||
|
@ -39,7 +39,7 @@ std::vector<T> splitStringInVector(const std::string_view& s, const std::string&
|
||||
if (!(skipEmptyStrings and posStart == posEnd)) {
|
||||
v.emplace_back(T(s.begin() + posStart, s.begin() + posEnd));
|
||||
}
|
||||
posStart = posEnd + 1;
|
||||
posStart = posEnd + separator.size();
|
||||
posEnd = s.find(separator, posStart);
|
||||
}
|
||||
// last element
|
||||
|
Loading…
Reference in New Issue
Block a user