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

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.