Remove string_view compatibility headers
parent
d7b896c013
commit
e6a7b32fee
|
@ -365,9 +365,6 @@ else()
|
||||||
message(WARNING "C++ experimental filesystem library is unusable!\nWill use own implementation.")
|
message(WARNING "C++ experimental filesystem library is unusable!\nWill use own implementation.")
|
||||||
endif()
|
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")
|
try_compile(HAVE_CHARCONV ${CMAKE_BINARY_DIR} "${CMAKE_SOURCE_DIR}/checks/cxxccint.cpp")
|
||||||
if(HAVE_CHARCONV)
|
if(HAVE_CHARCONV)
|
||||||
try_compile(HAVE_FLOAT_CHARCONV ${CMAKE_BINARY_DIR} "${CMAKE_SOURCE_DIR}/checks/cxxccfloat.cpp")
|
try_compile(HAVE_FLOAT_CHARCONV ${CMAKE_BINARY_DIR} "${CMAKE_SOURCE_DIR}/checks/cxxccfloat.cpp")
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
#include <string_view>
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
std::string_view sv("test");
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
#include <experimental/string_view>
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
std::experimental::string_view sv("test");
|
|
||||||
}
|
|
|
@ -3,7 +3,5 @@
|
||||||
#cmakedefine HAVE_FLOAT_CHARCONV
|
#cmakedefine HAVE_FLOAT_CHARCONV
|
||||||
#cmakedefine HAVE_FILESYSTEM
|
#cmakedefine HAVE_FILESYSTEM
|
||||||
#cmakedefine HAVE_EXPERIMENTAL_FILESYSTEM
|
#cmakedefine HAVE_EXPERIMENTAL_FILESYSTEM
|
||||||
#cmakedefine HAVE_STRING_VIEW
|
|
||||||
#cmakedefine HAVE_EXPERIMENTAL_STRING_VIEW
|
|
||||||
#cmakedefine HAVE_WORDEXP
|
#cmakedefine HAVE_WORDEXP
|
||||||
#cmakedefine WORDS_BIGENDIAN
|
#cmakedefine WORDS_BIGENDIAN
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <config.h>
|
|
||||||
|
|
||||||
#ifdef HAVE_STRING_VIEW
|
|
||||||
#include <string_view>
|
|
||||||
namespace celestia
|
|
||||||
{
|
|
||||||
namespace compat
|
|
||||||
{
|
|
||||||
using std::basic_string_view;
|
|
||||||
using std::string_view;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#elif defined(HAVE_EXPERIMENTAL_STRING_VIEW)
|
|
||||||
#include <experimental/string_view>
|
|
||||||
namespace celestia
|
|
||||||
{
|
|
||||||
namespace compat
|
|
||||||
{
|
|
||||||
using std::experimental::basic_string_view;
|
|
||||||
using std::experimental::string_view;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#include <fmt/format.h>
|
|
||||||
#include "sv.h"
|
|
||||||
|
|
||||||
template<>
|
|
||||||
struct fmt::formatter<celestia::compat::string_view> : formatter<fmt::string_view>
|
|
||||||
{
|
|
||||||
template<typename FormatContext>
|
|
||||||
auto format(celestia::compat::string_view v, FormatContext& ctx)
|
|
||||||
{
|
|
||||||
fmt::string_view f{v.data(), v.size()};
|
|
||||||
return formatter<fmt::string_view>::format(f, ctx);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#endif
|
|
|
@ -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 <string>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#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 <cstdlib>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace celestia
|
|
||||||
{
|
|
||||||
namespace compat
|
|
||||||
{
|
|
||||||
template<
|
|
||||||
typename CharT,
|
|
||||||
typename Traits = std::char_traits<CharT>
|
|
||||||
> 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<const_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<CharT, Traits> &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<CharT, Traits>() 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<char>;
|
|
||||||
using wstring_view = basic_string_view<wchar_t>;
|
|
||||||
|
|
||||||
template<class CharT, class Traits>
|
|
||||||
constexpr bool operator==(basic_string_view <CharT, Traits> lhs,
|
|
||||||
basic_string_view <CharT, Traits> rhs) noexcept
|
|
||||||
{
|
|
||||||
return lhs.compare(rhs) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Helpers missing in C++17 for compatibility with C++11/C++14
|
|
||||||
*/
|
|
||||||
template<class CharT, class Traits>
|
|
||||||
constexpr bool operator==(basic_string_view <CharT, Traits> lhs,
|
|
||||||
std::basic_string <CharT, Traits> rhs) noexcept
|
|
||||||
{
|
|
||||||
return lhs == basic_string_view<CharT, Traits>(rhs);
|
|
||||||
}
|
|
||||||
template<class CharT, class Traits>
|
|
||||||
constexpr bool operator==(std::basic_string <CharT, Traits> lhs,
|
|
||||||
basic_string_view <CharT, Traits> rhs) noexcept
|
|
||||||
{
|
|
||||||
return rhs == lhs;
|
|
||||||
}
|
|
||||||
template<class CharT, class Traits, size_t N>
|
|
||||||
constexpr bool operator==(basic_string_view <CharT, Traits> lhs,
|
|
||||||
const CharT (&rhs)[N]) noexcept
|
|
||||||
{
|
|
||||||
return lhs == basic_string_view<CharT, Traits>(rhs, N-1);
|
|
||||||
}
|
|
||||||
template<class CharT, class Traits, size_t N>
|
|
||||||
constexpr bool operator==(const CharT (&lhs)[N],
|
|
||||||
basic_string_view <CharT, Traits> rhs) noexcept
|
|
||||||
{
|
|
||||||
return rhs == lhs;
|
|
||||||
}
|
|
||||||
template<class CharT, class Traits, size_t N>
|
|
||||||
constexpr bool operator==(basic_string_view <CharT, Traits> lhs,
|
|
||||||
const CharT* rhs) noexcept
|
|
||||||
{
|
|
||||||
return lhs.compare(rhs) == 0;
|
|
||||||
}
|
|
||||||
template<class CharT, class Traits, size_t N>
|
|
||||||
constexpr bool operator==(const CharT* lhs,
|
|
||||||
basic_string_view <CharT, Traits> rhs) noexcept
|
|
||||||
{
|
|
||||||
return rhs == lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class CharT, class Traits>
|
|
||||||
constexpr bool operator!=(basic_string_view <CharT, Traits> lhs,
|
|
||||||
basic_string_view <CharT, Traits> rhs) noexcept
|
|
||||||
{
|
|
||||||
return lhs.compare(rhs) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Helpers missing in C++17 for compatibility with C++11/C++14
|
|
||||||
*/
|
|
||||||
template<class CharT, class Traits>
|
|
||||||
constexpr bool operator!=(basic_string_view <CharT, Traits> lhs,
|
|
||||||
std::basic_string <CharT, Traits> rhs) noexcept
|
|
||||||
{
|
|
||||||
return !(lhs == rhs);
|
|
||||||
}
|
|
||||||
template<class CharT, class Traits>
|
|
||||||
constexpr bool operator!=(std::basic_string <CharT, Traits> lhs,
|
|
||||||
basic_string_view <CharT, Traits> rhs) noexcept
|
|
||||||
{
|
|
||||||
return !(lhs == rhs);
|
|
||||||
}
|
|
||||||
template<class CharT, class Traits, size_t N>
|
|
||||||
constexpr bool operator!=(basic_string_view <CharT, Traits> lhs,
|
|
||||||
const CharT* rhs) noexcept
|
|
||||||
{
|
|
||||||
return !(lhs == rhs);
|
|
||||||
}
|
|
||||||
template<class CharT, class Traits, size_t N>
|
|
||||||
constexpr bool operator!=(const CharT* lhs,
|
|
||||||
basic_string_view <CharT, Traits> rhs) noexcept
|
|
||||||
{
|
|
||||||
return !(lhs == rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class CharT, class Traits>
|
|
||||||
constexpr bool operator<(basic_string_view <CharT, Traits> lhs,
|
|
||||||
basic_string_view <CharT, Traits> rhs) noexcept
|
|
||||||
{
|
|
||||||
return lhs.compare(rhs) < 0;
|
|
||||||
}
|
|
||||||
template<class CharT, class Traits>
|
|
||||||
constexpr bool operator<=(basic_string_view <CharT, Traits> lhs,
|
|
||||||
basic_string_view <CharT, Traits> rhs) noexcept
|
|
||||||
{
|
|
||||||
return lhs.compare(rhs) <= 0;
|
|
||||||
}
|
|
||||||
template<class CharT, class Traits>
|
|
||||||
constexpr bool operator>(basic_string_view <CharT, Traits> lhs,
|
|
||||||
basic_string_view <CharT, Traits> rhs) noexcept
|
|
||||||
{
|
|
||||||
return lhs.compare(rhs) > 0;
|
|
||||||
}
|
|
||||||
template<class CharT, class Traits>
|
|
||||||
constexpr bool operator>=(basic_string_view <CharT, Traits> lhs,
|
|
||||||
basic_string_view <CharT, Traits> rhs) noexcept
|
|
||||||
{
|
|
||||||
return lhs.compare(rhs) >= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class CharT, class Traits>
|
|
||||||
std::basic_ostream <CharT, Traits>& operator<<(std::basic_ostream <CharT, Traits>& os,
|
|
||||||
celestia::compat::basic_string_view <CharT, Traits> v)
|
|
||||||
{
|
|
||||||
os.write(v.data(), v.size());
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
template<size_t size = sizeof(size_t)>
|
|
||||||
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<typename T>
|
|
||||||
struct hash;
|
|
||||||
|
|
||||||
template<>
|
|
||||||
struct hash<string_view>
|
|
||||||
{
|
|
||||||
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
|
|
|
@ -103,7 +103,7 @@ static const char* MonthAbbrList[12] =
|
||||||
|
|
||||||
struct UnitDefinition
|
struct UnitDefinition
|
||||||
{
|
{
|
||||||
celestia::compat::string_view name;
|
std::string_view name;
|
||||||
double conversion;
|
double conversion;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -763,7 +763,7 @@ astro::TAItoJDUTC(double tai)
|
||||||
|
|
||||||
|
|
||||||
// Get scale of given length unit in kilometers
|
// 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]);
|
unsigned int nUnits = sizeof(lengthUnits) / sizeof(lengthUnits[0]);
|
||||||
bool foundMatch = false;
|
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
|
// 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)
|
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
|
// 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)
|
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)
|
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
|
// Check if unit is a length unit
|
||||||
bool astro::isLengthUnit(celestia::compat::string_view unitName)
|
bool astro::isLengthUnit(std::string_view unitName)
|
||||||
{
|
{
|
||||||
double dummy;
|
double dummy;
|
||||||
return getLengthScale(unitName, dummy);
|
return getLengthScale(unitName, dummy);
|
||||||
|
@ -837,7 +837,7 @@ bool astro::isLengthUnit(celestia::compat::string_view unitName)
|
||||||
|
|
||||||
|
|
||||||
// Check if unit is a time unit
|
// Check if unit is a time unit
|
||||||
bool astro::isTimeUnit(celestia::compat::string_view unitName)
|
bool astro::isTimeUnit(std::string_view unitName)
|
||||||
{
|
{
|
||||||
double dummy;
|
double dummy;
|
||||||
return getTimeScale(unitName, dummy);
|
return getTimeScale(unitName, dummy);
|
||||||
|
@ -845,14 +845,14 @@ bool astro::isTimeUnit(celestia::compat::string_view unitName)
|
||||||
|
|
||||||
|
|
||||||
// Check if unit is an angle unit
|
// Check if unit is an angle unit
|
||||||
bool astro::isAngleUnit(celestia::compat::string_view unitName)
|
bool astro::isAngleUnit(std::string_view unitName)
|
||||||
{
|
{
|
||||||
double dummy;
|
double dummy;
|
||||||
return getAngleScale(unitName, dummy);
|
return getAngleScale(unitName, dummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool astro::isMassUnit(celestia::compat::string_view unitName)
|
bool astro::isMassUnit(std::string_view unitName)
|
||||||
{
|
{
|
||||||
double dummy;
|
double dummy;
|
||||||
return getMassScale(unitName, dummy);
|
return getMassScale(unitName, dummy);
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
#include <Eigen/Geometry>
|
#include <Eigen/Geometry>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <celcompat/string_view.h>
|
#include <string_view>
|
||||||
#include <celmath/mathlib.h>
|
#include <celmath/mathlib.h>
|
||||||
|
|
||||||
#define SOLAR_ABSMAG 4.83f
|
#define SOLAR_ABSMAG 4.83f
|
||||||
|
@ -195,14 +195,14 @@ namespace astro
|
||||||
return jd * SECONDS_PER_DAY;
|
return jd * SECONDS_PER_DAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isLengthUnit(celestia::compat::string_view unitName);
|
bool isLengthUnit(std::string_view unitName);
|
||||||
bool isTimeUnit(celestia::compat::string_view unitName);
|
bool isTimeUnit(std::string_view unitName);
|
||||||
bool isAngleUnit(celestia::compat::string_view unitName);
|
bool isAngleUnit(std::string_view unitName);
|
||||||
bool isMassUnit(celestia::compat::string_view unitName);
|
bool isMassUnit(std::string_view unitName);
|
||||||
bool getLengthScale(celestia::compat::string_view unitName, double& scale);
|
bool getLengthScale(std::string_view unitName, double& scale);
|
||||||
bool getTimeScale(celestia::compat::string_view unitName, double& scale);
|
bool getTimeScale(std::string_view unitName, double& scale);
|
||||||
bool getAngleScale(celestia::compat::string_view unitName, double& scale);
|
bool getAngleScale(std::string_view unitName, double& scale);
|
||||||
bool getMassScale(celestia::compat::string_view unitName, double& scale);
|
bool getMassScale(std::string_view unitName, double& scale);
|
||||||
|
|
||||||
void decimalToDegMinSec(double angle, int& degrees, int& minutes, double& seconds);
|
void decimalToDegMinSec(double angle, int& degrees, int& minutes, double& seconds);
|
||||||
double degMinSecToDecimal(int degrees, int minutes, double seconds);
|
double degMinSecToDecimal(int degrees, int minutes, double seconds);
|
||||||
|
|
|
@ -65,7 +65,7 @@ std::string getBodyShortName(const std::string &body)
|
||||||
return D_(body.c_str());
|
return D_(body.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
celestia::compat::string_view
|
std::string_view
|
||||||
getCoordSysName(ObserverFrame::CoordinateSystem mode)
|
getCoordSysName(ObserverFrame::CoordinateSystem mode)
|
||||||
{
|
{
|
||||||
switch (mode)
|
switch (mode)
|
||||||
|
@ -293,17 +293,17 @@ Url::getEncodedObjectName(const Selection& selection, const CelestiaCore* appCor
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
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;
|
std::string out;
|
||||||
|
|
||||||
b = str.find('%');
|
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);
|
auto s = str.substr(a, b - a);
|
||||||
out.append(s.data(), s.length());
|
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;
|
uint8_t c;
|
||||||
if (to_number(c_code, c, 16))
|
if (to_number(c_code, c, 16))
|
||||||
{
|
{
|
||||||
|
@ -328,7 +328,7 @@ Url::decodeString(celestia::compat::string_view str)
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
Url::encodeString(celestia::compat::string_view str)
|
Url::encodeString(std::string_view str)
|
||||||
{
|
{
|
||||||
std::ostringstream enc;
|
std::ostringstream enc;
|
||||||
|
|
||||||
|
@ -370,7 +370,7 @@ Url::encodeString(celestia::compat::string_view str)
|
||||||
|
|
||||||
struct Mode
|
struct Mode
|
||||||
{
|
{
|
||||||
celestia::compat::string_view modeStr;
|
std::string_view modeStr;
|
||||||
ObserverFrame::CoordinateSystem mode;
|
ObserverFrame::CoordinateSystem mode;
|
||||||
int nBodies;
|
int nBodies;
|
||||||
};
|
};
|
||||||
|
@ -384,12 +384,12 @@ static Mode modes[] =
|
||||||
{ "PhaseLock", ObserverFrame::PhaseLock, 2 },
|
{ "PhaseLock", ObserverFrame::PhaseLock, 2 },
|
||||||
};
|
};
|
||||||
|
|
||||||
auto ParseURLParams(celestia::compat::string_view paramsStr)
|
auto ParseURLParams(std::string_view paramsStr)
|
||||||
-> std::map<celestia::compat::string_view, std::string>;
|
-> std::map<std::string_view, std::string>;
|
||||||
|
|
||||||
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://)
|
// proper URL string must start with protocol (cel://)
|
||||||
if (urlStr.compare(0, Url::proto().length(), Url::proto()) != 0)
|
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());
|
auto pathStr = urlStr.substr(Url::proto().length(), pos - Url::proto().length());
|
||||||
while (pathStr.back() == '/')
|
while (pathStr.back() == '/')
|
||||||
pathStr.remove_suffix(1);
|
pathStr.remove_suffix(1);
|
||||||
celestia::compat::string_view paramsStr;
|
std::string_view paramsStr;
|
||||||
if (pos != npos)
|
if (pos != npos)
|
||||||
paramsStr = urlStr.substr(pos + 1);
|
paramsStr = urlStr.substr(pos + 1);
|
||||||
|
|
||||||
|
@ -516,14 +516,14 @@ bool Url::parse(celestia::compat::string_view urlStr)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ParseURLParams(celestia::compat::string_view paramsStr)
|
auto ParseURLParams(std::string_view paramsStr)
|
||||||
-> std::map<celestia::compat::string_view, std::string>
|
-> std::map<std::string_view, std::string>
|
||||||
{
|
{
|
||||||
std::map<celestia::compat::string_view, std::string> params;
|
std::map<std::string_view, std::string> params;
|
||||||
if (paramsStr.empty())
|
if (paramsStr.empty())
|
||||||
return params;
|
return params;
|
||||||
|
|
||||||
constexpr auto npos = celestia::compat::string_view::npos;
|
constexpr auto npos = std::string_view::npos;
|
||||||
for (auto iter = paramsStr;;)
|
for (auto iter = paramsStr;;)
|
||||||
{
|
{
|
||||||
auto pos = iter.find('&');
|
auto pos = iter.find('&');
|
||||||
|
@ -543,7 +543,7 @@ auto ParseURLParams(celestia::compat::string_view paramsStr)
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Url::initVersion3(std::map<celestia::compat::string_view, std::string> ¶ms, celestia::compat::string_view timeStr)
|
bool Url::initVersion3(std::map<std::string_view, std::string> ¶ms, std::string_view timeStr)
|
||||||
{
|
{
|
||||||
m_version = 3;
|
m_version = 3;
|
||||||
|
|
||||||
|
@ -631,7 +631,7 @@ bool Url::initVersion3(std::map<celestia::compat::string_view, std::string> &par
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Url::initVersion4(std::map<celestia::compat::string_view, std::string> ¶ms, celestia::compat::string_view timeStr)
|
bool Url::initVersion4(std::map<std::string_view, std::string> ¶ms, std::string_view timeStr)
|
||||||
{
|
{
|
||||||
if (params.count("rf") != 0)
|
if (params.count("rf") != 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,10 +12,10 @@
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <Eigen/Geometry>
|
#include <Eigen/Geometry>
|
||||||
#include <celengine/observer.h>
|
#include <celengine/observer.h>
|
||||||
#include <celengine/astro.h>
|
#include <celengine/astro.h>
|
||||||
#include <celcompat/string_view.h>
|
|
||||||
#include "celestiastate.h"
|
#include "celestiastate.h"
|
||||||
|
|
||||||
class CelestiaCore;
|
class CelestiaCore;
|
||||||
|
@ -53,17 +53,17 @@ class Url
|
||||||
~Url() = default;
|
~Url() = default;
|
||||||
|
|
||||||
static std::string getEncodedObjectName(const Selection& sel, const CelestiaCore* appCore);
|
static std::string getEncodedObjectName(const Selection& sel, const CelestiaCore* appCore);
|
||||||
static constexpr celestia::compat::string_view proto();
|
static constexpr std::string_view proto();
|
||||||
static std::string decodeString(celestia::compat::string_view);
|
static std::string decodeString(std::string_view);
|
||||||
static std::string encodeString(celestia::compat::string_view);
|
static std::string encodeString(std::string_view);
|
||||||
|
|
||||||
bool parse(celestia::compat::string_view);
|
bool parse(std::string_view);
|
||||||
bool goTo();
|
bool goTo();
|
||||||
std::string getAsString() const;
|
std::string getAsString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool initVersion3(std::map<celestia::compat::string_view, std::string> ¶ms, celestia::compat::string_view timeStr);
|
bool initVersion3(std::map<std::string_view, std::string> ¶ms, std::string_view timeStr);
|
||||||
bool initVersion4(std::map<celestia::compat::string_view, std::string> ¶ms, celestia::compat::string_view timeStr);
|
bool initVersion4(std::map<std::string_view, std::string> ¶ms, std::string_view timeStr);
|
||||||
void evalName();
|
void evalName();
|
||||||
|
|
||||||
CelestiaState m_state;
|
CelestiaState m_state;
|
||||||
|
@ -84,7 +84,7 @@ class Url
|
||||||
bool m_valid { false };
|
bool m_valid { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr celestia::compat::string_view Url::proto()
|
constexpr std::string_view Url::proto()
|
||||||
{
|
{
|
||||||
return "cel://";
|
return "cel://";
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#define _CMDPARSER_H_
|
#define _CMDPARSER_H_
|
||||||
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <celcompat/string_view.h>
|
#include <string_view>
|
||||||
#include <celscript/common/scriptmaps.h>
|
#include <celscript/common/scriptmaps.h>
|
||||||
#include <celutil/array_view.h>
|
#include <celutil/array_view.h>
|
||||||
#include "command.h" // CommandSequence
|
#include "command.h" // CommandSequence
|
||||||
|
|
|
@ -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
|
// ignore all above 99 constellations
|
||||||
if (constellations.size() == MAX_CONSTELLATIONS)
|
if (constellations.size() == MAX_CONSTELLATIONS)
|
||||||
|
@ -1081,7 +1081,7 @@ void CommandConstellationColor::unsetColor()
|
||||||
flags.unset = true;
|
flags.unset = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandConstellationColor::setConstellations(celestia::compat::string_view _cons)
|
void CommandConstellationColor::setConstellations(std::string_view _cons)
|
||||||
{
|
{
|
||||||
// ignore all above 99 constellations
|
// ignore all above 99 constellations
|
||||||
if (constellations.size() == MAX_CONSTELLATIONS)
|
if (constellations.size() == MAX_CONSTELLATIONS)
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <celcompat/string_view.h>
|
#include <string_view>
|
||||||
#include <celutil/color.h>
|
#include <celutil/color.h>
|
||||||
#include "execenv.h"
|
#include "execenv.h"
|
||||||
|
|
||||||
|
@ -376,7 +376,7 @@ class CommandConstellations : public InstantaneousCommand
|
||||||
public:
|
public:
|
||||||
void process(ExecutionEnvironment&) override;
|
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 };
|
Flags flags { false, false };
|
||||||
|
|
||||||
|
@ -405,7 +405,7 @@ class CommandConstellationColor : public InstantaneousCommand
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void process(ExecutionEnvironment&) override;
|
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 setColor(float r, float g, float b);
|
||||||
void unsetColor();
|
void unsetColor();
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
using namespace std;
|
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 i1 = s1.begin();
|
||||||
auto i2 = s2.begin();
|
auto i2 = s2.begin();
|
||||||
|
@ -31,7 +31,7 @@ int compareIgnoringCase(celestia::compat::string_view s1, celestia::compat::stri
|
||||||
return s2.size() - s1.size();
|
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 i1 = s1.begin();
|
||||||
auto i2 = s2.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;
|
return n > 0 ? s2.size() - s1.size() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CompareIgnoringCasePredicate::operator()(celestia::compat::string_view s1,
|
bool CompareIgnoringCasePredicate::operator()(std::string_view s1,
|
||||||
celestia::compat::string_view s2) const
|
std::string_view s2) const
|
||||||
{
|
{
|
||||||
return compareIgnoringCase(s1, s2) < 0;
|
return compareIgnoringCase(s1, s2) < 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,26 +12,26 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
#include <celcompat/charconv.h>
|
#include <celcompat/charconv.h>
|
||||||
#include <celcompat/string_view.h>
|
|
||||||
|
|
||||||
int compareIgnoringCase(celestia::compat::string_view s1, celestia::compat::string_view s2);
|
int compareIgnoringCase(std::string_view s1, std::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 n);
|
||||||
|
|
||||||
struct CompareIgnoringCasePredicate
|
struct CompareIgnoringCasePredicate
|
||||||
{
|
{
|
||||||
bool operator()(celestia::compat::string_view, celestia::compat::string_view) const;
|
bool operator()(std::string_view, std::string_view) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
[[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);
|
auto r = celestia::compat::from_chars(p.data(), p.data() + p.size(), result);
|
||||||
return r.ec == std::errc();
|
return r.ec == std::errc();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
[[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);
|
auto r = celestia::compat::from_chars(p.data(), p.data() + p.size(), result, base);
|
||||||
return r.ec == std::errc();
|
return r.ec == std::errc();
|
||||||
|
|
Loading…
Reference in New Issue