* WIP

* WIP

* WIP

* cleaned up multi

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* split up python module

* WIP

* WIP

* WIP

* WIP

* WIP

* ok

* fixed bugs from rebase

* WIP

* fixed broken test

* WIP

* fixed python

* WIP

* sphinx help

* including new commands

* docs

* WIP

* WIP

* more tests

* added missing public header

* WIP
This commit is contained in:
Dhanya Thattil
2019-08-07 11:21:07 +02:00
committed by GitHub
parent 98ddf154b2
commit 4ceee97c03
58 changed files with 2317 additions and 571 deletions

View File

@ -1,30 +1,30 @@
#pragma once
#include <string>
#include <vector>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
namespace sls {
/* Implementation of a safe string copy function for setting fields in
for example the multi sls detector. It tries to copy the size of the
destination from the source, stopping on '\0'.
/* Implementation of a safe string copy function for setting fields in
for example the multi sls detector. It tries to copy the size of the
destination from the source, stopping on '\0'.
Warning this will truncate the source string and should be used with care.
Warning this will truncate the source string and should be used with care.
Still this is better than strcpy and a buffer overflow...
*/
template <size_t array_size>
void strcpy_safe(char (&destination)[array_size], const char *source) {
assert(array_size > strlen(source));
strncpy(destination, source, array_size-1);
strncpy(destination, source, array_size - 1);
destination[array_size - 1] = '\0';
}
template <size_t array_size>
void strcpy_safe(char (&destination)[array_size], const std::string& source) {
void strcpy_safe(char (&destination)[array_size], const std::string &source) {
assert(array_size > source.size());
strncpy(destination, source.c_str(), array_size-1);
strncpy(destination, source.c_str(), array_size - 1);
destination[array_size - 1] = '\0';
}
@ -32,8 +32,7 @@ void strcpy_safe(char (&destination)[array_size], const std::string& source) {
Removes all occurrences of the specified char from a c string
Templated on array size to ensure no access after buffer limits.
*/
template <size_t array_size>
void removeChar(char (&str)[array_size], char ch) {
template <size_t array_size> void removeChar(char (&str)[array_size], char ch) {
int count = 0;
for (int i = 0; str[i]; i++) {
if (str[i] != ch)
@ -44,7 +43,7 @@ void removeChar(char (&str)[array_size], char ch) {
str[count] = '\0';
}
/*
/*
Split a string using the specified delimeter and return a vector of strings.
TODO! Look into switching to absl or a string_view based implementation. Current
implementation should not be used in a performance critical place.
@ -62,9 +61,10 @@ Concatenate strings using + if the strings are different
std::string concatenateIfDifferent(const std::vector<std::string> &container);
/*
Concatenate vector of things with str method using + if the strings are different
Concatenate vector of things with str method using + if the strings are
different
*/
template<typename T>
template <typename T>
std::string concatenateIfDifferent(const std::vector<T> &container);
/*
@ -72,4 +72,7 @@ Convert an ip address string to a string in hex format. (removing dots)
*/
std::string stringIpToHex(const std::string &ip);
// remove the end of the string starting with the first aplhabetic character
// return the end
std::string RemoveUnit(std::string &str);
}; // namespace sls