Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a CopyCharSpanToMutableCharSpanTruncate function. #35360

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/lib/support/Span.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,18 @@ inline CHIP_ERROR CopyCharSpanToMutableCharSpan(CharSpan cspan_to_copy, MutableC
return CHIP_NO_ERROR;
}

/**
* Copies a CharSpan into a MutableCharSpan.
* If the span_to_copy does not if in out_span, span_to_copy in truncated to fit in out_span.
* @param span_to_copy The CharSpan to copy.
* @param out_span The MutableCharSpan in which span_to_copy is to be copied.
*/
inline void CopyCharSpanToMutableCharSpanTruncate(CharSpan span_to_copy, MutableCharSpan & out_span)
{
size_t size_to_copy = std::min(span_to_copy.size(), out_span.size());

memcpy(out_span.data(), span_to_copy.data(), size_to_copy);
out_span.reduce_size(size_to_copy);
}

} // namespace chip
Loading