Lagrange
Loading...
Searching...
No Matches
strings.h
1/*
2 * Copyright 2020 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/api.h>
15#include <lagrange/utils/fmt/format.h>
16
17
18#include <string>
19#include <string_view>
20#include <utility>
21#include <vector>
22
23namespace lagrange {
24
27
36LA_CORE_API std::vector<std::string> string_split(const std::string& str, char delimiter);
37
48LA_CORE_API bool starts_with(std::string_view str, std::string_view prefix);
49
60LA_CORE_API bool ends_with(std::string_view str, std::string_view suffix);
61
71LA_CORE_API std::string to_lower(std::string str);
72
82LA_CORE_API std::string to_upper(std::string str);
83
96template <typename... Args>
97std::string string_format(lagrange::format_string<Args...> format, Args&&... args)
98{
99// TODO: Remove this string_format in our next major release...
100#ifdef SPDLOG_USE_STD_FORMAT
101 return std::format(format, std::forward<Args>(args)...);
102#elif FMT_VERSION >= 90100
103 return fmt::format(fmt::runtime(format), std::forward<Args>(args)...);
104#else
105 return fmt::format(format, std::forward<Args>(args)...);
106#endif
107}
108
110
111} // namespace lagrange
LA_CORE_API std::string to_lower(std::string str)
Convert a string to lowercase.
Definition strings.cpp:43
LA_CORE_API std::string to_upper(std::string str)
Convert a string to uppercase.
Definition strings.cpp:51
LA_CORE_API bool ends_with(std::string_view str, std::string_view suffix)
Checks if the string ends with the given suffix.
Definition strings.cpp:31
std::string string_format(lagrange::format_string< Args... > format, Args &&... args)
Format args according to the format string fmt, and return the result as a string.
Definition strings.h:97
LA_CORE_API std::vector< std::string > string_split(const std::string &str, char delimiter)
Split a std::string using a prescribed delimiter.
Definition strings.cpp:20
LA_CORE_API bool starts_with(std::string_view str, std::string_view prefix)
Checks if the string begins with the given prefix.
Definition strings.cpp:38
Main namespace for Lagrange.
Definition project.cpp:27