mirror of
https://github.com/CookiePLMonster/SilentPatch.git
synced 2024-12-29 15:23:02 +05:00
add Patternies
This commit is contained in:
parent
f845ceb25f
commit
943a3acc24
9 changed files with 1396 additions and 0 deletions
269
SilentPatch/Patterns.cpp
Normal file
269
SilentPatch/Patterns.cpp
Normal file
|
@ -0,0 +1,269 @@
|
|||
/*
|
||||
* This file is part of the CitizenFX project - http://citizen.re/
|
||||
*
|
||||
* See LICENSE and MENTIONS in the root of the source tree for information
|
||||
* regarding licensing.
|
||||
*/
|
||||
|
||||
#include "Patterns.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
#include <algorithm>
|
||||
#include "string_view.hpp"
|
||||
|
||||
#if PATTERNS_USE_HINTS
|
||||
#include <map>
|
||||
#endif
|
||||
|
||||
|
||||
#if PATTERNS_USE_HINTS
|
||||
|
||||
// from boost someplace
|
||||
template <std::uint64_t FnvPrime, std::uint64_t OffsetBasis>
|
||||
struct basic_fnv_1
|
||||
{
|
||||
std::uint64_t operator()(libcxx_strviewclone::string_view text) const
|
||||
{
|
||||
std::uint64_t hash = OffsetBasis;
|
||||
for (auto it : text)
|
||||
{
|
||||
hash *= FnvPrime;
|
||||
hash ^= it;
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
};
|
||||
|
||||
const std::uint64_t fnv_prime = 1099511628211u;
|
||||
const std::uint64_t fnv_offset_basis = 14695981039346656037u;
|
||||
|
||||
typedef basic_fnv_1<fnv_prime, fnv_offset_basis> fnv_1;
|
||||
|
||||
#endif
|
||||
|
||||
namespace hook
|
||||
{
|
||||
ptrdiff_t baseAddressDifference;
|
||||
|
||||
// sets the base to the process main base
|
||||
void set_base()
|
||||
{
|
||||
set_base((uintptr_t)GetModuleHandle(nullptr));
|
||||
}
|
||||
|
||||
|
||||
#if PATTERNS_USE_HINTS
|
||||
static std::multimap<uint64_t, uintptr_t> g_hints;
|
||||
#endif
|
||||
|
||||
static void TransformPattern(libcxx_strviewclone::string_view pattern, std::string& data, std::string& mask)
|
||||
{
|
||||
uint8_t tempDigit = 0;
|
||||
bool tempFlag = false;
|
||||
|
||||
auto tol = [] (char ch) -> uint8_t
|
||||
{
|
||||
if (ch >= 'A' && ch <= 'F') return uint8_t(ch - 'A' + 10);
|
||||
if (ch >= 'a' && ch <= 'f') return uint8_t(ch - 'a' + 10);
|
||||
return uint8_t(ch - '0');
|
||||
};
|
||||
|
||||
for (auto ch : pattern)
|
||||
{
|
||||
if (ch == ' ')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (ch == '?')
|
||||
{
|
||||
data.push_back(0);
|
||||
mask.push_back('?');
|
||||
}
|
||||
else if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f'))
|
||||
{
|
||||
uint8_t thisDigit = tol(ch);
|
||||
|
||||
if (!tempFlag)
|
||||
{
|
||||
tempDigit = thisDigit << 4;
|
||||
tempFlag = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
tempDigit |= thisDigit;
|
||||
tempFlag = false;
|
||||
|
||||
data.push_back(tempDigit);
|
||||
mask.push_back('x');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class executable_meta
|
||||
{
|
||||
private:
|
||||
uintptr_t m_begin;
|
||||
uintptr_t m_end;
|
||||
|
||||
public:
|
||||
template<typename TReturn, typename TOffset>
|
||||
TReturn* getRVA(TOffset rva)
|
||||
{
|
||||
return (TReturn*)(m_begin + rva);
|
||||
}
|
||||
|
||||
executable_meta(void* module)
|
||||
: m_begin((uintptr_t)module)
|
||||
{
|
||||
PIMAGE_DOS_HEADER dosHeader = getRVA<IMAGE_DOS_HEADER>(0);
|
||||
PIMAGE_NT_HEADERS ntHeader = getRVA<IMAGE_NT_HEADERS>(dosHeader->e_lfanew);
|
||||
|
||||
m_end = m_begin + ntHeader->OptionalHeader.SizeOfCode;
|
||||
}
|
||||
|
||||
inline uintptr_t begin() const { return m_begin; }
|
||||
inline uintptr_t end() const { return m_end; }
|
||||
};
|
||||
|
||||
void pattern::Initialize(const char* pattern, size_t length)
|
||||
{
|
||||
// get the hash for the base pattern
|
||||
#if PATTERNS_USE_HINTS
|
||||
m_hash = fnv_1()(libcxx_strviewclone::string_view(pattern, length));
|
||||
#endif
|
||||
|
||||
// transform the base pattern from IDA format to canonical format
|
||||
TransformPattern(libcxx_strviewclone::string_view(pattern, length), m_bytes, m_mask);
|
||||
|
||||
m_size = m_mask.size();
|
||||
|
||||
#if PATTERNS_USE_HINTS
|
||||
// if there's hints, try those first
|
||||
if (m_module == GetModuleHandle(nullptr))
|
||||
{
|
||||
auto range = g_hints.equal_range(m_hash);
|
||||
|
||||
if (range.first != range.second)
|
||||
{
|
||||
std::for_each(range.first, range.second, [&] (const std::pair<uint64_t, uintptr_t>& hint)
|
||||
{
|
||||
ConsiderMatch(hint.second);
|
||||
});
|
||||
|
||||
// if the hints succeeded, we don't need to do anything more
|
||||
if (!m_matches.empty())
|
||||
{
|
||||
m_matched = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void pattern::EnsureMatches(uint32_t maxCount)
|
||||
{
|
||||
if (m_matched)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// scan the executable for code
|
||||
executable_meta executable(m_module);
|
||||
|
||||
auto matchSuccess = [&] (uintptr_t address)
|
||||
{
|
||||
#if PATTERNS_USE_HINTS
|
||||
g_hints.emplace(m_hash, address);
|
||||
#else
|
||||
(void)address;
|
||||
#endif
|
||||
|
||||
return (m_matches.size() == maxCount);
|
||||
};
|
||||
|
||||
const uint8_t* pattern = reinterpret_cast<const uint8_t*>(m_bytes.c_str());
|
||||
const char* mask = m_mask.c_str();
|
||||
size_t lastWild = m_mask.find_last_of('?');
|
||||
|
||||
ptrdiff_t Last[256];
|
||||
|
||||
std::fill(std::begin(Last), std::end(Last), lastWild == std::string::npos ? -1 : static_cast<ptrdiff_t>(lastWild) );
|
||||
|
||||
for ( ptrdiff_t i = 0; i < static_cast<ptrdiff_t>(m_size); ++i )
|
||||
{
|
||||
if ( Last[ pattern[i] ] < i )
|
||||
{
|
||||
Last[ pattern[i] ] = i;
|
||||
}
|
||||
}
|
||||
|
||||
for (uintptr_t i = executable.begin(), end = executable.end() - m_size; i <= end;)
|
||||
{
|
||||
uint8_t* ptr = reinterpret_cast<uint8_t*>(i);
|
||||
ptrdiff_t j = m_size - 1;
|
||||
|
||||
while((j >= 0) && (mask[j] == '?' || pattern[j] == ptr[j])) j--;
|
||||
|
||||
if(j < 0)
|
||||
{
|
||||
m_matches.emplace_back(ptr);
|
||||
|
||||
if (matchSuccess(i))
|
||||
{
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
else i += std::max(1, j - Last[ ptr[j] ]);
|
||||
}
|
||||
|
||||
m_matched = true;
|
||||
}
|
||||
|
||||
bool pattern::ConsiderMatch(uintptr_t offset)
|
||||
{
|
||||
const char* pattern = m_bytes.c_str();
|
||||
const char* mask = m_mask.c_str();
|
||||
|
||||
char* ptr = reinterpret_cast<char*>(offset);
|
||||
|
||||
for (size_t i = 0; i < m_size; i++)
|
||||
{
|
||||
if (mask[i] == '?')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pattern[i] != ptr[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
m_matches.emplace_back(ptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#if PATTERNS_USE_HINTS
|
||||
void pattern::hint(uint64_t hash, uintptr_t address)
|
||||
{
|
||||
auto range = g_hints.equal_range(hash);
|
||||
|
||||
for (auto it = range.first; it != range.second; it++)
|
||||
{
|
||||
if (it->second == address)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
g_hints.emplace(hash, address);
|
||||
}
|
||||
#endif
|
||||
}
|
175
SilentPatch/Patterns.h
Normal file
175
SilentPatch/Patterns.h
Normal file
|
@ -0,0 +1,175 @@
|
|||
/*
|
||||
* This file is part of the CitizenFX project - http://citizen.re/
|
||||
*
|
||||
* See LICENSE and MENTIONS in the root of the source tree for information
|
||||
* regarding licensing.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
|
||||
#define PATTERNS_USE_HINTS 0
|
||||
|
||||
namespace hook
|
||||
{
|
||||
extern ptrdiff_t baseAddressDifference;
|
||||
|
||||
// sets the base address difference based on an obtained pointer
|
||||
inline void set_base(uintptr_t address)
|
||||
{
|
||||
#ifdef _M_IX86
|
||||
uintptr_t addressDiff = (address - 0x400000);
|
||||
#elif defined(_M_AMD64)
|
||||
uintptr_t addressDiff = (address - 0x140000000);
|
||||
#endif
|
||||
|
||||
// pointer-style cast to ensure unsigned overflow ends up copied directly into a signed value
|
||||
baseAddressDifference = *(ptrdiff_t*)&addressDiff;
|
||||
}
|
||||
|
||||
// sets the base to the process main base
|
||||
void set_base();
|
||||
|
||||
template<typename T>
|
||||
inline T* getRVA(uintptr_t rva)
|
||||
{
|
||||
set_base();
|
||||
#ifdef _M_IX86
|
||||
return (T*)(baseAddressDifference + 0x400000 + rva);
|
||||
#elif defined(_M_AMD64)
|
||||
return (T*)(0x140000000 + rva);
|
||||
#endif
|
||||
}
|
||||
|
||||
class pattern_match
|
||||
{
|
||||
private:
|
||||
void* m_pointer;
|
||||
|
||||
public:
|
||||
inline pattern_match(void* pointer)
|
||||
: m_pointer(pointer)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* get(ptrdiff_t offset = 0) const
|
||||
{
|
||||
char* ptr = reinterpret_cast<char*>(m_pointer);
|
||||
return reinterpret_cast<T*>(ptr + offset);
|
||||
}
|
||||
};
|
||||
|
||||
class pattern
|
||||
{
|
||||
private:
|
||||
std::string m_bytes;
|
||||
std::string m_mask;
|
||||
|
||||
#if PATTERNS_USE_HINTS
|
||||
uint64_t m_hash;
|
||||
#endif
|
||||
|
||||
size_t m_size;
|
||||
|
||||
std::vector<pattern_match> m_matches;
|
||||
|
||||
bool m_matched;
|
||||
|
||||
void* m_module;
|
||||
|
||||
protected:
|
||||
inline pattern(void* module)
|
||||
: m_module(module), m_matched(false)
|
||||
{
|
||||
}
|
||||
|
||||
void Initialize(const char* pattern, size_t length);
|
||||
|
||||
private:
|
||||
bool ConsiderMatch(uintptr_t offset);
|
||||
|
||||
void EnsureMatches(uint32_t maxCount);
|
||||
|
||||
inline const pattern_match& _get_internal(size_t index)
|
||||
{
|
||||
return m_matches[index];
|
||||
}
|
||||
|
||||
public:
|
||||
template<size_t Len>
|
||||
pattern(const char (&pattern)[Len])
|
||||
: pattern(getRVA<void>(0))
|
||||
{
|
||||
Initialize(pattern, Len);
|
||||
}
|
||||
|
||||
inline pattern& count(uint32_t expected)
|
||||
{
|
||||
EnsureMatches(expected);
|
||||
assert(m_matches.size() == expected);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline pattern& count_hint(uint32_t expected)
|
||||
{
|
||||
EnsureMatches(expected);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline size_t size()
|
||||
{
|
||||
EnsureMatches(UINT32_MAX);
|
||||
return m_matches.size();
|
||||
}
|
||||
|
||||
inline bool empty()
|
||||
{
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
inline const pattern_match& get(size_t index)
|
||||
{
|
||||
EnsureMatches(UINT32_MAX);
|
||||
return _get_internal(index);
|
||||
}
|
||||
|
||||
inline const pattern_match& get_one()
|
||||
{
|
||||
return count(1)._get_internal(0);
|
||||
}
|
||||
|
||||
template<typename T = void>
|
||||
inline auto get_first(ptrdiff_t offset = 0)
|
||||
{
|
||||
return get_one().get<T>(offset);
|
||||
}
|
||||
|
||||
public:
|
||||
#if PATTERNS_USE_HINTS
|
||||
// define a hint
|
||||
static void hint(uint64_t hash, uintptr_t address);
|
||||
#endif
|
||||
};
|
||||
|
||||
class module_pattern
|
||||
: public pattern
|
||||
{
|
||||
public:
|
||||
template<size_t Len>
|
||||
module_pattern(void* module, const char(&pattern)[Len])
|
||||
: pattern(module)
|
||||
{
|
||||
Initialize(pattern, Len);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename T = void, size_t Len>
|
||||
auto get_pattern(const char(&pattern_string)[Len], ptrdiff_t offset = 0)
|
||||
{
|
||||
return pattern(pattern_string).get_first<T>(offset);
|
||||
}
|
||||
}
|
919
SilentPatch/string_view.hpp
Normal file
919
SilentPatch/string_view.hpp
Normal file
|
@ -0,0 +1,919 @@
|
|||
// -*- C++ -*-
|
||||
//===------------------------ string_view ---------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// This is a clone of the libcxx std::experimental::string_view (on <experimental/string_view>)
|
||||
// sighly edited (by Denilson das Merces Amorim <dma_2012@hotmail.com>) to be independent of the
|
||||
// libcxx library stack, so this can be used as a library on other compilers.
|
||||
// This should be useful/fun until all the compilers have a string_view implementation.
|
||||
|
||||
#ifndef _LIBCPP_STRVIEWCLONE_LFTS_STRING_VIEW
|
||||
#define _LIBCPP_STRVIEWCLONE_LFTS_STRING_VIEW
|
||||
|
||||
// Some LIBCPP macros left here because they are somewhat useful.
|
||||
// (renamed to LIBCPP_STRVIEWCLONE, 'course)
|
||||
#include <cassert>
|
||||
#define __LIBCPP_STRVIEWCLONE_throw(ex) throw (ex) // Might undefine this if -fno-exceptions? Dunno.
|
||||
#define _LIBCPP_STRVIEWCLONE_ASSERT(x, m) assert(x && m) // Translate libcxx assertion to C assert
|
||||
#if __cplusplus < 201402L
|
||||
# define _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11
|
||||
#else
|
||||
# define _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 constexpr
|
||||
#endif
|
||||
|
||||
/*
|
||||
string_view synopsis
|
||||
namespace std {
|
||||
namespace experimental {
|
||||
inline namespace library_fundamentals_v1 {
|
||||
// 7.2, Class template basic_string_view
|
||||
template<class charT, class traits = char_traits<charT>>
|
||||
class basic_string_view;
|
||||
// 7.9, basic_string_view non-member comparison functions
|
||||
template<class charT, class traits>
|
||||
constexpr bool operator==(basic_string_view<charT, traits> x,
|
||||
basic_string_view<charT, traits> y) noexcept;
|
||||
template<class charT, class traits>
|
||||
constexpr bool operator!=(basic_string_view<charT, traits> x,
|
||||
basic_string_view<charT, traits> y) noexcept;
|
||||
template<class charT, class traits>
|
||||
constexpr bool operator< (basic_string_view<charT, traits> x,
|
||||
basic_string_view<charT, traits> y) noexcept;
|
||||
template<class charT, class traits>
|
||||
constexpr bool operator> (basic_string_view<charT, traits> x,
|
||||
basic_string_view<charT, traits> y) noexcept;
|
||||
template<class charT, class traits>
|
||||
constexpr bool operator<=(basic_string_view<charT, traits> x,
|
||||
basic_string_view<charT, traits> y) noexcept;
|
||||
template<class charT, class traits>
|
||||
constexpr bool operator>=(basic_string_view<charT, traits> x,
|
||||
basic_string_view<charT, traits> y) noexcept;
|
||||
// see below, sufficient additional overloads of comparison functions
|
||||
// 7.10, Inserters and extractors
|
||||
template<class charT, class traits>
|
||||
basic_ostream<charT, traits>&
|
||||
operator<<(basic_ostream<charT, traits>& os,
|
||||
basic_string_view<charT, traits> str);
|
||||
// basic_string_view typedef names
|
||||
typedef basic_string_view<char> string_view;
|
||||
typedef basic_string_view<char16_t> u16string_view;
|
||||
typedef basic_string_view<char32_t> u32string_view;
|
||||
typedef basic_string_view<wchar_t> wstring_view;
|
||||
template<class charT, class traits = char_traits<charT>>
|
||||
class basic_string_view {
|
||||
public:
|
||||
// types
|
||||
typedef traits traits_type;
|
||||
typedef charT value_type;
|
||||
typedef charT* pointer;
|
||||
typedef const charT* const_pointer;
|
||||
typedef charT& reference;
|
||||
typedef const charT& const_reference;
|
||||
typedef implementation-defined const_iterator;
|
||||
typedef const_iterator iterator;
|
||||
typedef reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
typedef const_reverse_iterator reverse_iterator;
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
static constexpr size_type npos = size_type(-1);
|
||||
// 7.3, basic_string_view constructors and assignment operators
|
||||
constexpr basic_string_view() noexcept;
|
||||
constexpr basic_string_view(const basic_string_view&) noexcept = default;
|
||||
basic_string_view& operator=(const basic_string_view&) noexcept = default;
|
||||
template<class Allocator>
|
||||
basic_string_view(const std::basic_string<charT, traits, Allocator>& str) noexcept;
|
||||
constexpr basic_string_view(const charT* str);
|
||||
constexpr basic_string_view(const charT* str, size_type len);
|
||||
// 7.4, basic_string_view iterator support
|
||||
constexpr const_iterator begin() const noexcept;
|
||||
constexpr const_iterator end() const noexcept;
|
||||
constexpr const_iterator cbegin() const noexcept;
|
||||
constexpr const_iterator cend() const noexcept;
|
||||
const_reverse_iterator rbegin() const noexcept;
|
||||
const_reverse_iterator rend() const noexcept;
|
||||
const_reverse_iterator crbegin() const noexcept;
|
||||
const_reverse_iterator crend() const noexcept;
|
||||
// 7.5, basic_string_view capacity
|
||||
constexpr size_type size() const noexcept;
|
||||
constexpr size_type length() const noexcept;
|
||||
constexpr size_type max_size() const noexcept;
|
||||
constexpr bool empty() const noexcept;
|
||||
// 7.6, basic_string_view element access
|
||||
constexpr const_reference operator[](size_type pos) const;
|
||||
constexpr const_reference at(size_type pos) const;
|
||||
constexpr const_reference front() const;
|
||||
constexpr const_reference back() const;
|
||||
constexpr const_pointer data() const noexcept;
|
||||
// 7.7, basic_string_view modifiers
|
||||
constexpr void clear() noexcept;
|
||||
constexpr void remove_prefix(size_type n);
|
||||
constexpr void remove_suffix(size_type n);
|
||||
constexpr void swap(basic_string_view& s) noexcept;
|
||||
// 7.8, basic_string_view string operations
|
||||
template<class Allocator>
|
||||
explicit operator std::basic_string<charT, traits, Allocator>() const;
|
||||
template<class Allocator = allocator<charT>>
|
||||
std::basic_string<charT, traits, Allocator> to_string(
|
||||
const Allocator& a = Allocator()) const;
|
||||
size_type copy(charT* s, size_type n, size_type pos = 0) const;
|
||||
constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
|
||||
constexpr int compare(basic_string_view s) const noexcept;
|
||||
constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;
|
||||
constexpr int compare(size_type pos1, size_type n1,
|
||||
basic_string_view s, size_type pos2, size_type n2) const;
|
||||
constexpr int compare(const charT* s) const;
|
||||
constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
|
||||
constexpr int compare(size_type pos1, size_type n1,
|
||||
const charT* s, size_type n2) const;
|
||||
constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;
|
||||
constexpr size_type find(charT c, size_type pos = 0) const noexcept;
|
||||
constexpr size_type find(const charT* s, size_type pos, size_type n) const;
|
||||
constexpr size_type find(const charT* s, size_type pos = 0) const;
|
||||
constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept;
|
||||
constexpr size_type rfind(charT c, size_type pos = npos) const noexcept;
|
||||
constexpr size_type rfind(const charT* s, size_type pos, size_type n) const;
|
||||
constexpr size_type rfind(const charT* s, size_type pos = npos) const;
|
||||
constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept;
|
||||
constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept;
|
||||
constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const;
|
||||
constexpr size_type find_first_of(const charT* s, size_type pos = 0) const;
|
||||
constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept;
|
||||
constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept;
|
||||
constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const;
|
||||
constexpr size_type find_last_of(const charT* s, size_type pos = npos) const;
|
||||
constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept;
|
||||
constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept;
|
||||
constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const;
|
||||
constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const;
|
||||
constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept;
|
||||
constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
|
||||
constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const;
|
||||
constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const;
|
||||
private:
|
||||
const_pointer data_; // exposition only
|
||||
size_type size_; // exposition only
|
||||
};
|
||||
} // namespace fundamentals_v1
|
||||
} // namespace experimental
|
||||
// 7.11, Hash support
|
||||
template <class T> struct hash;
|
||||
template <> struct hash<experimental::string_view>;
|
||||
template <> struct hash<experimental::u16string_view>;
|
||||
template <> struct hash<experimental::u32string_view>;
|
||||
template <> struct hash<experimental::wstring_view>;
|
||||
} // namespace std
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <ostream>
|
||||
#include <stdexcept>
|
||||
#include <iomanip>
|
||||
#include <cstddef>
|
||||
|
||||
namespace libcxx_strviewclone {
|
||||
|
||||
template<class _CharT, class _Traits = std::char_traits<_CharT> >
|
||||
class basic_string_view {
|
||||
public:
|
||||
// types
|
||||
typedef _Traits traits_type;
|
||||
typedef _CharT value_type;
|
||||
typedef const _CharT* pointer;
|
||||
typedef const _CharT* const_pointer;
|
||||
typedef const _CharT& reference;
|
||||
typedef const _CharT& const_reference;
|
||||
typedef const_pointer const_iterator; // See [string.view.iterators]
|
||||
typedef const_iterator iterator;
|
||||
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
typedef const_reverse_iterator reverse_iterator;
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
static constexpr const size_type npos = size_type(-1);
|
||||
|
||||
// [string.view.cons], construct/copy
|
||||
constexpr inline
|
||||
basic_string_view() noexcept : __data (nullptr), __size(0) {}
|
||||
|
||||
constexpr inline
|
||||
basic_string_view(const basic_string_view&) noexcept = default;
|
||||
|
||||
inline
|
||||
basic_string_view& operator=(const basic_string_view&) noexcept = default;
|
||||
|
||||
template<class _Allocator>
|
||||
inline
|
||||
basic_string_view(const std::basic_string<_CharT, _Traits, _Allocator>& __str) noexcept
|
||||
: __data (__str.data()), __size(__str.size()) {}
|
||||
|
||||
constexpr inline
|
||||
basic_string_view(const _CharT* __s, size_type __len)
|
||||
: __data(__s), __size(__len)
|
||||
{
|
||||
// _LIBCPP_STRVIEWCLONE_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr");
|
||||
}
|
||||
|
||||
constexpr inline
|
||||
basic_string_view(const _CharT* __s)
|
||||
: __data(__s), __size(_Traits::length(__s)) {}
|
||||
|
||||
// [string.view.iterators], iterators
|
||||
constexpr inline
|
||||
const_iterator begin() const noexcept { return cbegin(); }
|
||||
|
||||
constexpr inline
|
||||
const_iterator end() const noexcept { return cend(); }
|
||||
|
||||
constexpr inline
|
||||
const_iterator cbegin() const noexcept { return __data; }
|
||||
|
||||
constexpr inline
|
||||
const_iterator cend() const noexcept { return __data + __size; }
|
||||
|
||||
inline
|
||||
const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(cend()); }
|
||||
|
||||
inline
|
||||
const_reverse_iterator rend() const noexcept { return const_reverse_iterator(cbegin()); }
|
||||
|
||||
inline
|
||||
const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(cend()); }
|
||||
|
||||
inline
|
||||
const_reverse_iterator crend() const noexcept { return const_reverse_iterator(cbegin()); }
|
||||
|
||||
// [string.view.capacity], capacity
|
||||
constexpr inline
|
||||
size_type size() const noexcept { return __size; }
|
||||
|
||||
constexpr inline
|
||||
size_type length() const noexcept { return __size; }
|
||||
|
||||
constexpr inline
|
||||
size_type max_size() const noexcept { return std::numeric_limits<size_type>::max(); }
|
||||
|
||||
constexpr bool inline
|
||||
empty() const noexcept { return __size == 0; }
|
||||
|
||||
// [string.view.access], element access
|
||||
constexpr inline
|
||||
const_reference operator[](size_type __pos) const { return __data[__pos]; }
|
||||
|
||||
constexpr inline
|
||||
const_reference at(size_type __pos) const
|
||||
{
|
||||
return __pos >= size()
|
||||
? (__LIBCPP_STRVIEWCLONE_throw(std::out_of_range("string_view::at")), __data[0])
|
||||
: __data[__pos];
|
||||
}
|
||||
|
||||
constexpr inline
|
||||
const_reference front() const
|
||||
{
|
||||
return _LIBCPP_STRVIEWCLONE_ASSERT(!empty(), "string_view::front(): string is empty"), __data[0];
|
||||
}
|
||||
|
||||
constexpr inline
|
||||
const_reference back() const
|
||||
{
|
||||
return _LIBCPP_STRVIEWCLONE_ASSERT(!empty(), "string_view::back(): string is empty"), __data[__size-1];
|
||||
}
|
||||
|
||||
constexpr inline
|
||||
const_pointer data() const noexcept { return __data; }
|
||||
|
||||
// [string.view.modifiers], modifiers:
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
void clear() noexcept
|
||||
{
|
||||
__data = nullptr;
|
||||
__size = 0;
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
void remove_prefix(size_type __n) noexcept
|
||||
{
|
||||
_LIBCPP_STRVIEWCLONE_ASSERT(__n <= size(), "remove_prefix() can't remove more than size()");
|
||||
__data += __n;
|
||||
__size -= __n;
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
void remove_suffix(size_type __n) noexcept
|
||||
{
|
||||
_LIBCPP_STRVIEWCLONE_ASSERT(__n <= size(), "remove_suffix() can't remove more than size()");
|
||||
__size -= __n;
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
void swap(basic_string_view& __other) noexcept
|
||||
{
|
||||
const value_type *__p = __data;
|
||||
__data = __other.__data;
|
||||
__other.__data = __p;
|
||||
|
||||
size_type __sz = __size;
|
||||
__size = __other.__size;
|
||||
__other.__size = __sz;
|
||||
// std::swap( __data, __other.__data );
|
||||
// std::swap( __size, __other.__size );
|
||||
}
|
||||
|
||||
// [string.view.ops], string operations:
|
||||
template<class _Allocator>
|
||||
inline
|
||||
explicit operator std::basic_string<_CharT, _Traits, _Allocator>() const
|
||||
{ return std::basic_string<_CharT, _Traits, _Allocator>( begin(), end()); }
|
||||
|
||||
template<class _Allocator = std::allocator<_CharT> >
|
||||
inline
|
||||
std::basic_string<_CharT, _Traits, _Allocator>
|
||||
to_string( const _Allocator& __a = _Allocator()) const
|
||||
{ return std::basic_string<_CharT, _Traits, _Allocator> ( begin(), end(), __a ); }
|
||||
|
||||
size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const
|
||||
{
|
||||
if ( __pos > size())
|
||||
__LIBCPP_STRVIEWCLONE_throw(std::out_of_range("string_view::copy"));
|
||||
size_type __rlen = std::min( __n, size() - __pos );
|
||||
std::copy_n(begin() + __pos, __rlen, __s );
|
||||
return __rlen;
|
||||
}
|
||||
|
||||
constexpr
|
||||
basic_string_view substr(size_type __pos = 0, size_type __n = npos) const
|
||||
{
|
||||
// if (__pos > size())
|
||||
// throw out_of_range("string_view::substr");
|
||||
// size_type __rlen = std::min( __n, size() - __pos );
|
||||
// return basic_string_view(data() + __pos, __rlen);
|
||||
return __pos > size()
|
||||
? (__LIBCPP_STRVIEWCLONE_throw((std::out_of_range("string_view::substr"))), basic_string_view())
|
||||
: basic_string_view(data() + __pos, std::min(__n, size() - __pos));
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 int compare(basic_string_view __sv) const noexcept
|
||||
{
|
||||
size_type __rlen = std::min( size(), __sv.size());
|
||||
int __retval = _Traits::compare(data(), __sv.data(), __rlen);
|
||||
if ( __retval == 0 ) // first __rlen chars matched
|
||||
__retval = size() == __sv.size() ? 0 : ( size() < __sv.size() ? -1 : 1 );
|
||||
return __retval;
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const
|
||||
{
|
||||
return substr(__pos1, __n1).compare(__sv);
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
int compare( size_type __pos1, size_type __n1,
|
||||
basic_string_view _sv, size_type __pos2, size_type __n2) const
|
||||
{
|
||||
return substr(__pos1, __n1).compare(_sv.substr(__pos2, __n2));
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
int compare(const _CharT* __s) const
|
||||
{
|
||||
return compare(basic_string_view(__s));
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
int compare(size_type __pos1, size_type __n1, const _CharT* __s) const
|
||||
{
|
||||
return substr(__pos1, __n1).compare(basic_string_view(__s));
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const
|
||||
{
|
||||
return substr(__pos1, __n1).compare(basic_string_view(__s, __n2));
|
||||
}
|
||||
|
||||
// find
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type find(basic_string_view __s, size_type __pos = 0) const noexcept
|
||||
{
|
||||
_LIBCPP_STRVIEWCLONE_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
|
||||
return this->__str_find<value_type, size_type, traits_type, npos>
|
||||
(data(), size(), __s.data(), __pos, __s.size());
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type find(_CharT __c, size_type __pos = 0) const noexcept
|
||||
{
|
||||
return this->__str_find<value_type, size_type, traits_type, npos>
|
||||
(data(), size(), __c, __pos);
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type find(const _CharT* __s, size_type __pos, size_type __n) const
|
||||
{
|
||||
_LIBCPP_STRVIEWCLONE_ASSERT(__n == 0 || __s != nullptr, "string_view::find(): received nullptr");
|
||||
return this->__str_find<value_type, size_type, traits_type, npos>
|
||||
(data(), size(), __s, __pos, __n);
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type find(const _CharT* __s, size_type __pos = 0) const
|
||||
{
|
||||
_LIBCPP_STRVIEWCLONE_ASSERT(__s != nullptr, "string_view::find(): received nullptr");
|
||||
return this->__str_find<value_type, size_type, traits_type, npos>
|
||||
(data(), size(), __s, __pos, traits_type::length(__s));
|
||||
}
|
||||
|
||||
// rfind
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type rfind(basic_string_view __s, size_type __pos = npos) const noexcept
|
||||
{
|
||||
_LIBCPP_STRVIEWCLONE_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
|
||||
return this->__str_rfind<value_type, size_type, traits_type, npos>
|
||||
(data(), size(), __s.data(), __pos, __s.size());
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type rfind(_CharT __c, size_type __pos = npos) const noexcept
|
||||
{
|
||||
return this->__str_rfind<value_type, size_type, traits_type, npos>
|
||||
(data(), size(), __c, __pos);
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const
|
||||
{
|
||||
_LIBCPP_STRVIEWCLONE_ASSERT(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr");
|
||||
return this->__str_rfind<value_type, size_type, traits_type, npos>
|
||||
(data(), size(), __s, __pos, __n);
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type rfind(const _CharT* __s, size_type __pos=npos) const
|
||||
{
|
||||
_LIBCPP_STRVIEWCLONE_ASSERT(__s != nullptr, "string_view::rfind(): received nullptr");
|
||||
return this->__str_rfind<value_type, size_type, traits_type, npos>
|
||||
(data(), size(), __s, __pos, traits_type::length(__s));
|
||||
}
|
||||
|
||||
// find_first_of
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type find_first_of(basic_string_view __s, size_type __pos = 0) const noexcept
|
||||
{
|
||||
_LIBCPP_STRVIEWCLONE_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr");
|
||||
return this->__str_find_first_of<value_type, size_type, traits_type, npos>
|
||||
(data(), size(), __s.data(), __pos, __s.size());
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type find_first_of(_CharT __c, size_type __pos = 0) const noexcept
|
||||
{ return find(__c, __pos); }
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
|
||||
{
|
||||
_LIBCPP_STRVIEWCLONE_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr");
|
||||
return this->__str_find_first_of<value_type, size_type, traits_type, npos>
|
||||
(data(), size(), __s, __pos, __n);
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type find_first_of(const _CharT* __s, size_type __pos=0) const
|
||||
{
|
||||
_LIBCPP_STRVIEWCLONE_ASSERT(__s != nullptr, "string_view::find_first_of(): received nullptr");
|
||||
return this->__str_find_first_of<value_type, size_type, traits_type, npos>
|
||||
(data(), size(), __s, __pos, traits_type::length(__s));
|
||||
}
|
||||
|
||||
// find_last_of
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type find_last_of(basic_string_view __s, size_type __pos=npos) const noexcept
|
||||
{
|
||||
_LIBCPP_STRVIEWCLONE_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr");
|
||||
return this->__str_find_last_of<value_type, size_type, traits_type, npos>
|
||||
(data(), size(), __s.data(), __pos, __s.size());
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type find_last_of(_CharT __c, size_type __pos = npos) const noexcept
|
||||
{ return rfind(__c, __pos); }
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
|
||||
{
|
||||
_LIBCPP_STRVIEWCLONE_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr");
|
||||
return this->__str_find_last_of<value_type, size_type, traits_type, npos>
|
||||
(data(), size(), __s, __pos, __n);
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type find_last_of(const _CharT* __s, size_type __pos=npos) const
|
||||
{
|
||||
_LIBCPP_STRVIEWCLONE_ASSERT(__s != nullptr, "string_view::find_last_of(): received nullptr");
|
||||
return this->__str_find_last_of<value_type, size_type, traits_type, npos>
|
||||
(data(), size(), __s, __pos, traits_type::length(__s));
|
||||
}
|
||||
|
||||
// find_first_not_of
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const noexcept
|
||||
{
|
||||
_LIBCPP_STRVIEWCLONE_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr");
|
||||
return this->__str_find_first_not_of<value_type, size_type, traits_type, npos>
|
||||
(data(), size(), __s.data(), __pos, __s.size());
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type find_first_not_of(_CharT __c, size_type __pos=0) const noexcept
|
||||
{
|
||||
return this->__str_find_first_not_of<value_type, size_type, traits_type, npos>
|
||||
(data(), size(), __c, __pos);
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
|
||||
{
|
||||
_LIBCPP_STRVIEWCLONE_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr");
|
||||
return this->__str_find_first_not_of<value_type, size_type, traits_type, npos>
|
||||
(data(), size(), __s, __pos, __n);
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const
|
||||
{
|
||||
_LIBCPP_STRVIEWCLONE_ASSERT(__s != nullptr, "string_view::find_first_not_of(): received nullptr");
|
||||
return this->__str_find_first_not_of<value_type, size_type, traits_type, npos>
|
||||
(data(), size(), __s, __pos, traits_type::length(__s));
|
||||
}
|
||||
|
||||
// find_last_not_of
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const noexcept
|
||||
{
|
||||
_LIBCPP_STRVIEWCLONE_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr");
|
||||
return this->__str_find_last_not_of<value_type, size_type, traits_type, npos>
|
||||
(data(), size(), __s.data(), __pos, __s.size());
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type find_last_not_of(_CharT __c, size_type __pos=npos) const noexcept
|
||||
{
|
||||
return this->__str_find_last_not_of<value_type, size_type, traits_type, npos>
|
||||
(data(), size(), __c, __pos);
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
|
||||
{
|
||||
_LIBCPP_STRVIEWCLONE_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr");
|
||||
return this->__str_find_last_not_of<value_type, size_type, traits_type, npos>
|
||||
(data(), size(), __s, __pos, __n);
|
||||
}
|
||||
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const
|
||||
{
|
||||
_LIBCPP_STRVIEWCLONE_ASSERT(__s != nullptr, "string_view::find_last_not_of(): received nullptr");
|
||||
return this->__str_find_last_not_of<value_type, size_type, traits_type, npos>
|
||||
(data(), size(), __s, __pos, traits_type::length(__s));
|
||||
}
|
||||
|
||||
private:
|
||||
//
|
||||
// Some function taken from libcxx internals and put here, as private methods of string_view.
|
||||
//
|
||||
|
||||
// __str_find
|
||||
template<class /*_CharT*/, class _SizeT, class /*_Traits*/, _SizeT __npos>
|
||||
static _SizeT _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
__str_find(const _CharT *__p, _SizeT __sz,
|
||||
const _CharT* __s, _SizeT __pos, _SizeT __n) noexcept
|
||||
{
|
||||
if (__pos > __sz || __sz - __pos < __n)
|
||||
return __npos;
|
||||
if (__n == 0)
|
||||
return __pos;
|
||||
const _CharT* __r =
|
||||
std::search(__p + __pos, __p + __sz,
|
||||
__s, __s + __n, _Traits::eq);
|
||||
if (__r == __p + __sz)
|
||||
return __npos;
|
||||
return static_cast<_SizeT>(__r - __p);
|
||||
}
|
||||
|
||||
// __str_rfind
|
||||
template<class /*_CharT*/, class _SizeT, class /*_Traits*/, _SizeT __npos>
|
||||
static _SizeT _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
__str_rfind(const _CharT *__p, _SizeT __sz,
|
||||
const _CharT* __s, _SizeT __pos, _SizeT __n) noexcept
|
||||
{
|
||||
__pos = std::min(__pos, __sz);
|
||||
if (__n < __sz - __pos)
|
||||
__pos += __n;
|
||||
else
|
||||
__pos = __sz;
|
||||
const _CharT* __r = std::find_end(
|
||||
__p, __p + __pos, __s, __s + __n, _Traits::eq);
|
||||
if (__n > 0 && __r == __p + __pos)
|
||||
return __npos;
|
||||
return static_cast<_SizeT>(__r - __p);
|
||||
}
|
||||
|
||||
// __str_find_first_of
|
||||
template<class /*_CharT*/, class _SizeT, class /*_Traits*/, _SizeT __npos>
|
||||
static _SizeT _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
__str_find_first_of(const _CharT *__p, _SizeT __sz,
|
||||
const _CharT* __s, _SizeT __pos, _SizeT __n) noexcept
|
||||
{
|
||||
if (__pos >= __sz || __n == 0)
|
||||
return __npos;
|
||||
const _CharT* __r = std::find_first_of
|
||||
(__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq );
|
||||
if (__r == __p + __sz)
|
||||
return __npos;
|
||||
return static_cast<_SizeT>(__r - __p);
|
||||
}
|
||||
|
||||
|
||||
// __str_find_last_of
|
||||
template<class /*_CharT*/, class _SizeT, class /*_Traits*/, _SizeT __npos>
|
||||
static _SizeT _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
__str_find_last_of(const _CharT *__p, _SizeT __sz,
|
||||
const _CharT* __s, _SizeT __pos, _SizeT __n) noexcept
|
||||
{
|
||||
if (__n != 0)
|
||||
{
|
||||
if (__pos < __sz)
|
||||
++__pos;
|
||||
else
|
||||
__pos = __sz;
|
||||
for (const _CharT* __ps = __p + __pos; __ps != __p;)
|
||||
{
|
||||
const _CharT* __r = _Traits::find(__s, __n, *--__ps);
|
||||
if (__r)
|
||||
return static_cast<_SizeT>(__ps - __p);
|
||||
}
|
||||
}
|
||||
return __npos;
|
||||
}
|
||||
|
||||
|
||||
// __str_find_first_not_of
|
||||
template<class /*_CharT*/, class _SizeT, class /*_Traits*/, _SizeT __npos>
|
||||
static _SizeT _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
|
||||
const _CharT* __s, _SizeT __pos, _SizeT __n) noexcept
|
||||
{
|
||||
if (__pos < __sz)
|
||||
{
|
||||
const _CharT* __pe = __p + __sz;
|
||||
for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
|
||||
if (_Traits::find(__s, __n, *__ps) == 0)
|
||||
return static_cast<_SizeT>(__ps - __p);
|
||||
}
|
||||
return __npos;
|
||||
}
|
||||
|
||||
|
||||
// __str_find_last_not_of
|
||||
template<class /*_CharT*/, class _SizeT, class /*_Traits*/, _SizeT __npos>
|
||||
static _SizeT _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
__str_find_last_not_of(const _CharT *__p, _SizeT __sz,
|
||||
const _CharT* __s, _SizeT __pos, _SizeT __n) noexcept
|
||||
{
|
||||
if (__pos < __sz)
|
||||
++__pos;
|
||||
else
|
||||
__pos = __sz;
|
||||
for (const _CharT* __ps = __p + __pos; __ps != __p;)
|
||||
if (_Traits::find(__s, __n, *--__ps) == 0)
|
||||
return static_cast<_SizeT>(__ps - __p);
|
||||
return __npos;
|
||||
}
|
||||
|
||||
private:
|
||||
const value_type* __data;
|
||||
size_type __size;
|
||||
};
|
||||
|
||||
|
||||
// [string.view.comparison]
|
||||
// operator ==
|
||||
template<class _CharT, class _Traits>
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
bool operator==(basic_string_view<_CharT, _Traits> __lhs,
|
||||
basic_string_view<_CharT, _Traits> __rhs) noexcept
|
||||
{
|
||||
if ( __lhs.size() != __rhs.size()) return false;
|
||||
return __lhs.compare(__rhs) == 0;
|
||||
}
|
||||
|
||||
template<class _CharT, class _Traits>
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
bool operator==(basic_string_view<_CharT, _Traits> __lhs,
|
||||
typename std::common_type<basic_string_view<_CharT, _Traits> >::type __rhs) noexcept
|
||||
{
|
||||
if ( __lhs.size() != __rhs.size()) return false;
|
||||
return __lhs.compare(__rhs) == 0;
|
||||
}
|
||||
|
||||
template<class _CharT, class _Traits>
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
bool operator==(typename std::common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
|
||||
basic_string_view<_CharT, _Traits> __rhs) noexcept
|
||||
{
|
||||
if ( __lhs.size() != __rhs.size()) return false;
|
||||
return __lhs.compare(__rhs) == 0;
|
||||
}
|
||||
|
||||
|
||||
// operator !=
|
||||
template<class _CharT, class _Traits>
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
bool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) noexcept
|
||||
{
|
||||
if ( __lhs.size() != __rhs.size())
|
||||
return true;
|
||||
return __lhs.compare(__rhs) != 0;
|
||||
}
|
||||
|
||||
template<class _CharT, class _Traits>
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
bool operator!=(basic_string_view<_CharT, _Traits> __lhs,
|
||||
typename std::common_type<basic_string_view<_CharT, _Traits> >::type __rhs) noexcept
|
||||
{
|
||||
if ( __lhs.size() != __rhs.size())
|
||||
return true;
|
||||
return __lhs.compare(__rhs) != 0;
|
||||
}
|
||||
|
||||
template<class _CharT, class _Traits>
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
bool operator!=(typename std::common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
|
||||
basic_string_view<_CharT, _Traits> __rhs) noexcept
|
||||
{
|
||||
if ( __lhs.size() != __rhs.size())
|
||||
return true;
|
||||
return __lhs.compare(__rhs) != 0;
|
||||
}
|
||||
|
||||
|
||||
// operator <
|
||||
template<class _CharT, class _Traits>
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
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>
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
bool operator<(basic_string_view<_CharT, _Traits> __lhs,
|
||||
typename std::common_type<basic_string_view<_CharT, _Traits> >::type __rhs) noexcept
|
||||
{
|
||||
return __lhs.compare(__rhs) < 0;
|
||||
}
|
||||
|
||||
template<class _CharT, class _Traits>
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
bool operator<(typename std::common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
|
||||
basic_string_view<_CharT, _Traits> __rhs) noexcept
|
||||
{
|
||||
return __lhs.compare(__rhs) < 0;
|
||||
}
|
||||
|
||||
|
||||
// operator >
|
||||
template<class _CharT, class _Traits>
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
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>
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
bool operator>(basic_string_view<_CharT, _Traits> __lhs,
|
||||
typename std::common_type<basic_string_view<_CharT, _Traits> >::type __rhs) noexcept
|
||||
{
|
||||
return __lhs.compare(__rhs) > 0;
|
||||
}
|
||||
|
||||
template<class _CharT, class _Traits>
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
bool operator>(typename std::common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
|
||||
basic_string_view<_CharT, _Traits> __rhs) noexcept
|
||||
{
|
||||
return __lhs.compare(__rhs) > 0;
|
||||
}
|
||||
|
||||
|
||||
// operator <=
|
||||
template<class _CharT, class _Traits>
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
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>
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
bool operator<=(basic_string_view<_CharT, _Traits> __lhs,
|
||||
typename std::common_type<basic_string_view<_CharT, _Traits> >::type __rhs) noexcept
|
||||
{
|
||||
return __lhs.compare(__rhs) <= 0;
|
||||
}
|
||||
|
||||
template<class _CharT, class _Traits>
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
bool operator<=(typename std::common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
|
||||
basic_string_view<_CharT, _Traits> __rhs) noexcept
|
||||
{
|
||||
return __lhs.compare(__rhs) <= 0;
|
||||
}
|
||||
|
||||
|
||||
// operator >=
|
||||
template<class _CharT, class _Traits>
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
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>
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
bool operator>=(basic_string_view<_CharT, _Traits> __lhs,
|
||||
typename std::common_type<basic_string_view<_CharT, _Traits> >::type __rhs) noexcept
|
||||
{
|
||||
return __lhs.compare(__rhs) >= 0;
|
||||
}
|
||||
|
||||
template<class _CharT, class _Traits>
|
||||
_LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline
|
||||
bool operator>=(typename std::common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
|
||||
basic_string_view<_CharT, _Traits> __rhs) noexcept
|
||||
{
|
||||
return __lhs.compare(__rhs) >= 0;
|
||||
}
|
||||
|
||||
|
||||
// [string.view.io]
|
||||
template<class _CharT, class _Traits> inline
|
||||
std::basic_ostream<_CharT, _Traits>&
|
||||
operator<<(std::basic_ostream<_CharT, _Traits>& __os, basic_string_view<_CharT, _Traits> __sv)
|
||||
{
|
||||
auto& s = __sv;
|
||||
copy(s.begin(), s.end(), std::ostream_iterator<char>(__os));
|
||||
return __os;
|
||||
}
|
||||
|
||||
typedef basic_string_view<char> string_view;
|
||||
typedef basic_string_view<char16_t> u16string_view;
|
||||
typedef basic_string_view<char32_t> u32string_view;
|
||||
typedef basic_string_view<wchar_t> wstring_view;
|
||||
|
||||
}
|
||||
namespace std {
|
||||
|
||||
/*
|
||||
// [string.view.hash]
|
||||
// Shamelessly stolen from <string>
|
||||
template<class _CharT, class _Traits>
|
||||
struct hash<std::experimental::basic_string_view<_CharT, _Traits> >
|
||||
: public unary_function<std::experimental::basic_string_view<_CharT, _Traits>, size_t>
|
||||
{
|
||||
size_t operator()(const std::experimental::basic_string_view<_CharT, _Traits>& __val) const noexcept;
|
||||
};
|
||||
|
||||
template<class _CharT, class _Traits>
|
||||
size_t
|
||||
hash<std::experimental::basic_string_view<_CharT, _Traits> >::operator()(
|
||||
const std::experimental::basic_string_view<_CharT, _Traits>& __val) const noexcept
|
||||
{
|
||||
return __do_string_hash(__val.data(), __val.data() + __val.size());
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
template <class _CharT, class _Traits>
|
||||
__quoted_output_proxy<_CharT, const _CharT *, _Traits>
|
||||
quoted ( std::experimental::basic_string_view <_CharT, _Traits> __sv,
|
||||
_CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\'))
|
||||
{
|
||||
return __quoted_output_proxy<_CharT, const _CharT *, _Traits>
|
||||
( __sv.data(), __sv.data() + __sv.size(), __delim, __escape );
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_STRVIEWCLONE_LFTS_STRING_VIEW
|
|
@ -11,6 +11,10 @@
|
|||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\SilentPatch\Patterns.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\SilentPatch\Timer.cpp" />
|
||||
<ClCompile Include="SilentPatchIII.cpp" />
|
||||
<ClCompile Include="StdAfxIII.cpp">
|
||||
|
@ -21,6 +25,7 @@
|
|||
<ItemGroup>
|
||||
<ClInclude Include="..\SilentPatch\General.h" />
|
||||
<ClInclude Include="..\SilentPatch\MemoryMgr.h" />
|
||||
<ClInclude Include="..\SilentPatch\Patterns.h" />
|
||||
<ClInclude Include="..\SilentPatch\StdAfx.h" />
|
||||
<ClInclude Include="..\SilentPatch\Timer.h" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
<ClCompile Include="StdAfxIII.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\SilentPatch\Patterns.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\SilentPatch\MemoryMgr.h">
|
||||
|
@ -38,5 +41,8 @@
|
|||
<ClInclude Include="..\SilentPatch\StdAfx.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\SilentPatch\Patterns.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -114,6 +114,10 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio
|
|||
</FxCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\SilentPatch\Patterns.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="AudioHardwareSA.cpp" />
|
||||
<ClCompile Include="FLACDecoderSA.cpp" />
|
||||
<ClCompile Include="GeneralSA.cpp" />
|
||||
|
@ -155,6 +159,7 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio
|
|||
<ClInclude Include="..\SilentPatch\FLAC\ordinals.h" />
|
||||
<ClInclude Include="..\SilentPatch\FLAC\stream_decoder.h" />
|
||||
<ClInclude Include="..\SilentPatch\MemoryMgr.h" />
|
||||
<ClInclude Include="..\SilentPatch\Patterns.h" />
|
||||
<ClInclude Include="..\SilentPatch\Timer.h" />
|
||||
<ClInclude Include="AudioHardwareSA.h" />
|
||||
<ClInclude Include="FLACDecoderSA.h" />
|
||||
|
|
|
@ -60,6 +60,9 @@
|
|||
<ClCompile Include="FLACDecoderSA.cpp">
|
||||
<Filter>Source Files\decoders</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\SilentPatch\Patterns.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\SilentPatch\MemoryMgr.h">
|
||||
|
@ -128,6 +131,9 @@
|
|||
<ClInclude Include="FLACDecoderSA.h">
|
||||
<Filter>Source Files\decoders</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\SilentPatch\Patterns.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="Shaders.rc">
|
||||
|
|
|
@ -103,10 +103,15 @@
|
|||
<ItemGroup>
|
||||
<ClInclude Include="..\SilentPatch\General.h" />
|
||||
<ClInclude Include="..\SilentPatch\MemoryMgr.h" />
|
||||
<ClInclude Include="..\SilentPatch\Patterns.h" />
|
||||
<ClInclude Include="..\SilentPatch\StdAfx.h" />
|
||||
<ClInclude Include="..\SilentPatch\Timer.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\SilentPatch\Patterns.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\SilentPatch\Timer.cpp" />
|
||||
<ClCompile Include="SilentPatchVC.cpp" />
|
||||
<ClCompile Include="StdAfxVC.cpp">
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
<ClInclude Include="..\SilentPatch\StdAfx.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\SilentPatch\Patterns.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\SilentPatch\Timer.cpp">
|
||||
|
@ -38,5 +41,8 @@
|
|||
<ClCompile Include="SilentPatchVC.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\SilentPatch\Patterns.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Reference in a new issue