diff --git a/CMakeLists.txt b/CMakeLists.txt index 5fcdb3af0..c142c0109 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -365,9 +365,6 @@ else() message(WARNING "C++ experimental filesystem library is unusable!\nWill use own implementation.") endif() -try_compile(HAVE_STRING_VIEW ${CMAKE_BINARY_DIR} "${CMAKE_SOURCE_DIR}/checks/cxxsv.cpp") -try_compile(HAVE_EXPERIMENTAL_STRING_VIEW ${CMAKE_BINARY_DIR} "${CMAKE_SOURCE_DIR}/checks/cxxsvexp.cpp") - try_compile(HAVE_CHARCONV ${CMAKE_BINARY_DIR} "${CMAKE_SOURCE_DIR}/checks/cxxccint.cpp") if(HAVE_CHARCONV) try_compile(HAVE_FLOAT_CHARCONV ${CMAKE_BINARY_DIR} "${CMAKE_SOURCE_DIR}/checks/cxxccfloat.cpp") diff --git a/checks/cxxsv.cpp b/checks/cxxsv.cpp deleted file mode 100644 index bca793d14..000000000 --- a/checks/cxxsv.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main() -{ - std::string_view sv("test"); -} diff --git a/checks/cxxsvexp.cpp b/checks/cxxsvexp.cpp deleted file mode 100644 index f73617c1e..000000000 --- a/checks/cxxsvexp.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main() -{ - std::experimental::string_view sv("test"); -} diff --git a/config.h.in b/config.h.in index c9ef232b3..526eaa8f9 100644 --- a/config.h.in +++ b/config.h.in @@ -3,7 +3,5 @@ #cmakedefine HAVE_FLOAT_CHARCONV #cmakedefine HAVE_FILESYSTEM #cmakedefine HAVE_EXPERIMENTAL_FILESYSTEM -#cmakedefine HAVE_STRING_VIEW -#cmakedefine HAVE_EXPERIMENTAL_STRING_VIEW #cmakedefine HAVE_WORDEXP #cmakedefine WORDS_BIGENDIAN diff --git a/src/celcompat/string_view.h b/src/celcompat/string_view.h deleted file mode 100644 index 7ddb44fe0..000000000 --- a/src/celcompat/string_view.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include - -#ifdef HAVE_STRING_VIEW -#include -namespace celestia -{ -namespace compat -{ - using std::basic_string_view; - using std::string_view; -} -} -#elif defined(HAVE_EXPERIMENTAL_STRING_VIEW) -#include -namespace celestia -{ -namespace compat -{ - using std::experimental::basic_string_view; - using std::experimental::string_view; -} -} -#else -#include -#include "sv.h" - -template<> -struct fmt::formatter : formatter -{ - template - auto format(celestia::compat::string_view v, FormatContext& ctx) - { - fmt::string_view f{v.data(), v.size()}; - return formatter::format(f, ctx); - } -}; -#endif diff --git a/src/celcompat/sv.h b/src/celcompat/sv.h deleted file mode 100644 index 0307166ce..000000000 --- a/src/celcompat/sv.h +++ /dev/null @@ -1,547 +0,0 @@ -// sv.h -// -// Copyright (C) 2021-present, Celestia Development Team. -// -// Read-only view of C/C++ strings. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. - -#pragma once - -#include -#include -#include - -#if defined(_MSC_VER) && !defined(__clang__) -// M$VC++ build without C++ exceptions are not supported yet -#ifndef __cpp_exceptions -#define __cpp_exceptions 1 -#endif -#endif - -#if ! __cpp_exceptions -#include -#endif - -namespace celestia -{ -namespace compat -{ -template< - typename CharT, - typename Traits = std::char_traits -> class basic_string_view -{ - public: - using traits_type = Traits; - using value_type = CharT; - using pointer = CharT*; - using const_pointer = const CharT*; - using reference = CharT&; - using const_reference = const CharT&; - using const_iterator = const CharT*; - using iterator = const_iterator; - using const_reverse_iterator = std::reverse_iterator; - using reverse_iterator = const_reverse_iterator; - using size_type = std::size_t; - using difference_type = std::ptrdiff_t; - - enum : size_type - { - npos = size_type(-1) - }; - - constexpr basic_string_view() noexcept = default; - constexpr basic_string_view(const basic_string_view& other) noexcept = default; - constexpr basic_string_view(const CharT* s, size_type count) : - m_data { s }, - m_size { count } - {} - constexpr basic_string_view(const std::basic_string &s) : - m_data { s.data() }, - m_size { s.size() } - {} - - constexpr basic_string_view(const CharT* s) : - m_data { s }, - m_size { Traits::length(s) } - {} - - constexpr basic_string_view& operator=(const basic_string_view&) noexcept = default; - - explicit operator std::basic_string() const - { - return { m_data, m_size }; - } - - constexpr const_pointer data() const noexcept - { - return m_data; - } - constexpr size_type size() const noexcept - { - return m_size; - } - constexpr size_type length() const noexcept - { - return size(); - } - constexpr bool empty() const noexcept - { - return size() == 0; - } - constexpr const_reference operator[](size_type pos) const - { - return m_data[pos]; - } - constexpr const_reference at(size_type pos) const - { - if (pos < size()) - return m_data[pos]; -#if __cpp_exceptions - throw std::out_of_range("pos >= size()"); -#else - std::abort(); -#endif - } - constexpr const_reference front() const - { - return *m_data; - } - constexpr const_reference back() const - { - return *(m_data + m_size - 1); - } - constexpr size_type max_size() const noexcept - { - return (npos - sizeof(size_type) - sizeof(pointer)) / sizeof(value_type) / 4; - } - constexpr const_iterator begin() const noexcept - { - return m_data; - } - constexpr const_iterator cbegin() const noexcept - { - return begin(); - } - constexpr const_iterator end() const noexcept - { - return m_data + m_size; - } - constexpr const_iterator cend() const noexcept - { - return end(); - } - constexpr const_reverse_iterator rbegin() const noexcept - { - return const_reverse_iterator(end()); - } - constexpr const_reverse_iterator crbegin() const noexcept - { - return const_reverse_iterator(end()); - } - constexpr const_reverse_iterator rend() const noexcept - { - return const_reverse_iterator(begin()); - } - constexpr const_reverse_iterator crend() const noexcept - { - return const_reverse_iterator(begin()); - } - constexpr void remove_prefix(size_type n) - { - m_data += n; - m_size -= n; - } - constexpr void remove_suffix(size_type n) - { - m_size -= n; - } - constexpr void swap(basic_string_view& v) noexcept - { - auto t = *this; - this = v; - v = t; - } - size_type copy(CharT* dest, size_type count, size_type pos = 0) const - { - if (pos > m_size) -#if __cpp_exceptions - throw std::out_of_range("pos >= size()"); -#else - std::abort(); -#endif - - auto rcount = std::min(count, m_size - pos); - return Traits::copy(dest, m_data + pos, rcount); - } - constexpr basic_string_view substr(size_type pos = 0, size_type count = npos ) const - { - if (pos > m_size) -#if __cpp_exceptions - throw std::out_of_range("pos >= size()"); -#else - std::abort(); -#endif - - auto rcount = std::min(count, m_size - pos); - return { m_data + pos, rcount }; - } - constexpr int compare(basic_string_view v) const noexcept - { - auto r = Traits::compare(data(), v.data(), std::min(size(), v.size())); - return r == 0 ? size() - v.size() : r; - } - constexpr int compare(size_type pos1, size_type count1, basic_string_view v) const - { - return substr(pos1, count1).compare(v); - } - constexpr int compare(size_type pos1, size_type count1, basic_string_view v, size_type pos2, size_type count2) const - { - return substr(pos1, count1).compare(v.substr(pos2, count2)); - } - constexpr int compare(const CharT* s) const - { - return compare(basic_string_view(s)); - } - constexpr int compare(size_type pos1, size_type count1, const CharT* s) const - { - return substr(pos1, count1).compare(basic_string_view(s)); - } - constexpr int compare(size_type pos1, size_type count1, const CharT* s, size_type count2) const - { - return substr(pos1, count1).compare(basic_string_view(s, count2)); - } - constexpr size_type find(basic_string_view v, size_type pos = 0) const noexcept - { - return (pos >= m_size ? npos : (basic_string_view(m_data + pos, v.size()).compare(v) == 0 ? pos : find(v, pos + 1))); - } - constexpr size_type find(CharT ch, size_type pos = 0) const noexcept - { - return find(basic_string_view(std::addressof(ch), 1), pos); - } - constexpr size_type find(const CharT* s, size_type pos, size_type count) const - { - return find(basic_string_view(s, count), pos); - } - constexpr size_type find(const CharT* s, size_type pos = 0) const - { - return find(basic_string_view(s), pos); - } - constexpr size_type rfind(basic_string_view v, size_type pos = npos) const noexcept - { - if (v.size() > size()) - return npos; - if (v.size() == 0) - return std::min(size(), pos); - auto last = begin() + std::min(pos, size()); - auto r = std::find_end(begin(), last, v.begin(), v.end()); - if (r != last) - return r - begin(); - return npos; - } - constexpr size_type rfind(CharT c, size_type pos = npos) const noexcept - { - return rfind(basic_string_view(std::addressof(c), 1), pos); - } - constexpr size_type rfind(const CharT* s, size_type pos, size_type count) const - { - return rfind(basic_string_view(s, count), pos); - } - constexpr size_type rfind(const CharT* s, size_type pos = npos) const - { - return rfind(basic_string_view(s), pos); - } - constexpr size_type find_first_of(basic_string_view v, size_type pos = 0) const noexcept - { - for (size_type i = pos; i < m_size; i++) - for (auto c : v) - if (c == m_data[i]) - return i; - return npos; - } - constexpr size_type find_first_of(CharT c, size_type pos = 0) const noexcept - { - return find_first_of(basic_string_view(std::addressof(c), 1), pos); - } - constexpr size_type find_first_of(const CharT* s, size_type pos, size_type count) const - { - return find_first_of(basic_string_view(s, count), pos); - } - constexpr size_type find_first_of(const CharT* s, size_type pos = 0) const - { - return find_first_of(basic_string_view(s), pos); - } - constexpr size_type find_last_of(basic_string_view v, size_type pos = npos) const noexcept - { - for (auto iter = cbegin() + std::min(m_size - 1, pos); iter >= cbegin(); iter--) - for (auto c : v) - if (c == *iter) - return iter - cbegin(); - return npos; - } - constexpr size_type find_last_of(CharT c, size_type pos = npos) const noexcept - { - return find_last_of(basic_string_view(std::addressof(c), 1), pos); - } - constexpr size_type find_last_of(const CharT* s, size_type pos, size_type count) const - { - return find_last_of(basic_string_view(s, count), pos); - } - constexpr size_type find_last_of(const CharT* s, size_type pos = npos) const - { - return find_last_of(basic_string_view(s), pos); - } - constexpr size_type find_first_not_of(basic_string_view v, size_type pos = 0) const noexcept - { - for (size_type i = pos; i < m_size; i++) - if (v.find(m_data[i]) == npos) - return i; - return npos; - } - constexpr size_type find_first_not_of(CharT c, size_type pos = 0) const noexcept - { - return find_first_not_of(basic_string_view(std::addressof(c), 1), pos); - } - constexpr size_type find_first_not_of(const CharT* s, size_type pos, size_type count) const - { - return find_first_not_of(basic_string_view(s, count), pos); - } - constexpr size_type find_first_not_of(const CharT* s, size_type pos = 0) const - { - return find_first_not_of(basic_string_view(s), pos); - } - constexpr size_type find_last_not_of(basic_string_view v, size_type pos = npos) const noexcept - { - for (auto iter = cbegin() + std::min(m_size - 1, pos); iter >= cbegin(); iter--) - if (v.find(*iter) == npos) - return iter - cbegin(); - return npos; - } - constexpr size_type find_last_not_of(CharT c, size_type pos = npos) const noexcept - { - return find_last_not_of(basic_string_view(std::addressof(c), 1), pos); - } - constexpr size_type find_last_not_of(const CharT* s, size_type pos, size_type count) const - { - return find_last_not_of(basic_string_view(s, count), pos); - } - constexpr size_type find_last_not_of(const CharT* s, size_type pos = npos) const - { - return find_last_not_of(basic_string_view(s), pos); - } - - private: - const_pointer m_data { nullptr }; - size_type m_size { 0 }; -}; - -using string_view = basic_string_view; -using wstring_view = basic_string_view; - -template -constexpr bool operator==(basic_string_view lhs, - basic_string_view rhs) noexcept -{ - return lhs.compare(rhs) == 0; -} - -/*! - * Helpers missing in C++17 for compatibility with C++11/C++14 - */ -template -constexpr bool operator==(basic_string_view lhs, - std::basic_string rhs) noexcept -{ - return lhs == basic_string_view(rhs); -} -template -constexpr bool operator==(std::basic_string lhs, - basic_string_view rhs) noexcept -{ - return rhs == lhs; -} -template -constexpr bool operator==(basic_string_view lhs, - const CharT (&rhs)[N]) noexcept -{ - return lhs == basic_string_view(rhs, N-1); -} -template -constexpr bool operator==(const CharT (&lhs)[N], - basic_string_view rhs) noexcept -{ - return rhs == lhs; -} -template -constexpr bool operator==(basic_string_view lhs, - const CharT* rhs) noexcept -{ - return lhs.compare(rhs) == 0; -} -template -constexpr bool operator==(const CharT* lhs, - basic_string_view rhs) noexcept -{ - return rhs == lhs; -} - -template -constexpr bool operator!=(basic_string_view lhs, - basic_string_view rhs) noexcept -{ - return lhs.compare(rhs) != 0; -} - -/*! - * Helpers missing in C++17 for compatibility with C++11/C++14 - */ -template -constexpr bool operator!=(basic_string_view lhs, - std::basic_string rhs) noexcept -{ - return !(lhs == rhs); -} -template -constexpr bool operator!=(std::basic_string lhs, - basic_string_view rhs) noexcept -{ - return !(lhs == rhs); -} -template -constexpr bool operator!=(basic_string_view lhs, - const CharT* rhs) noexcept -{ - return !(lhs == rhs); -} -template -constexpr bool operator!=(const CharT* lhs, - basic_string_view rhs) noexcept -{ - return !(lhs == rhs); -} - -template -constexpr bool operator<(basic_string_view lhs, - basic_string_view rhs) noexcept -{ - return lhs.compare(rhs) < 0; -} -template -constexpr bool operator<=(basic_string_view lhs, - basic_string_view rhs) noexcept -{ - return lhs.compare(rhs) <= 0; -} -template -constexpr bool operator>(basic_string_view lhs, - basic_string_view rhs) noexcept -{ - return lhs.compare(rhs) > 0; -} -template -constexpr bool operator>=(basic_string_view lhs, - basic_string_view rhs) noexcept -{ - return lhs.compare(rhs) >= 0; -} - -template -std::basic_ostream & operator<<(std::basic_ostream & os, - celestia::compat::basic_string_view v) -{ - os.write(v.data(), v.size()); - return os; -} - -namespace -{ -template -struct fnv; - -template<> -struct fnv<4> -{ - enum : uint32_t - { - offset = 2166136261ul, - prime = 16777619ul - }; -}; - -template<> -struct fnv<8> -{ - enum : uint64_t - { - offset = 14695981039346656037ull, - prime = 1099511628211ull - }; -}; - -constexpr size_t fnv1a_loop_helper(const char *begin, const char *end, size_t hash = fnv<>::offset) -{ - return begin < end ? fnv1a_loop_helper(begin + 1, end, (hash ^ size_t(*begin)) * fnv<>::prime) : hash; -} -} - -template -struct hash; - -template<> -struct hash -{ - size_t operator()(const string_view& sv) const noexcept - { -#if 0 - size_t _hash = fnv<>::offset; - for (char c : sv) - { - _hash ^= size_t(c); - _hash *= fnv<>::prime; - } - return _hash; -#else - return fnv1a_loop_helper(sv.data(), sv.data() + sv.length()); -#endif - } -}; -} -} - -#if defined(__clang__) -#pragma clang diagnostic ignored "-Wreserved-user-defined-literal" -//#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wuser-defined-literals" -#elif defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wliteral-suffix" -#endif -constexpr celestia::compat::string_view operator "" sv(const char *str, std::size_t len) -{ - return { str, len }; -} - -constexpr celestia::compat::wstring_view operator "" sv(const wchar_t *str, std::size_t len) -{ - return { str, len }; -} - -constexpr celestia::compat::string_view operator "" _sv(const char *str, std::size_t len) -{ - return { str, len }; -} - -constexpr celestia::compat::wstring_view operator "" _sv(const wchar_t *str, std::size_t len) -{ - return { str, len }; -} - -#if defined(__clang__) -//#pragma clang diagnostic pop -#elif defined(__GNUC__) -#pragma GCC diagnostic pop -#endif diff --git a/src/celengine/astro.cpp b/src/celengine/astro.cpp index 4bd78cb31..19ab65003 100644 --- a/src/celengine/astro.cpp +++ b/src/celengine/astro.cpp @@ -103,7 +103,7 @@ static const char* MonthAbbrList[12] = struct UnitDefinition { - celestia::compat::string_view name; + std::string_view name; double conversion; }; @@ -763,7 +763,7 @@ astro::TAItoJDUTC(double tai) // Get scale of given length unit in kilometers -bool astro::getLengthScale(celestia::compat::string_view unitName, double& scale) +bool astro::getLengthScale(std::string_view unitName, double& scale) { unsigned int nUnits = sizeof(lengthUnits) / sizeof(lengthUnits[0]); bool foundMatch = false; @@ -782,7 +782,7 @@ bool astro::getLengthScale(celestia::compat::string_view unitName, double& scale // Get scale of given time unit in days -bool astro::getTimeScale(celestia::compat::string_view unitName, double& scale) +bool astro::getTimeScale(std::string_view unitName, double& scale) { for (const auto& timeUnit : timeUnits) { @@ -798,7 +798,7 @@ bool astro::getTimeScale(celestia::compat::string_view unitName, double& scale) // Get scale of given angle unit in degrees -bool astro::getAngleScale(celestia::compat::string_view unitName, double& scale) +bool astro::getAngleScale(std::string_view unitName, double& scale) { for (const auto& angleUnit : angleUnits) { @@ -813,7 +813,7 @@ bool astro::getAngleScale(celestia::compat::string_view unitName, double& scale) } -bool astro::getMassScale(celestia::compat::string_view unitName, double& scale) +bool astro::getMassScale(std::string_view unitName, double& scale) { for (const auto& massUnit : massUnits) { @@ -829,7 +829,7 @@ bool astro::getMassScale(celestia::compat::string_view unitName, double& scale) // Check if unit is a length unit -bool astro::isLengthUnit(celestia::compat::string_view unitName) +bool astro::isLengthUnit(std::string_view unitName) { double dummy; return getLengthScale(unitName, dummy); @@ -837,7 +837,7 @@ bool astro::isLengthUnit(celestia::compat::string_view unitName) // Check if unit is a time unit -bool astro::isTimeUnit(celestia::compat::string_view unitName) +bool astro::isTimeUnit(std::string_view unitName) { double dummy; return getTimeScale(unitName, dummy); @@ -845,14 +845,14 @@ bool astro::isTimeUnit(celestia::compat::string_view unitName) // Check if unit is an angle unit -bool astro::isAngleUnit(celestia::compat::string_view unitName) +bool astro::isAngleUnit(std::string_view unitName) { double dummy; return getAngleScale(unitName, dummy); } -bool astro::isMassUnit(celestia::compat::string_view unitName) +bool astro::isMassUnit(std::string_view unitName) { double dummy; return getMassScale(unitName, dummy); diff --git a/src/celengine/astro.h b/src/celengine/astro.h index e54501b58..ceb6ead6b 100644 --- a/src/celengine/astro.h +++ b/src/celengine/astro.h @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #define SOLAR_ABSMAG 4.83f @@ -195,14 +195,14 @@ namespace astro return jd * SECONDS_PER_DAY; } - bool isLengthUnit(celestia::compat::string_view unitName); - bool isTimeUnit(celestia::compat::string_view unitName); - bool isAngleUnit(celestia::compat::string_view unitName); - bool isMassUnit(celestia::compat::string_view unitName); - bool getLengthScale(celestia::compat::string_view unitName, double& scale); - bool getTimeScale(celestia::compat::string_view unitName, double& scale); - bool getAngleScale(celestia::compat::string_view unitName, double& scale); - bool getMassScale(celestia::compat::string_view unitName, double& scale); + bool isLengthUnit(std::string_view unitName); + bool isTimeUnit(std::string_view unitName); + bool isAngleUnit(std::string_view unitName); + bool isMassUnit(std::string_view unitName); + bool getLengthScale(std::string_view unitName, double& scale); + bool getTimeScale(std::string_view unitName, double& scale); + bool getAngleScale(std::string_view unitName, double& scale); + bool getMassScale(std::string_view unitName, double& scale); void decimalToDegMinSec(double angle, int& degrees, int& minutes, double& seconds); double degMinSecToDecimal(int degrees, int minutes, double seconds); diff --git a/src/celestia/url.cpp b/src/celestia/url.cpp index 7ee0a2bf5..69ef895b6 100644 --- a/src/celestia/url.cpp +++ b/src/celestia/url.cpp @@ -65,7 +65,7 @@ std::string getBodyShortName(const std::string &body) return D_(body.c_str()); } -celestia::compat::string_view +std::string_view getCoordSysName(ObserverFrame::CoordinateSystem mode) { switch (mode) @@ -293,17 +293,17 @@ Url::getEncodedObjectName(const Selection& selection, const CelestiaCore* appCor } std::string -Url::decodeString(celestia::compat::string_view str) +Url::decodeString(std::string_view str) { - celestia::compat::string_view::size_type a = 0, b = 0; + std::string_view::size_type a = 0, b = 0; std::string out; b = str.find('%'); - while (b != celestia::compat::string_view::npos && a < str.length()) + while (b != std::string_view::npos && a < str.length()) { auto s = str.substr(a, b - a); out.append(s.data(), s.length()); - celestia::compat::string_view c_code = str.substr(b + 1, 2); + std::string_view c_code = str.substr(b + 1, 2); uint8_t c; if (to_number(c_code, c, 16)) { @@ -328,7 +328,7 @@ Url::decodeString(celestia::compat::string_view str) } std::string -Url::encodeString(celestia::compat::string_view str) +Url::encodeString(std::string_view str) { std::ostringstream enc; @@ -370,7 +370,7 @@ Url::encodeString(celestia::compat::string_view str) struct Mode { - celestia::compat::string_view modeStr; + std::string_view modeStr; ObserverFrame::CoordinateSystem mode; int nBodies; }; @@ -384,12 +384,12 @@ static Mode modes[] = { "PhaseLock", ObserverFrame::PhaseLock, 2 }, }; -auto ParseURLParams(celestia::compat::string_view paramsStr) - -> std::map; +auto ParseURLParams(std::string_view paramsStr) + -> std::map; -bool Url::parse(celestia::compat::string_view urlStr) +bool Url::parse(std::string_view urlStr) { - constexpr auto npos = celestia::compat::string_view::npos; + constexpr auto npos = std::string_view::npos; // proper URL string must start with protocol (cel://) if (urlStr.compare(0, Url::proto().length(), Url::proto()) != 0) @@ -403,7 +403,7 @@ bool Url::parse(celestia::compat::string_view urlStr) auto pathStr = urlStr.substr(Url::proto().length(), pos - Url::proto().length()); while (pathStr.back() == '/') pathStr.remove_suffix(1); - celestia::compat::string_view paramsStr; + std::string_view paramsStr; if (pos != npos) paramsStr = urlStr.substr(pos + 1); @@ -516,14 +516,14 @@ bool Url::parse(celestia::compat::string_view urlStr) return true; } -auto ParseURLParams(celestia::compat::string_view paramsStr) - -> std::map +auto ParseURLParams(std::string_view paramsStr) + -> std::map { - std::map params; + std::map params; if (paramsStr.empty()) return params; - constexpr auto npos = celestia::compat::string_view::npos; + constexpr auto npos = std::string_view::npos; for (auto iter = paramsStr;;) { auto pos = iter.find('&'); @@ -543,7 +543,7 @@ auto ParseURLParams(celestia::compat::string_view paramsStr) return params; } -bool Url::initVersion3(std::map ¶ms, celestia::compat::string_view timeStr) +bool Url::initVersion3(std::map ¶ms, std::string_view timeStr) { m_version = 3; @@ -631,7 +631,7 @@ bool Url::initVersion3(std::map &par return true; } -bool Url::initVersion4(std::map ¶ms, celestia::compat::string_view timeStr) +bool Url::initVersion4(std::map ¶ms, std::string_view timeStr) { if (params.count("rf") != 0) { diff --git a/src/celestia/url.h b/src/celestia/url.h index 837bf945e..4b8ef1acc 100644 --- a/src/celestia/url.h +++ b/src/celestia/url.h @@ -12,10 +12,10 @@ #include #include +#include #include #include #include -#include #include "celestiastate.h" class CelestiaCore; @@ -53,17 +53,17 @@ class Url ~Url() = default; static std::string getEncodedObjectName(const Selection& sel, const CelestiaCore* appCore); - static constexpr celestia::compat::string_view proto(); - static std::string decodeString(celestia::compat::string_view); - static std::string encodeString(celestia::compat::string_view); + static constexpr std::string_view proto(); + static std::string decodeString(std::string_view); + static std::string encodeString(std::string_view); - bool parse(celestia::compat::string_view); + bool parse(std::string_view); bool goTo(); std::string getAsString() const; private: - bool initVersion3(std::map ¶ms, celestia::compat::string_view timeStr); - bool initVersion4(std::map ¶ms, celestia::compat::string_view timeStr); + bool initVersion3(std::map ¶ms, std::string_view timeStr); + bool initVersion4(std::map ¶ms, std::string_view timeStr); void evalName(); CelestiaState m_state; @@ -84,7 +84,7 @@ class Url bool m_valid { false }; }; -constexpr celestia::compat::string_view Url::proto() +constexpr std::string_view Url::proto() { return "cel://"; } diff --git a/src/celscript/legacy/cmdparser.h b/src/celscript/legacy/cmdparser.h index c77a780e3..06badd114 100644 --- a/src/celscript/legacy/cmdparser.h +++ b/src/celscript/legacy/cmdparser.h @@ -13,7 +13,7 @@ #define _CMDPARSER_H_ #include -#include +#include #include #include #include "command.h" // CommandSequence diff --git a/src/celscript/legacy/command.cpp b/src/celscript/legacy/command.cpp index 8b15f0d0b..c0a008094 100644 --- a/src/celscript/legacy/command.cpp +++ b/src/celscript/legacy/command.cpp @@ -1015,7 +1015,7 @@ void CommandConstellations::process(ExecutionEnvironment& env) } } -void CommandConstellations::setValues(celestia::compat::string_view _cons, bool act) +void CommandConstellations::setValues(std::string_view _cons, bool act) { // ignore all above 99 constellations if (constellations.size() == MAX_CONSTELLATIONS) @@ -1081,7 +1081,7 @@ void CommandConstellationColor::unsetColor() flags.unset = true; } -void CommandConstellationColor::setConstellations(celestia::compat::string_view _cons) +void CommandConstellationColor::setConstellations(std::string_view _cons) { // ignore all above 99 constellations if (constellations.size() == MAX_CONSTELLATIONS) diff --git a/src/celscript/legacy/command.h b/src/celscript/legacy/command.h index d23bb0f43..5e9eb3d21 100644 --- a/src/celscript/legacy/command.h +++ b/src/celscript/legacy/command.h @@ -14,7 +14,7 @@ #include #include -#include +#include #include #include "execenv.h" @@ -376,7 +376,7 @@ class CommandConstellations : public InstantaneousCommand public: void process(ExecutionEnvironment&) override; - void setValues(celestia::compat::string_view cons, bool act); + void setValues(std::string_view cons, bool act); Flags flags { false, false }; @@ -405,7 +405,7 @@ class CommandConstellationColor : public InstantaneousCommand public: void process(ExecutionEnvironment&) override; - void setConstellations(celestia::compat::string_view cons); + void setConstellations(std::string_view cons); void setColor(float r, float g, float b); void unsetColor(); diff --git a/src/celutil/stringutils.cpp b/src/celutil/stringutils.cpp index 8a1e7f39d..91ea3fb69 100644 --- a/src/celutil/stringutils.cpp +++ b/src/celutil/stringutils.cpp @@ -15,7 +15,7 @@ using namespace std; -int compareIgnoringCase(celestia::compat::string_view s1, celestia::compat::string_view s2) +int compareIgnoringCase(std::string_view s1, std::string_view s2) { auto i1 = s1.begin(); auto i2 = s2.begin(); @@ -31,7 +31,7 @@ int compareIgnoringCase(celestia::compat::string_view s1, celestia::compat::stri return s2.size() - s1.size(); } -int compareIgnoringCase(celestia::compat::string_view s1, celestia::compat::string_view s2, int n) +int compareIgnoringCase(std::string_view s1, std::string_view s2, int n) { auto i1 = s1.begin(); auto i2 = s2.begin(); @@ -48,8 +48,8 @@ int compareIgnoringCase(celestia::compat::string_view s1, celestia::compat::stri return n > 0 ? s2.size() - s1.size() : 0; } -bool CompareIgnoringCasePredicate::operator()(celestia::compat::string_view s1, - celestia::compat::string_view s2) const +bool CompareIgnoringCasePredicate::operator()(std::string_view s1, + std::string_view s2) const { return compareIgnoringCase(s1, s2) < 0; } diff --git a/src/celutil/stringutils.h b/src/celutil/stringutils.h index 81d9fef08..b2a196b1a 100644 --- a/src/celutil/stringutils.h +++ b/src/celutil/stringutils.h @@ -12,26 +12,26 @@ #pragma once +#include #include -#include -int compareIgnoringCase(celestia::compat::string_view s1, celestia::compat::string_view s2); -int compareIgnoringCase(celestia::compat::string_view s1, celestia::compat::string_view s2, int n); +int compareIgnoringCase(std::string_view s1, std::string_view s2); +int compareIgnoringCase(std::string_view s1, std::string_view s2, int n); struct CompareIgnoringCasePredicate { - bool operator()(celestia::compat::string_view, celestia::compat::string_view) const; + bool operator()(std::string_view, std::string_view) const; }; template -[[nodiscard]] bool to_number(celestia::compat::string_view p, T &result) +[[nodiscard]] bool to_number(std::string_view p, T &result) { auto r = celestia::compat::from_chars(p.data(), p.data() + p.size(), result); return r.ec == std::errc(); } template -[[nodiscard]] bool to_number(celestia::compat::string_view p, T &result, int base) +[[nodiscard]] bool to_number(std::string_view p, T &result, int base) { auto r = celestia::compat::from_chars(p.data(), p.data() + p.size(), result, base); return r.ec == std::errc();