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