Mbed OS Reference
Loading...
Searching...
No Matches
util.h
1/* mbed Microcontroller Library
2 * Copyright (c) 2018 ARM Limited
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef FEATURES_NFC_SOURCE_NFC_COMMON_UTIL_H_
19#define FEATURES_NFC_SOURCE_NFC_COMMON_UTIL_H_
20
21#include "platform/Span.h"
22
23namespace mbed {
24namespace nfc {
25namespace ndef {
26namespace common {
27
28/**
29 * @addtogroup nfc
30 * @{
31 */
32
33/**
34 * Convert a C-string into a Span<const uint8_t>.
35 *
36 * @note The NULL charactere is not present in the resulting object.
37 *
38 * @param cstr The cstr to convert into a Span.
39 *
40 * @return A Span that views cstr but doesn't include the NULL terminator
41 * character.
42 */
43template<size_t N>
44Span < const uint8_t, N - 1 > span_from_cstr(const char (&cstr)[N])
45{
46 return Span < const uint8_t, N - 1 > ((const uint8_t *)cstr, N - 1);
47}
48
49/**
50 * Convert a C-string into a Span<const uint8_t>.
51 *
52 * @note The NULL charactere is not present in the resulting object.
53 *
54 * @param cstr The cstr to convert into a Span.
55 *
56 * @return A Span that views cstr but doesn't include the NULL terminator
57 * character.
58 */
60
61/**
62 * @}
63 */
64
65} // namespace common
66} // namespace ndef
67} // namespace nfc
68} // namespace mbed
69
70#endif /* FEATURES_NFC_SOURCE_NFC_COMMON_UTIL_H_ */
Span< const uint8_t, N - 1 > span_from_cstr(const char(&cstr)[N])
Convert a C-string into a Span<const uint8_t>.
Definition: util.h:44
Nonowning view to a sequence of contiguous elements.
Definition: Span.h:215