2019-06-25 05:39:37 +08:00
|
|
|
#ifndef FTXUI_SCREEN_STRING_HPP
|
|
|
|
#define FTXUI_SCREEN_STRING_HPP
|
|
|
|
|
2018-09-18 14:48:40 +08:00
|
|
|
#include <string>
|
|
|
|
|
2020-08-09 20:53:56 +08:00
|
|
|
namespace ftxui {
|
2018-09-18 14:48:40 +08:00
|
|
|
std::string to_string(const std::wstring& s);
|
|
|
|
std::wstring to_wstring(const std::string& s);
|
2019-01-06 23:10:57 +08:00
|
|
|
|
2020-03-24 04:26:00 +08:00
|
|
|
template <typename T>
|
2019-01-06 23:10:57 +08:00
|
|
|
std::wstring to_wstring(T s) {
|
|
|
|
return to_wstring(std::to_string(s));
|
|
|
|
}
|
2019-06-25 05:39:37 +08:00
|
|
|
|
2021-05-19 03:48:32 +08:00
|
|
|
int wchar_width(char32_t);
|
2019-06-25 05:39:37 +08:00
|
|
|
int wchar_width(wchar_t);
|
2021-05-19 03:48:32 +08:00
|
|
|
int wchar_width_cjk(char32_t);
|
2019-06-25 05:39:37 +08:00
|
|
|
int wchar_width_cjk(wchar_t);
|
|
|
|
int wstring_width(const std::wstring&);
|
|
|
|
int wstring_width_cjk(const std::wstring&);
|
2021-05-15 03:43:35 +08:00
|
|
|
|
|
|
|
/// @brief For convenience, this class convert multiple mutable string
|
|
|
|
/// references toward a shared representation.
|
|
|
|
class StringRef {
|
|
|
|
public:
|
|
|
|
StringRef(std::wstring* ref);
|
2021-05-15 07:34:37 +08:00
|
|
|
StringRef(std::wstring ref);
|
2021-05-15 03:43:35 +08:00
|
|
|
StringRef(const wchar_t* ref);
|
|
|
|
StringRef(const char* ref);
|
|
|
|
|
|
|
|
std::wstring& operator*();
|
|
|
|
std::wstring* operator->();
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::wstring* const borrowed_ = nullptr;
|
|
|
|
std::wstring owned_;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// @brief For convenience, this class convert multiple immutable string
|
|
|
|
/// references toward shared representation.
|
|
|
|
class ConstStringRef {
|
|
|
|
public:
|
|
|
|
ConstStringRef(const std::wstring* ref);
|
2021-05-15 07:34:37 +08:00
|
|
|
ConstStringRef(std::wstring ref);
|
2021-05-15 03:43:35 +08:00
|
|
|
ConstStringRef(const wchar_t* ref);
|
|
|
|
ConstStringRef(const char* ref);
|
|
|
|
|
|
|
|
const std::wstring& operator*();
|
|
|
|
const std::wstring* operator->();
|
|
|
|
|
|
|
|
private:
|
|
|
|
const std::wstring* const borrowed_ = nullptr;
|
|
|
|
const std::wstring owned_;
|
|
|
|
};
|
|
|
|
|
2020-08-09 20:53:56 +08:00
|
|
|
} // namespace ftxui
|
2019-06-25 05:39:37 +08:00
|
|
|
|
|
|
|
#endif /* end of include guard: FTXUI_SCREEN_STRING_HPP */
|
2020-08-16 06:24:18 +08:00
|
|
|
|
|
|
|
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
|
|
|
// Use of this source code is governed by the MIT license that can be found in
|
|
|
|
// the LICENSE file.
|