source: azure_iot_hub/trunk/azure_iothub/c-utility/inc/azure_c_shared_utility/string_token.h@ 389

Last change on this file since 389 was 389, checked in by coas-nagasima, 5 years ago

ビルドが通るよう更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 5.0 KB
Line 
1// Copyright (c) Microsoft. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4#ifndef STRING_TOKEN_H
5#define STRING_TOKEN_H
6
7#ifdef __cplusplus
8#include <cstddef>
9extern "C"
10{
11#else
12#include <stddef.h>
13#include <stdbool.h>
14#endif
15
16#include "azure_c_shared_utility/umock_c_prod.h"
17
18typedef struct STRING_TOKEN_TAG* STRING_TOKEN_HANDLE;
19
20/*
21* @brief Tries to identify the first token defined in source up to its length using the delimiters provided.
22* @Remark If no delimiter is found, the entire source string becomes the resulting token. Empty tokens (when delimiters occur side-by-side) can also detected.
23* @param source The initial string to be tokenized.
24* @param length The length of the source string, not including the null-terminator.
25* @param delimiters Array with null-terminated strings to be used as token delimiters.
26* @param n_delims Number of elements in delimiters array.
27* @return A STRING_TOKEN_HANDLE if no failures occur (arguments, memory allocation), or NULL otherwise.
28*/
29MOCKABLE_FUNCTION(, STRING_TOKEN_HANDLE, StringToken_GetFirst, const char*, source, size_t, length, const char**, delimiters, size_t, n_delims);
30
31/*
32* @brief Tries to identify the next token defined in source up to its length using the delimiters provided.
33* @Remark After StringToken_GetFirst is initially called, StringToken_GetNext shall be called for obtaining the next tokens.
34* If no delimiter is found, the entire source string becomes the resulting token.
35* Empty tokens (when delimiters occur side-by-side) can also detected.
36* @param token The handle returned by StringToken_GetFirst.
37* @param delimiters Array with null-terminated strings to be used as token delimiters.
38* @param n_delims Number of elements in delimiters array.
39* @return True if a token could be identified, or false if the tokenizer already reached the end of the source string an no more tokens are available.
40*/
41MOCKABLE_FUNCTION(, bool, StringToken_GetNext, STRING_TOKEN_HANDLE, token, const char**, delimiters, size_t, n_delims);
42
43/*
44* @brief Gets the pointer to the beginning of the current token identified in the source string.
45* @param token The handle returned by StringToken_GetFirst.
46* @return The pointer to the token identified in the last successfull call to StringToken_GetFirst or StringToken_GetNext.
47* If the token string is empty (e.g., between two delimiters side-by-side or if a delimiter occurs at the end of the source string),
48* NULL is returned instead of an empty string.
49*/
50MOCKABLE_FUNCTION(, const char*, StringToken_GetValue, STRING_TOKEN_HANDLE, token);
51
52/*
53* @brief Gets the length of the current token identified in the source string.
54* @param token The handle returned by StringToken_GetFirst.
55* @return A non-zero value if the current token is not empty, zero otherwise.
56*/
57MOCKABLE_FUNCTION(, size_t, StringToken_GetLength, STRING_TOKEN_HANDLE, token);
58
59/*
60* @brief Gets a pointer to last delimiter identified (which defined the current token).
61* @param token The handle returned by StringToken_GetFirst.
62* @return If a delimiter was identified in the previous search,
63* the pointer returned is to the element in the delimiters array provided in the previous call to StringToken_GetFirst or StringToken_GetNext;
64* it returns NULL if no delimiter was found in the previous call to those functions.
65*/
66MOCKABLE_FUNCTION(, const char*, StringToken_GetDelimiter, STRING_TOKEN_HANDLE, token);
67
68/*
69* @brief Splits a string into an array with all the tokens identified using the delimiters provided.
70* @param source The string to be tokenized.
71* @param length The length of the source string, not including the null-terminator.
72* @param delimiters Array with null-terminated strings to be used as token delimiters.
73* @param n_delims Number of elements in delimiters array.
74* @param include_empty Indicates if empty strings shall be included (as NULL values) in the resulting array.
75* @param tokens If no failures occur, the resulting array with the split tokens (dynamically allocated).
76* @param token_count The number of elements in the tokens array.
77* @return Zero if no failures occur, or a non-zero value otherwise.
78*/
79MOCKABLE_FUNCTION(, int, StringToken_Split, const char*, source, size_t, length, const char**, delimiters, size_t, n_delims, bool, include_empty, char***, tokens, size_t*, token_count);
80
81/*
82* @brief Destroys the handle created when calling StringToken_GetFirst.
83* @param token The handle returned by StringToken_GetFirst.
84* @return Nothing
85*/
86MOCKABLE_FUNCTION(, void, StringToken_Destroy, STRING_TOKEN_HANDLE, token);
87
88#ifdef __cplusplus
89}
90#endif
91
92#endif /*STRING_TOKEN_H*/
Note: See TracBrowser for help on using the repository browser.