• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *    http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef HC_STRING_H
17 #define HC_STRING_H
18 
19 #include "hc_parcel.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 typedef struct HcString {
26     HcParcel parcel; // parcel data, used to storage the string data
27 } HcString;
28 
29 /*
30  * Append a HcString
31  * Notice: It will add '\0' automatically.
32  * @param self: self pointer.
33  * @param str: append string.
34  * @return HC_TRUE (ok), HC_FALSE (error)
35  */
36 HcBool StringAppend(HcString *self, HcString str);
37 
38 /*
39  * Append string pointer
40  * Notice: It will add '\0' automatically.
41  * @param self: self pointer.
42  * @param str: string pointer.
43  * @return HC_TRUE (ok), HC_FALSE (error)
44  */
45 HcBool StringAppendPointer(HcString *self, const char *str);
46 
47 /*
48  * Append a char
49  * Notice: It will add '\0' automatically.
50  * @param self: self pointer.
51  * @param str: char.
52  * @return HC_TRUE (ok), HC_FALSE (error)
53  */
54 HcBool StringAppendChar(HcString *self, char c);
55 
56 /*
57  * Assign a value to the HcString
58  * Notice: It will add '\0' automatically.
59  * @param self: self pointer.
60  * @param str: assign value of ta_sting.
61  * @return HC_TRUE (ok), HC_FALSE (error)
62  */
63 HcBool StringSet(HcString *self, HcString str);
64 
65 /*
66  * Assign a value to the HcString
67  * Notice: It will add '\0' automatically.
68  * @param self: self pointer.
69  * @param str: assign value of string pointer.
70  * @return HC_TRUE (ok), HC_FALSE (error)
71  */
72 HcBool StringSetPointer(HcString *self, const char *str);
73 
74 /*
75  * Get the string pointer data
76  * @param self: self pointer.
77  * @return the pointer data of the string
78  */
79 const char* StringGet(const HcString *self);
80 
81 /*
82  * Get the length of the string
83  * @param self: self pointer.
84  * @return the length of the string
85  */
86 uint32_t StringLength(const HcString *self);
87 
88 /*
89  * Create a string.
90  * Notice: You should delete string when you don't need the string anymore.
91  * @return the created string.
92  */
93 HcString CreateString(void);
94 
95 /*
96  * Delete a string. In fact it will not destroy the string,
97  * but only free the allocated memory of the string and reset the member's value
98  * of the string. You can continue to use the string if you want.
99  * Notice: You should delete the string when you don't need it any more to avoid memory leak.
100  * @param str: The string you want to delete.
101  */
102 void DeleteString(HcString *str);
103 
104 #ifdef __cplusplus
105 }
106 #endif
107 #endif
108