Zvikomborero VIncent Zvikaramba | 5b852f6 | 2016-07-22 01:37:09 -0400 | [diff] [blame] | 1 | /* Copyright (c) 2014, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are |
| 5 | * met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer in the documentation and/or other materials provided |
| 11 | * with the distribution. |
| 12 | * * Neither the name of The Linux Foundation, nor the names of its |
| 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | * |
| 28 | */ |
| 29 | #ifndef _LOC_MISC_UTILS_H_ |
| 30 | #define _LOC_MISC_UTILS_H_ |
| 31 | |
| 32 | #ifdef __cplusplus |
| 33 | extern "C" { |
| 34 | #endif |
| 35 | |
| 36 | /*=========================================================================== |
| 37 | FUNCTION loc_split_string |
| 38 | |
| 39 | DESCRIPTION: |
| 40 | This function is used to split a delimiter separated string into |
| 41 | sub-strings. This function does not allocate new memory to store the split |
| 42 | strings. Instead, it places '\0' in places of delimiters and assings the |
| 43 | starting address of the substring within the raw string as the string address |
| 44 | The input raw_string no longer remains to be a collection of sub-strings |
| 45 | after this function is executed. |
| 46 | Please make a copy of the input string before calling this function if |
| 47 | necessary |
| 48 | |
| 49 | PARAMETERS: |
| 50 | char *raw_string: is the original string with delimiter separated substrings |
| 51 | char **split_strings_ptr: is the arraw of pointers which will hold the addresses |
| 52 | of individual substrings |
| 53 | int max_num_substrings: is the maximum number of substrings that are expected |
| 54 | by the caller. The array of pointers in the above parameter |
| 55 | is usually this long |
| 56 | char delimiter: is the delimiter that separates the substrings. Examples: ' ', ';' |
| 57 | |
| 58 | DEPENDENCIES |
| 59 | N/A |
| 60 | |
| 61 | RETURN VALUE |
| 62 | int Number of split strings |
| 63 | |
| 64 | SIDE EFFECTS |
| 65 | The input raw_string no longer remains a delimiter separated single string. |
| 66 | |
| 67 | EXAMPLE |
| 68 | delimiter = ' ' //space |
| 69 | raw_string = "hello new user" //delimiter is space ' ' |
| 70 | addresses = 0123456789abcd |
| 71 | split_strings_ptr[0] = &raw_string[0]; //split_strings_ptr[0] contains "hello" |
| 72 | split_strings_ptr[1] = &raw_string[6]; //split_strings_ptr[1] contains "new" |
| 73 | split_strings_ptr[2] = &raw_string[a]; //split_strings_ptr[2] contains "user" |
| 74 | |
| 75 | ===========================================================================*/ |
| 76 | int loc_util_split_string(char *raw_string, char **split_strings_ptr, int max_num_substrings, |
| 77 | char delimiter); |
| 78 | |
| 79 | /*=========================================================================== |
| 80 | FUNCTION trim_space |
| 81 | |
| 82 | DESCRIPTION |
| 83 | Removes leading and trailing spaces of the string |
| 84 | |
| 85 | DEPENDENCIES |
| 86 | N/A |
| 87 | |
| 88 | RETURN VALUE |
| 89 | None |
| 90 | |
| 91 | SIDE EFFECTS |
| 92 | N/A |
| 93 | ===========================================================================*/ |
| 94 | void loc_util_trim_space(char *org_string); |
| 95 | #ifdef __cplusplus |
| 96 | } |
| 97 | #endif |
| 98 | |
| 99 | #endif //_LOC_MISC_UTILS_H_ |