qcacmn: Add qdf_str files to QDF
Add files for QDF string APIs. Existing qdf_str_* APIs will be moved as part of a future change. Change-Id: If98d41380b2f7f62bbe5de141b6827e9427944ab CRs-Fixed: 2184462
This commit is contained in:
91
qdf/inc/qdf_str.h
Normal file
91
qdf/inc/qdf_str.h
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 The Linux Foundation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for
|
||||||
|
* any purpose with or without fee is hereby granted, provided that the
|
||||||
|
* above copyright notice and this permission notice appear in all
|
||||||
|
* copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
||||||
|
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
||||||
|
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||||
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||||
|
* PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DOC: qdf_str
|
||||||
|
* QCA driver framework (QDF) string APIs.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __QDF_STR_H
|
||||||
|
#define __QDF_STR_H
|
||||||
|
|
||||||
|
#include "i_qdf_str.h"
|
||||||
|
#include "qdf_types.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* qdf_is_space() - check if @c is a whitespace character
|
||||||
|
* @c: the character to check
|
||||||
|
*
|
||||||
|
* Whitespace characters include HT, LF, VT, FF, CR, space, and nbsp
|
||||||
|
*
|
||||||
|
* Return: true if @ is a whitespace character
|
||||||
|
*/
|
||||||
|
static inline bool qdf_is_space(char c)
|
||||||
|
{
|
||||||
|
return __qdf_is_space(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* qdf_str_left_trim() - Trim any leading whitespace from @str
|
||||||
|
* @str: the string to trim
|
||||||
|
*
|
||||||
|
* Return: A pointer to the first non-space character in @str
|
||||||
|
*/
|
||||||
|
static inline char *qdf_str_left_trim(char *str)
|
||||||
|
{
|
||||||
|
return __qdf_str_left_trim(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* qdf_str_right_trim() - Trim any trailing whitespace from @str
|
||||||
|
* @str: the string to trim
|
||||||
|
*
|
||||||
|
* Note: The first trailing whitespace character is replaced with a
|
||||||
|
* null-terminator
|
||||||
|
*
|
||||||
|
* Return: None
|
||||||
|
*/
|
||||||
|
void qdf_str_right_trim(char *str);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* qdf_str_trim() - Trim any leading/trailing whitespace from @str
|
||||||
|
* @str: the string to trim
|
||||||
|
*
|
||||||
|
* Note: The first trailing whitespace character is replaced with a
|
||||||
|
* null-terminator
|
||||||
|
*
|
||||||
|
* Return: A pointer to the first non-space character in @str
|
||||||
|
*/
|
||||||
|
static inline char *qdf_str_trim(char *str)
|
||||||
|
{
|
||||||
|
return __qdf_str_trim(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* qdf_str_nlen() - Get string length up to @limit characters
|
||||||
|
* @str: the string to get the length of
|
||||||
|
* @limit: the maximum number of characters to check
|
||||||
|
*
|
||||||
|
* Return: length of @str, or @limit if the end is not found
|
||||||
|
*/
|
||||||
|
static inline qdf_size_t qdf_str_nlen(const char *str, size_t limit)
|
||||||
|
{
|
||||||
|
return __qdf_str_nlen(str, limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __QDF_STR_H */
|
32
qdf/libc/inc/i_qdf_str.h
Normal file
32
qdf/libc/inc/i_qdf_str.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 The Linux Foundation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for
|
||||||
|
* any purpose with or without fee is hereby granted, provided that the
|
||||||
|
* above copyright notice and this permission notice appear in all
|
||||||
|
* copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
||||||
|
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
||||||
|
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||||
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||||
|
* PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DOC: i_qdf_str.h
|
||||||
|
* Libc-specific implementations for qdf_str
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __I_QDF_STR_H
|
||||||
|
#define __I_QDF_STR_H
|
||||||
|
|
||||||
|
#define __qdf_is_space(c) isspace(c)
|
||||||
|
char *__qdf_str_left_trim(char *str);
|
||||||
|
char *__qdf_str_trim(char *str);
|
||||||
|
#define __qdf_str_nlen(str, limit) strnlen(str, limit)
|
||||||
|
|
||||||
|
#endif /* __I_QDF_STR_H */
|
37
qdf/libc/inc/qdf_str.c
Normal file
37
qdf/libc/inc/qdf_str.c
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 The Linux Foundation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for
|
||||||
|
* any purpose with or without fee is hereby granted, provided that the
|
||||||
|
* above copyright notice and this permission notice appear in all
|
||||||
|
* copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
||||||
|
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
||||||
|
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||||
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||||
|
* PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "i_qdf_str.h"
|
||||||
|
|
||||||
|
char *__qdf_str_left_trim(char *str)
|
||||||
|
{
|
||||||
|
while (qdf_str_is_space(str))
|
||||||
|
str++;
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *__qdf_str_trim(char *str)
|
||||||
|
{
|
||||||
|
char *trimmed = qdf_str_left_trim(str);
|
||||||
|
|
||||||
|
qdf_str_right_trim(str);
|
||||||
|
|
||||||
|
return trimmed;
|
||||||
|
}
|
||||||
|
|
35
qdf/linux/src/i_qdf_str.h
Normal file
35
qdf/linux/src/i_qdf_str.h
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 The Linux Foundation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for
|
||||||
|
* any purpose with or without fee is hereby granted, provided that the
|
||||||
|
* above copyright notice and this permission notice appear in all
|
||||||
|
* copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
||||||
|
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
||||||
|
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||||
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||||
|
* PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DOC: i_qdf_str.h
|
||||||
|
* Linux-specific implementations for qdf_str
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __I_QDF_STR_H
|
||||||
|
#define __I_QDF_STR_H
|
||||||
|
|
||||||
|
#include "linux/ctype.h"
|
||||||
|
#include "linux/string.h"
|
||||||
|
|
||||||
|
#define __qdf_is_space(c) isspace(c)
|
||||||
|
#define __qdf_str_left_trim(str) skip_spaces(str)
|
||||||
|
#define __qdf_str_trim(str) strim(str)
|
||||||
|
#define __qdf_str_nlen(str, limit) strnlen(str, limit)
|
||||||
|
|
||||||
|
#endif /* __I_QDF_STR_H */
|
33
qdf/src/qdf_str.c
Normal file
33
qdf/src/qdf_str.c
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 The Linux Foundation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for
|
||||||
|
* any purpose with or without fee is hereby granted, provided that the
|
||||||
|
* above copyright notice and this permission notice appear in all
|
||||||
|
* copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
||||||
|
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
||||||
|
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||||
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||||
|
* PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "qdf_mem.h"
|
||||||
|
#include "qdf_module.h"
|
||||||
|
#include "qdf_str.h"
|
||||||
|
|
||||||
|
void qdf_str_right_trim(char *str)
|
||||||
|
{
|
||||||
|
char *end = str + qdf_str_len(str) - 1;
|
||||||
|
|
||||||
|
while (end >= str && qdf_is_space(*end))
|
||||||
|
end--;
|
||||||
|
|
||||||
|
end[1] = '\0';
|
||||||
|
}
|
||||||
|
qdf_export_symbol(qdf_str_right_trim);
|
||||||
|
|
Reference in New Issue
Block a user