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 #include "string_utils.h"
17
18 namespace OHOS {
19 namespace NativeRdb {
SurroundWithQuote(std::string value,std::string quote)20 std::string StringUtils::SurroundWithQuote(std::string value, std::string quote)
21 {
22 if (value.empty()) {
23 return value;
24 }
25 std::string str = quote + value + quote;
26 return str;
27 }
28
29 // Join array members as parameters of a function call.
SurroundWithFunction(std::string function,std::string separator,std::vector<std::string> array)30 std::string StringUtils::SurroundWithFunction(std::string function, std::string separator,
31 std::vector<std::string> array)
32 {
33 std::string builder(function);
34 builder += "(";
35 bool isFirst = true;
36 for (auto text : array) {
37 if (!isFirst) {
38 builder = builder + " " + separator + " ";
39 } else {
40 isFirst = false;
41 }
42 builder += text;
43 }
44 builder += ")";
45 return builder;
46 }
47
StringUtils()48 StringUtils::StringUtils() {}
~StringUtils()49 StringUtils::~StringUtils() {}
50 } // namespace NativeRdb
51 } // namespace OHOS