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
29
38LA_CORE_API std::vector<std::string> string_split(const std::string& str, char delimiter);
39
50LA_CORE_API bool starts_with(std::string_view str, std::string_view prefix);
51
62LA_CORE_API bool ends_with(std::string_view str, std::string_view suffix);
63
73LA_CORE_API std::string to_lower(std::string str);
74
84LA_CORE_API std::string to_upper(std::string str);
85
98template <typename... Args>
99std::string string_format(lagrange::format_string<Args...> format, Args&&... args)
100{
101// TODO: Remove this string_format in our next major release...
102#ifdef SPDLOG_USE_STD_FORMAT
103 return std::format(format, std::forward<Args>(args)...);
104#elif FMT_VERSION >= 90100
105 return fmt::format(fmt::runtime(format), std::forward<Args>(args)...);
106#else
107 return fmt::format(format, std::forward<Args>(args)...);
108#endif
109}
110
112
113} // 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:99
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