mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-18 15:57:13 +02:00
added string_utils and strcpy_safe
This commit is contained in:
@ -98,6 +98,8 @@ T minusOneIfDifferent(const std::vector<T>& container)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//TODO!(Erik)Should try to move away from using this in the slsDetectorPackage
|
||||
inline
|
||||
std::string concatenateIfDifferent(std::vector<std::string> container)
|
||||
|
17
slsSupportLib/include/string_utils.h
Normal file
17
slsSupportLib/include/string_utils.h
Normal file
@ -0,0 +1,17 @@
|
||||
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'.
|
||||
|
||||
Warning this would truncate the source string and should be used with care.
|
||||
Still this is better than strcpy...
|
||||
*/
|
||||
template <size_t array_size>
|
||||
void strcpy_safe(char (&destination)[array_size], const char *source) {
|
||||
strncpy(destination, source, array_size);
|
||||
destination[array_size - 1] = '\0';
|
||||
}
|
||||
|
||||
|
||||
}; // namespace sls
|
9
slsSupportLib/src/string_utils.cpp
Normal file
9
slsSupportLib/src/string_utils.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
// #include <cstring>
|
||||
// namespace sls{
|
||||
|
||||
// void strcpy_safe(char *dst, const char *src, size_t size){
|
||||
// strncpy(dst, src, size);
|
||||
// }
|
||||
|
||||
// };
|
Reference in New Issue
Block a user