Mistake on this page?
Report an issue in GitHub or email us
wstr.h
Go to the documentation of this file.
1 /*************************************************************************************************/
2 /*!
3  * \file wstr.h
4  *
5  * \brief String manipulation functions.
6  *
7  * Copyright (c) 2014-2018 Arm Ltd. All Rights Reserved.
8  *
9  * Copyright (c) 2019-2020 Packetcraft, Inc.
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 /*************************************************************************************************/
24 
25 #ifndef WSTR_H
26 #define WSTR_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 /*! \addtogroup WSF_UTIL_API
33  * \{ */
34 
35 /**************************************************************************************************
36  Macros
37 **************************************************************************************************/
38 
39 /*! HEX format '0x' or '0X' check */
40 #define WSTR_IS_HEX_FORMAT(c) (((char)(c)[0] == '0') && \
41  (((char)(c)[1] == 'x') || ((char)(c)[1] == 'X')))
42 
43 /*! Binary format '0b' check */
44 #define WSTR_IS_BIN_FORMAT(c) (((char)(c)[0] == '0') && ((char)(c)[1] == 'b'))
45 
46 /*************************************************************************************************/
47 /*!
48  * \brief Copies a string up to a given length.
49  *
50  * \param pBuf Pointer to buffer to copy to.
51  * \param pData Pointer to the string to copy.
52  * \param n Size of pBuf in bytes.
53  *
54  * \return none.
55  */
56 /*************************************************************************************************/
57 void WstrnCpy(char *pBuf, const char *pData, uint8_t n);
58 
59 /*************************************************************************************************/
60 /*!
61  * \brief Byte by byte reverse and copy a buffer.
62  *
63  * \param pBuf1 Buffer to hold reversed copy.
64  * \param pBuf2 Buffer to copy.
65  * \param len Size of pBuf1 and pBuf2 in bytes.
66  */
67 /*************************************************************************************************/
68 void WStrReverseCpy(uint8_t *pBuf1, const uint8_t *pBuf2, uint16_t len);
69 
70 /*************************************************************************************************/
71 /*!
72  * \brief Byte by byte reverse a buffer.
73  *
74  * \param pBuf Buffer to reverse.
75  * \param len size of pBuf in bytes.
76  */
77 /*************************************************************************************************/
78 void WStrReverse(uint8_t *pBuf, uint8_t len);
79 
80 /*************************************************************************************************/
81 /*!
82  * \brief Format a hex value.
83  *
84  * \param pBuf Storage for string representation of value.
85  * \param val Value.
86  * \param len Length of value, in bits.
87  */
88 /*************************************************************************************************/
89 void WStrFormatHex(char *pBuf, uint32_t val, uint8_t len);
90 
91 /*************************************************************************************************/
92 /*!
93  * \brief Convert a formatted string to int array, zero out space after the string length.
94  *
95  * \param pStr Pointer to the string to convert.
96  * \param pBuf Pointer to destination buffer.
97  * \param len Size of pBuf in bytes.
98  *
99  * \return none.
100  */
101 /*************************************************************************************************/
102 void WStrHexToArray(const char *pStr, uint8_t *pBuf, uint16_t len);
103 
104 /*! \} */ /* WSF_UTIL_API */
105 
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif /* WSTR_H */
void WStrReverseCpy(uint8_t *pBuf1, const uint8_t *pBuf2, uint16_t len)
Byte by byte reverse and copy a buffer.
void WStrHexToArray(const char *pStr, uint8_t *pBuf, uint16_t len)
Convert a formatted string to int array, zero out space after the string length.
void WStrFormatHex(char *pBuf, uint32_t val, uint8_t len)
Format a hex value.
void WstrnCpy(char *pBuf, const char *pData, uint8_t n)
Copies a string up to a given length.
void WStrReverse(uint8_t *pBuf, uint8_t len)
Byte by byte reverse a buffer.
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.