1 /*
2  * Copyright (c) 2021-2022 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 #include "string_wrapper.h"
17 
18 namespace OHOS {
19 namespace AAFwk {
20 IINTERFACE_IMPL_1(String, Object, IString);
21 
GetString(std::string & str)22 ErrCode String::GetString(std::string &str) /* [out] */
23 {
24     VALIDATE_NOT_NULL(&str);
25 
26     str = string_;
27     return ERR_OK;
28 }
29 
Equals(IObject & other)30 bool String::Equals(IObject &other) /* [in] */
31 {
32     String *otherObj = static_cast<String *>(IString::Query(&other));
33     return otherObj != nullptr && otherObj->string_ == string_;
34 }
35 
ToString()36 std::string String::ToString()
37 {
38     return string_;
39 }
40 
Box(const std::string & str)41 sptr<IString> String::Box(const std::string &str) /* [in] */
42 {
43     sptr<IString> object = new String(str);
44     return object;
45 }
46 
Unbox(IString * object)47 std::string String::Unbox(IString *object) /* [in] */
48 {
49     std::string str;
50     object->GetString(str);
51     return str;
52 }
53 
Parse(const std::string & str)54 sptr<IString> String::Parse(const std::string &str) /* [in] */
55 {
56     sptr<IString> object = new String(str);
57     return object;
58 }
59 }  // namespace AAFwk
60 }  // namespace OHOS