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 "base/utils/string_utils.h"
17
18#ifndef WINDOWS_PLATFORM
19#include "securec.h"
20#endif
21
22namespace OHOS::Ace::StringUtils {
23namespace {
24const size_t MAX_STRING_SIZE = 256;
25} // namespace
26
27const char DEFAULT_STRING[] = "error";
28const std::wstring DEFAULT_WSTRING = L"error";
29const std::u16string DEFAULT_USTRING = u"error";
30const std::u32string DEFAULT_U32STRING = U"error";
31
32const std::string FormatString(const char* fmt, ...)
33{
34    va_list args;
35    va_start(args, fmt);
36    char name[MAX_STRING_SIZE] = { 0 };
37    if (vsnprintf_s(name, sizeof(name), sizeof(name) - 1, fmt, args) < 0) {
38        va_end(args);
39        return "";
40    }
41    va_end(args);
42    return name;
43}
44
45bool IsAscii(const std::string& str)
46{
47    for (const auto& c : str) {
48        if (!isascii(c)) {
49            return false;
50        }
51    }
52    return true;
53}
54
55} // namespace OHOS::Ace::StringUtils