F´ Flight Software - C/C++ Documentation
NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
StringUtils.cpp
Go to the documentation of this file.
1
#include "
StringUtils.hpp
"
2
#include <
Fw/Types/Assert.hpp
>
3
#include <cstring>
4
5
char
*
Fw::StringUtils::string_copy
(
char
* destination,
const
char
* source, U32 num) {
6
// Handle self-copy
7
if
(destination == source) {
8
return
destination;
9
}
10
11
// Copying an overlapping range is undefined
12
U32 source_len =
string_length
(source, num) + 1;
13
FW_ASSERT
(source + source_len <= destination || destination + num <= source);
14
15
char
* returned = strncpy(destination, source, num);
16
destination[num - 1] =
'\0'
;
17
return
returned;
18
}
19
20
U32
Fw::StringUtils::string_length
(
const
CHAR
* source, U32 max_len) {
21
return
strnlen(source, max_len);
22
}
CHAR
char CHAR
Definition:
BasicTypes.hpp:99
StringUtils.hpp
Assert.hpp
Fw::StringUtils::string_copy
char * string_copy(char *destination, const char *source, U32 num)
copy string with null-termination guaranteed
Definition:
StringUtils.cpp:5
FW_ASSERT
#define FW_ASSERT(...)
Definition:
Assert.hpp:8
Fw::StringUtils::string_length
U32 string_length(const CHAR *source, U32 max_len)
get the length of the source string or max_len if the string is longer than max_len.
Definition:
StringUtils.cpp:20
Fw
Types
StringUtils.cpp
Generated by
1.8.17