![](/media/cache/profiles/20200518_163046.jpg.50x50_q85.jpg)
CITY3032-wifi-mqtt
connectivity-utilities/cy_string/cy_string_utils.h@4:7ebc3d28bcb2, 2021-11-13 (annotated)
- Committer:
- reedas
- Date:
- Sat Nov 13 11:31:22 2021 +0000
- Revision:
- 4:7ebc3d28bcb2
flattened
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
reedas | 4:7ebc3d28bcb2 | 1 | /* |
reedas | 4:7ebc3d28bcb2 | 2 | * Copyright 2019-2021, Cypress Semiconductor Corporation (an Infineon company) or |
reedas | 4:7ebc3d28bcb2 | 3 | * an affiliate of Cypress Semiconductor Corporation. All rights reserved. |
reedas | 4:7ebc3d28bcb2 | 4 | * |
reedas | 4:7ebc3d28bcb2 | 5 | * This software, including source code, documentation and related |
reedas | 4:7ebc3d28bcb2 | 6 | * materials ("Software") is owned by Cypress Semiconductor Corporation |
reedas | 4:7ebc3d28bcb2 | 7 | * or one of its affiliates ("Cypress") and is protected by and subject to |
reedas | 4:7ebc3d28bcb2 | 8 | * worldwide patent protection (United States and foreign), |
reedas | 4:7ebc3d28bcb2 | 9 | * United States copyright laws and international treaty provisions. |
reedas | 4:7ebc3d28bcb2 | 10 | * Therefore, you may use this Software only as provided in the license |
reedas | 4:7ebc3d28bcb2 | 11 | * agreement accompanying the software package from which you |
reedas | 4:7ebc3d28bcb2 | 12 | * obtained this Software ("EULA"). |
reedas | 4:7ebc3d28bcb2 | 13 | * If no EULA applies, Cypress hereby grants you a personal, non-exclusive, |
reedas | 4:7ebc3d28bcb2 | 14 | * non-transferable license to copy, modify, and compile the Software |
reedas | 4:7ebc3d28bcb2 | 15 | * source code solely for use in connection with Cypress's |
reedas | 4:7ebc3d28bcb2 | 16 | * integrated circuit products. Any reproduction, modification, translation, |
reedas | 4:7ebc3d28bcb2 | 17 | * compilation, or representation of this Software except as specified |
reedas | 4:7ebc3d28bcb2 | 18 | * above is prohibited without the express written permission of Cypress. |
reedas | 4:7ebc3d28bcb2 | 19 | * |
reedas | 4:7ebc3d28bcb2 | 20 | * Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND, |
reedas | 4:7ebc3d28bcb2 | 21 | * EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED |
reedas | 4:7ebc3d28bcb2 | 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress |
reedas | 4:7ebc3d28bcb2 | 23 | * reserves the right to make changes to the Software without notice. Cypress |
reedas | 4:7ebc3d28bcb2 | 24 | * does not assume any liability arising out of the application or use of the |
reedas | 4:7ebc3d28bcb2 | 25 | * Software or any product or circuit described in the Software. Cypress does |
reedas | 4:7ebc3d28bcb2 | 26 | * not authorize its products for use in any products where a malfunction or |
reedas | 4:7ebc3d28bcb2 | 27 | * failure of the Cypress product may reasonably be expected to result in |
reedas | 4:7ebc3d28bcb2 | 28 | * significant property damage, injury or death ("High Risk Product"). By |
reedas | 4:7ebc3d28bcb2 | 29 | * including Cypress's product in a High Risk Product, the manufacturer |
reedas | 4:7ebc3d28bcb2 | 30 | * of such system or application assumes all risk of such use and in doing |
reedas | 4:7ebc3d28bcb2 | 31 | * so agrees to indemnify Cypress against all liability. |
reedas | 4:7ebc3d28bcb2 | 32 | */ |
reedas | 4:7ebc3d28bcb2 | 33 | |
reedas | 4:7ebc3d28bcb2 | 34 | /* |
reedas | 4:7ebc3d28bcb2 | 35 | * @file |
reedas | 4:7ebc3d28bcb2 | 36 | * The string utilities module is a collection of string conversion helpers to convert between integer and strings |
reedas | 4:7ebc3d28bcb2 | 37 | * |
reedas | 4:7ebc3d28bcb2 | 38 | */ |
reedas | 4:7ebc3d28bcb2 | 39 | |
reedas | 4:7ebc3d28bcb2 | 40 | #ifndef __CY_STRING_H__ |
reedas | 4:7ebc3d28bcb2 | 41 | #define __CY_STRING_H__ |
reedas | 4:7ebc3d28bcb2 | 42 | |
reedas | 4:7ebc3d28bcb2 | 43 | #ifdef __cplusplus |
reedas | 4:7ebc3d28bcb2 | 44 | extern "C" { |
reedas | 4:7ebc3d28bcb2 | 45 | #endif |
reedas | 4:7ebc3d28bcb2 | 46 | |
reedas | 4:7ebc3d28bcb2 | 47 | /** \addtogroup string_utils |
reedas | 4:7ebc3d28bcb2 | 48 | * The string utilities module is a collection of string conversion helpers to convert between integer and strings. |
reedas | 4:7ebc3d28bcb2 | 49 | */ |
reedas | 4:7ebc3d28bcb2 | 50 | |
reedas | 4:7ebc3d28bcb2 | 51 | /*****************************************************************************/ |
reedas | 4:7ebc3d28bcb2 | 52 | /** |
reedas | 4:7ebc3d28bcb2 | 53 | * |
reedas | 4:7ebc3d28bcb2 | 54 | * @addtogroup group_string_func |
reedas | 4:7ebc3d28bcb2 | 55 | * |
reedas | 4:7ebc3d28bcb2 | 56 | * The string utilities module is a collection of string conversion helpers to convert between integer and strings |
reedas | 4:7ebc3d28bcb2 | 57 | * |
reedas | 4:7ebc3d28bcb2 | 58 | * @{ |
reedas | 4:7ebc3d28bcb2 | 59 | */ |
reedas | 4:7ebc3d28bcb2 | 60 | /*****************************************************************************/ |
reedas | 4:7ebc3d28bcb2 | 61 | |
reedas | 4:7ebc3d28bcb2 | 62 | /*! |
reedas | 4:7ebc3d28bcb2 | 63 | ****************************************************************************** |
reedas | 4:7ebc3d28bcb2 | 64 | * Convert a decimal or hexidecimal string to an integer. |
reedas | 4:7ebc3d28bcb2 | 65 | * |
reedas | 4:7ebc3d28bcb2 | 66 | * @param[in] str The string containing the value. |
reedas | 4:7ebc3d28bcb2 | 67 | * |
reedas | 4:7ebc3d28bcb2 | 68 | * @return The value represented by the string. |
reedas | 4:7ebc3d28bcb2 | 69 | */ |
reedas | 4:7ebc3d28bcb2 | 70 | uint32_t cy_generic_string_to_unsigned( const char* str ); |
reedas | 4:7ebc3d28bcb2 | 71 | |
reedas | 4:7ebc3d28bcb2 | 72 | /** |
reedas | 4:7ebc3d28bcb2 | 73 | * Converts a decimal/hexidecimal string (with optional sign) to a signed long int |
reedas | 4:7ebc3d28bcb2 | 74 | * Better than strtol or atol or atoi because the return value indicates if an error occurred |
reedas | 4:7ebc3d28bcb2 | 75 | * |
reedas | 4:7ebc3d28bcb2 | 76 | * @param[in] string : The string buffer to be converted |
reedas | 4:7ebc3d28bcb2 | 77 | * @param[in] str_length : The maximum number of characters to process in the string buffer |
reedas | 4:7ebc3d28bcb2 | 78 | * @param[out] value_out : The unsigned in that will receive value of the the decimal string |
reedas | 4:7ebc3d28bcb2 | 79 | * @param[in] is_hex : 0 = Decimal string, 1 = Hexidecimal string |
reedas | 4:7ebc3d28bcb2 | 80 | * |
reedas | 4:7ebc3d28bcb2 | 81 | * @return the number of characters successfully converted (including sign). i.e. 0 = error |
reedas | 4:7ebc3d28bcb2 | 82 | * |
reedas | 4:7ebc3d28bcb2 | 83 | */ |
reedas | 4:7ebc3d28bcb2 | 84 | uint8_t cy_string_to_signed( const char* string, uint16_t str_length, int32_t* value_out, uint8_t is_hex ); |
reedas | 4:7ebc3d28bcb2 | 85 | |
reedas | 4:7ebc3d28bcb2 | 86 | |
reedas | 4:7ebc3d28bcb2 | 87 | /** |
reedas | 4:7ebc3d28bcb2 | 88 | * Converts a decimal/hexidecimal string to an unsigned long int |
reedas | 4:7ebc3d28bcb2 | 89 | * Better than strtol or atol or atoi because the return value indicates if an error occurred |
reedas | 4:7ebc3d28bcb2 | 90 | * |
reedas | 4:7ebc3d28bcb2 | 91 | * @param[in] string : The string buffer to be converted |
reedas | 4:7ebc3d28bcb2 | 92 | * @param[in] str_length : The maximum number of characters to process in the string buffer |
reedas | 4:7ebc3d28bcb2 | 93 | * @param[out] value_out : The unsigned in that will receive value of the the decimal string |
reedas | 4:7ebc3d28bcb2 | 94 | * @param[in] is_hex : 0 = Decimal string, 1 = Hexidecimal string |
reedas | 4:7ebc3d28bcb2 | 95 | * |
reedas | 4:7ebc3d28bcb2 | 96 | * @return the number of characters successfully converted. i.e. 0 = error |
reedas | 4:7ebc3d28bcb2 | 97 | * |
reedas | 4:7ebc3d28bcb2 | 98 | */ |
reedas | 4:7ebc3d28bcb2 | 99 | uint8_t cy_string_to_unsigned( const char* string, uint8_t str_length, uint32_t* value_out, uint8_t is_hex ); |
reedas | 4:7ebc3d28bcb2 | 100 | |
reedas | 4:7ebc3d28bcb2 | 101 | /** @} */ |
reedas | 4:7ebc3d28bcb2 | 102 | |
reedas | 4:7ebc3d28bcb2 | 103 | #ifdef __cplusplus |
reedas | 4:7ebc3d28bcb2 | 104 | } |
reedas | 4:7ebc3d28bcb2 | 105 | #endif |
reedas | 4:7ebc3d28bcb2 | 106 | |
reedas | 4:7ebc3d28bcb2 | 107 | |
reedas | 4:7ebc3d28bcb2 | 108 | #endif /* __CY_STRING_H__ */ |