117fd14ceSopenharmony_ci/*
217fd14ceSopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd.
317fd14ceSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
417fd14ceSopenharmony_ci * you may not use this file except in compliance with the License.
517fd14ceSopenharmony_ci * You may obtain a copy of the License at
617fd14ceSopenharmony_ci *
717fd14ceSopenharmony_ci *    http://www.apache.org/licenses/LICENSE-2.0
817fd14ceSopenharmony_ci *
917fd14ceSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1017fd14ceSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1117fd14ceSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1217fd14ceSopenharmony_ci * See the License for the specific language governing permissions and
1317fd14ceSopenharmony_ci * limitations under the License.
1417fd14ceSopenharmony_ci */
1517fd14ceSopenharmony_ci
1617fd14ceSopenharmony_ci#ifndef HC_STRING_H
1717fd14ceSopenharmony_ci#define HC_STRING_H
1817fd14ceSopenharmony_ci
1917fd14ceSopenharmony_ci#include "hc_parcel.h"
2017fd14ceSopenharmony_ci
2117fd14ceSopenharmony_ci#ifdef __cplusplus
2217fd14ceSopenharmony_ciextern "C" {
2317fd14ceSopenharmony_ci#endif
2417fd14ceSopenharmony_ci
2517fd14ceSopenharmony_citypedef struct HcString {
2617fd14ceSopenharmony_ci    HcParcel parcel; // parcel data, used to storage the string data
2717fd14ceSopenharmony_ci} HcString;
2817fd14ceSopenharmony_ci
2917fd14ceSopenharmony_ci/*
3017fd14ceSopenharmony_ci * Append a HcString
3117fd14ceSopenharmony_ci * Notice: It will add '\0' automatically.
3217fd14ceSopenharmony_ci * @param self: self pointer.
3317fd14ceSopenharmony_ci * @param str: append string.
3417fd14ceSopenharmony_ci * @return HC_TRUE (ok), HC_FALSE (error)
3517fd14ceSopenharmony_ci */
3617fd14ceSopenharmony_ciHcBool StringAppend(HcString *self, HcString str);
3717fd14ceSopenharmony_ci
3817fd14ceSopenharmony_ci/*
3917fd14ceSopenharmony_ci * Append string pointer
4017fd14ceSopenharmony_ci * Notice: It will add '\0' automatically.
4117fd14ceSopenharmony_ci * @param self: self pointer.
4217fd14ceSopenharmony_ci * @param str: string pointer.
4317fd14ceSopenharmony_ci * @return HC_TRUE (ok), HC_FALSE (error)
4417fd14ceSopenharmony_ci */
4517fd14ceSopenharmony_ciHcBool StringAppendPointer(HcString *self, const char *str);
4617fd14ceSopenharmony_ci
4717fd14ceSopenharmony_ci/*
4817fd14ceSopenharmony_ci * Append a char
4917fd14ceSopenharmony_ci * Notice: It will add '\0' automatically.
5017fd14ceSopenharmony_ci * @param self: self pointer.
5117fd14ceSopenharmony_ci * @param str: char.
5217fd14ceSopenharmony_ci * @return HC_TRUE (ok), HC_FALSE (error)
5317fd14ceSopenharmony_ci */
5417fd14ceSopenharmony_ciHcBool StringAppendChar(HcString *self, char c);
5517fd14ceSopenharmony_ci
5617fd14ceSopenharmony_ci/*
5717fd14ceSopenharmony_ci * Assign a value to the HcString
5817fd14ceSopenharmony_ci * Notice: It will add '\0' automatically.
5917fd14ceSopenharmony_ci * @param self: self pointer.
6017fd14ceSopenharmony_ci * @param str: assign value of ta_sting.
6117fd14ceSopenharmony_ci * @return HC_TRUE (ok), HC_FALSE (error)
6217fd14ceSopenharmony_ci */
6317fd14ceSopenharmony_ciHcBool StringSet(HcString *self, HcString str);
6417fd14ceSopenharmony_ci
6517fd14ceSopenharmony_ci/*
6617fd14ceSopenharmony_ci * Assign a value to the HcString
6717fd14ceSopenharmony_ci * Notice: It will add '\0' automatically.
6817fd14ceSopenharmony_ci * @param self: self pointer.
6917fd14ceSopenharmony_ci * @param str: assign value of string pointer.
7017fd14ceSopenharmony_ci * @return HC_TRUE (ok), HC_FALSE (error)
7117fd14ceSopenharmony_ci */
7217fd14ceSopenharmony_ciHcBool StringSetPointer(HcString *self, const char *str);
7317fd14ceSopenharmony_ci
7417fd14ceSopenharmony_ci/*
7517fd14ceSopenharmony_ci * Get the string pointer data
7617fd14ceSopenharmony_ci * @param self: self pointer.
7717fd14ceSopenharmony_ci * @return the pointer data of the string
7817fd14ceSopenharmony_ci */
7917fd14ceSopenharmony_ciconst char* StringGet(const HcString *self);
8017fd14ceSopenharmony_ci
8117fd14ceSopenharmony_ci/*
8217fd14ceSopenharmony_ci * Get the length of the string
8317fd14ceSopenharmony_ci * @param self: self pointer.
8417fd14ceSopenharmony_ci * @return the length of the string
8517fd14ceSopenharmony_ci */
8617fd14ceSopenharmony_ciuint32_t StringLength(const HcString *self);
8717fd14ceSopenharmony_ci
8817fd14ceSopenharmony_ci/*
8917fd14ceSopenharmony_ci * Create a string.
9017fd14ceSopenharmony_ci * Notice: You should delete string when you don't need the string anymore.
9117fd14ceSopenharmony_ci * @return the created string.
9217fd14ceSopenharmony_ci */
9317fd14ceSopenharmony_ciHcString CreateString(void);
9417fd14ceSopenharmony_ci
9517fd14ceSopenharmony_ci/*
9617fd14ceSopenharmony_ci * Delete a string. In fact it will not destroy the string,
9717fd14ceSopenharmony_ci * but only free the allocated memory of the string and reset the member's value
9817fd14ceSopenharmony_ci * of the string. You can continue to use the string if you want.
9917fd14ceSopenharmony_ci * Notice: You should delete the string when you don't need it any more to avoid memory leak.
10017fd14ceSopenharmony_ci * @param str: The string you want to delete.
10117fd14ceSopenharmony_ci */
10217fd14ceSopenharmony_civoid DeleteString(HcString *str);
10317fd14ceSopenharmony_ci
10417fd14ceSopenharmony_ci#ifdef __cplusplus
10517fd14ceSopenharmony_ci}
10617fd14ceSopenharmony_ci#endif
10717fd14ceSopenharmony_ci#endif
108