Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
strconv.h
00001 /* 00002 * Copyright (c) 2018 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #ifndef STRCONVERSION_H 00017 #define STRCONVERSION_H 00018 00019 #ifdef __cplusplus 00020 extern "C" { 00021 #endif 00022 00023 #include "ns_types.h" 00024 00025 /** Convert hex string to binary array 00026 * e.g. 00027 * char str[] = {30, 31, 32, 33}; 00028 * uint8_t buffer[4]; 00029 * strtohex( buffer, str, 4 ); 00030 */ 00031 int8_t strtohex(uint8_t *out, const char *str, int8_t max_length); 00032 00033 /** Convert space separated hex string (eg. "76 ab ff") to binary array. 00034 */ 00035 int string_to_bytes(const char *str, uint8_t *buf, int bytes); 00036 00037 /** Convert a colon/space separated hex string (eg. "76:ab:ff") to binary 00038 * array (inplace) returning the number of the bytes in the array. 00039 */ 00040 int hexstr_to_bytes_inplace(char *str); 00041 00042 /** Convert hex array to string 00043 */ 00044 int16_t hextostr(const uint8_t *buf, uint16_t buf_length, char *out, int16_t out_length, char delimiter); 00045 /** Replace hex characters from string 00046 * e.g. 00047 * "hello\\n" -> "hello\n" 00048 * "hello\\r" -> "hello\r" 00049 * "val: \\10" -> "val: \x0a" //integer 00050 * "val: \\x10" -> "val: \x10" //hex value 00051 * @param str string that will be replaced 00052 * @return length 00053 */ 00054 int replace_hexdata(char *str); 00055 /** 00056 * check if array contains only visible characters 00057 * = isalpha | isdigit 00058 */ 00059 bool is_visible(uint8_t *buf, int len); 00060 00061 /** Convert ipv6 address to string format 00062 */ 00063 char *print_ipv6(const void *addr_ptr); 00064 /** Convert ipv6 prefix to string format 00065 */ 00066 char *print_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len); 00067 /** Convert binary array to string format and return static results 00068 */ 00069 char *print_array(const uint8_t *buf, uint16_t len); 00070 /** The strdupl() function shall return a pointer to a new string, 00071 * which is a duplicate of the string pointed to by s1. The returned pointer can be passed to free(). 00072 * A null pointer is returned if the new string cannot be created. 00073 * strdupl are same than linux strdup, but this way we avoid to duplicate reference in linux 00074 */ 00075 char *strdupl(const char *str); 00076 /** The strdup() function returns a pointer to a new string which is a duplicate of the string. 00077 * Memory for the new string is obtained with malloc(3), and can be freed with free(3). 00078 * The strndup() function is similar, but only copies at most n bytes. If s is longer than n, 00079 * only n bytes are copied, and a terminating null byte ('\0') is added. 00080 */ 00081 char *strndupl(const char *s, int n); 00082 /** strnlen - determine the length of a fixed-size string 00083 * The strnlen() function returns the number of bytes in the string pointed to by s, excluding the terminating null bye ('\0'), but at most maxlen. 00084 * In doing this, strnlen() looks only at the first maxlen bytes at s and never beyond s+maxlen. 00085 * The strnlen() function returns strlen(s), if that is less than maxlen, or maxlen if there is no null byte ('\0') 00086 * among the first maxlen bytes pointed to by s. 00087 */ 00088 int strnlen_(const char *s, int n); 00089 /** strnicmp compares a and b without sensitivity to case. 00090 * All alphabetic characters in the two arguments a and b are converted to lowercase before the comparison. 00091 */ 00092 int strnicmp_(char const *a, char const *b, int n); 00093 00094 #ifdef __cplusplus 00095 } 00096 #endif 00097 #endif 00098
Generated on Tue Aug 9 2022 00:37:21 by
1.7.2