mirror of
https://github.com/beefytech/Beef.git
synced 2025-07-04 23:36:00 +02:00
Beefy::String changes, lambda hotswap fixes
Changed some string internals related to StringViewsma Added an "incompatible capture" error for lambdas when the captures change
This commit is contained in:
parent
767a3fafd9
commit
2f01cc14dd
25 changed files with 544 additions and 180 deletions
|
@ -483,6 +483,15 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
// template <typename TAltKey>
|
||||
// bool TryAddWith(const TAltKey& key, TKey** keyPtr, TValue** valuePtr)
|
||||
// {
|
||||
// if (!Insert(key, false, keyPtr, valuePtr))
|
||||
// return false;
|
||||
// new (*valuePtr) TValue();
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// Returns uninitialized valuePtr - must use placement new
|
||||
bool TryAddRaw(const TKey& key, TKey** keyPtr, TValue** valuePtr)
|
||||
{
|
||||
|
|
|
@ -157,7 +157,7 @@ public:
|
|||
String mName;
|
||||
|
||||
public:
|
||||
DebugTimeGuard(int maxTicks, const StringImpl& name = "DebugTimeGuard")
|
||||
DebugTimeGuard(int maxTicks, const StringImpl& name = StringImpl::MakeRef("DebugTimeGuard"))
|
||||
{
|
||||
mName = name;
|
||||
mMaxTicks = maxTicks;
|
||||
|
|
|
@ -129,6 +129,16 @@ String Beefy::operator+(const StringImpl& lhs, const StringView& rhs)
|
|||
return str;
|
||||
}
|
||||
|
||||
String Beefy::operator+(const StringImpl& lhs, const char* rhs)
|
||||
{
|
||||
String str;
|
||||
int rhsLen = (int)strlen(rhs);
|
||||
str.Reserve(lhs.mLength + rhsLen + 1);
|
||||
str.Append(lhs);
|
||||
str.Append(rhs, rhsLen);
|
||||
return str;
|
||||
}
|
||||
|
||||
String Beefy::operator+(const StringImpl& lhs, char rhs)
|
||||
{
|
||||
String str;
|
||||
|
@ -138,6 +148,26 @@ String Beefy::operator+(const StringImpl& lhs, char rhs)
|
|||
return str;
|
||||
}
|
||||
|
||||
String Beefy::operator+(const char* lhs, const StringImpl& rhs)
|
||||
{
|
||||
String str;
|
||||
int lhsLen = (int)strlen(lhs);
|
||||
str.Reserve(rhs.mLength + lhsLen + 1);
|
||||
str.Append(lhs, lhsLen);
|
||||
str.Append(rhs);
|
||||
return str;
|
||||
}
|
||||
|
||||
String Beefy::operator+(const char* lhs, const StringView& rhs)
|
||||
{
|
||||
String str;
|
||||
int lhsLen = (int)strlen(lhs);
|
||||
str.Reserve(rhs.mLength + lhsLen + 1);
|
||||
str.Append(lhs, lhsLen);
|
||||
str.Append(rhs);
|
||||
return str;
|
||||
}
|
||||
|
||||
bool Beefy::operator==(const char* lhs, const StringImpl& rhs)
|
||||
{
|
||||
return rhs == lhs;
|
||||
|
@ -363,6 +393,11 @@ intptr StringImpl::CompareOrdinalHelper(const StringImpl & strA, intptr indexA,
|
|||
return CompareOrdinalHelper(strA.GetPtr() + indexA, lengthA, strB.GetPtr() + indexB, lengthB);
|
||||
}
|
||||
|
||||
void StringImpl::Append(const char* appendPtr)
|
||||
{
|
||||
Append(appendPtr, (int)strlen(appendPtr));
|
||||
}
|
||||
|
||||
void StringImpl::Append(const char* appendPtr, intptr length)
|
||||
{
|
||||
intptr newCurrentIndex = mLength + length;
|
||||
|
@ -538,7 +573,7 @@ intptr StringImpl::Compare(const StringImpl & strA, intptr indexA, const StringI
|
|||
return CompareOrdinalHelper(strA, indexA, lengthA, strB, indexB, lengthB);
|
||||
}
|
||||
|
||||
void StringImpl::ReplaceLargerHelper(const StringImpl & find, const StringImpl & replace)
|
||||
void StringImpl::ReplaceLargerHelper(const StringView& find, const StringView& replace)
|
||||
{
|
||||
Array<int> replaceEntries;
|
||||
|
||||
|
@ -546,7 +581,7 @@ void StringImpl::ReplaceLargerHelper(const StringImpl & find, const StringImpl &
|
|||
|
||||
for (int startIdx = 0; startIdx < mLength - find.mLength; startIdx++)
|
||||
{
|
||||
if (EqualsHelper(GetPtr() + startIdx, find.GetPtr(), find.mLength))
|
||||
if (EqualsHelper(GetPtr() + startIdx, find.mPtr, find.mLength))
|
||||
{
|
||||
replaceEntries.Add(startIdx);
|
||||
startIdx += find.mLength - 1;
|
||||
|
@ -561,7 +596,7 @@ void StringImpl::ReplaceLargerHelper(const StringImpl & find, const StringImpl &
|
|||
if (needSize > GetAllocSize())
|
||||
Realloc((int_strsize)needSize);
|
||||
|
||||
auto replacePtr = replace.GetPtr();
|
||||
auto replacePtr = replace.mPtr;
|
||||
auto ptr = GetMutablePtr();
|
||||
|
||||
intptr lastDestStartIdx = destLength;
|
||||
|
@ -585,7 +620,7 @@ void StringImpl::ReplaceLargerHelper(const StringImpl & find, const StringImpl &
|
|||
mLength = (int_strsize)destLength;
|
||||
}
|
||||
|
||||
void StringImpl::Replace(const StringImpl & find, const StringImpl & replace)
|
||||
void StringImpl::Replace(const StringView& find, const StringView & replace)
|
||||
{
|
||||
if (replace.mLength > find.mLength)
|
||||
{
|
||||
|
@ -594,8 +629,8 @@ void StringImpl::Replace(const StringImpl & find, const StringImpl & replace)
|
|||
}
|
||||
|
||||
auto ptr = GetMutablePtr();
|
||||
auto findPtr = find.GetPtr();
|
||||
auto replacePtr = replace.GetPtr();
|
||||
auto findPtr = find.mPtr;
|
||||
auto replacePtr = replace.mPtr;
|
||||
|
||||
int_strsize inIdx = 0;
|
||||
int_strsize outIdx = 0;
|
||||
|
@ -693,7 +728,7 @@ bool StringImpl::HasMultibyteChars()
|
|||
return false;
|
||||
}
|
||||
|
||||
intptr StringImpl::IndexOf(const StringImpl& subStr, bool ignoreCase) const
|
||||
intptr StringImpl::IndexOf(const StringView& subStr, bool ignoreCase) const
|
||||
{
|
||||
for (intptr ofs = 0; ofs <= mLength - subStr.mLength; ofs++)
|
||||
{
|
||||
|
@ -704,15 +739,15 @@ intptr StringImpl::IndexOf(const StringImpl& subStr, bool ignoreCase) const
|
|||
return -1;
|
||||
}
|
||||
|
||||
intptr StringImpl::IndexOf(const StringImpl& subStr, int32 startIdx) const
|
||||
intptr StringImpl::IndexOf(const StringView& subStr, int32 startIdx) const
|
||||
{
|
||||
return IndexOf(subStr, (int64)startIdx);
|
||||
}
|
||||
|
||||
intptr StringImpl::IndexOf(const StringImpl& subStr, int64 startIdx) const
|
||||
intptr StringImpl::IndexOf(const StringView& subStr, int64 startIdx) const
|
||||
{
|
||||
const char* ptr = GetPtr();
|
||||
const char* subStrPtr = subStr.GetPtr();
|
||||
const char* subStrPtr = subStr.mPtr;
|
||||
for (intptr ofs = (intptr)startIdx; ofs <= mLength - subStr.mLength; ofs++)
|
||||
{
|
||||
if (strncmp(ptr + ofs, subStrPtr, subStr.mLength) == 0)
|
||||
|
|
|
@ -33,6 +33,12 @@ public:
|
|||
StringView(const StringImpl& str, int offset);
|
||||
StringView(const StringImpl& str, int offset, int length);
|
||||
|
||||
StringView(const char* ptr)
|
||||
{
|
||||
this->mPtr = ptr;
|
||||
this->mLength = (int)strlen(ptr);
|
||||
}
|
||||
|
||||
StringView(const char* ptr, int length)
|
||||
{
|
||||
this->mPtr = ptr;
|
||||
|
@ -54,6 +60,13 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
StringView& operator=(const char* str)
|
||||
{
|
||||
this->mPtr = str;
|
||||
this->mLength = (int)strlen(str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const StringImpl& strB) const;
|
||||
|
||||
bool operator!=(const StringImpl& strB) const;
|
||||
|
@ -339,6 +352,26 @@ protected:
|
|||
|
||||
|
||||
public:
|
||||
static StringImpl MakeRef(const char* charPtr)
|
||||
{
|
||||
StringImpl str;
|
||||
// This is just a ref - called when we pass a literal to a method (for example)
|
||||
str.mPtr = (char*)charPtr;
|
||||
str.mLength = (int_strsize)strlen(charPtr);
|
||||
str.mAllocSizeAndFlags = str.mLength | StrPtrFlag;
|
||||
return str;
|
||||
}
|
||||
|
||||
static StringImpl MakeRef(const StringView& strView)
|
||||
{
|
||||
StringImpl str;
|
||||
// This is just a ref - called when we pass a literal to a method (for example)
|
||||
str.mPtr = (char*)strView.mPtr;
|
||||
str.mLength = (int_strsize)strView.mLength;
|
||||
str.mAllocSizeAndFlags = str.mLength | StrPtrFlag;
|
||||
return str;
|
||||
}
|
||||
|
||||
StringImpl(const char* charPtr)
|
||||
{
|
||||
// This is just a ref - called when we pass a literal to a method (for example)
|
||||
|
@ -617,6 +650,7 @@ public:
|
|||
static String CreateReference(const StringView& strView);
|
||||
void Reserve(intptr newSize);
|
||||
|
||||
void Append(const char* appendPtr);
|
||||
void Append(const char* appendPtr, intptr length);
|
||||
void Append(const StringView& str);
|
||||
void Append(const StringImpl& str);
|
||||
|
@ -672,22 +706,22 @@ public:
|
|||
return EqualsHelper(a.GetPtr(), b.GetPtr(), a.mLength);
|
||||
}
|
||||
|
||||
bool StartsWith(const StringImpl& b, CompareKind comparisonType = CompareKind_Ordinal) const
|
||||
bool StartsWith(const StringView& b, CompareKind comparisonType = CompareKind_Ordinal) const
|
||||
{
|
||||
if (this->mLength < b.mLength)
|
||||
return false;
|
||||
if (comparisonType == CompareKind_OrdinalIgnoreCase)
|
||||
return EqualsIgnoreCaseHelper(this->GetPtr(), b.GetPtr(), b.mLength);
|
||||
return EqualsHelper(this->GetPtr(), b.GetPtr(), b.mLength);
|
||||
return EqualsIgnoreCaseHelper(this->GetPtr(), b.mPtr, b.mLength);
|
||||
return EqualsHelper(this->GetPtr(), b.mPtr, b.mLength);
|
||||
}
|
||||
|
||||
bool EndsWith(const StringImpl& b, CompareKind comparisonType = CompareKind_Ordinal) const
|
||||
bool EndsWith(const StringView& b, CompareKind comparisonType = CompareKind_Ordinal) const
|
||||
{
|
||||
if (this->mLength < b.mLength)
|
||||
return false;
|
||||
if (comparisonType == CompareKind_OrdinalIgnoreCase)
|
||||
return EqualsIgnoreCaseHelper(this->GetPtr() + this->mLength - b.mLength, b.GetPtr(), b.mLength);
|
||||
return EqualsHelper(this->GetPtr() + this->mLength - b.mLength, b.GetPtr(), b.mLength);
|
||||
return EqualsIgnoreCaseHelper(this->GetPtr() + this->mLength - b.mLength, b.mPtr, b.mLength);
|
||||
return EqualsHelper(this->GetPtr() + this->mLength - b.mLength, b.mPtr, b.mLength);
|
||||
}
|
||||
|
||||
bool StartsWith(char c) const
|
||||
|
@ -704,8 +738,8 @@ public:
|
|||
return GetPtr()[this->mLength - 1] == c;
|
||||
}
|
||||
|
||||
void ReplaceLargerHelper(const StringImpl& find, const StringImpl& replace);
|
||||
void Replace(const StringImpl& find, const StringImpl& replace);
|
||||
void ReplaceLargerHelper(const StringView& find, const StringView& replace);
|
||||
void Replace(const StringView& find, const StringView& replace);
|
||||
void TrimEnd();
|
||||
void TrimStart();
|
||||
void Trim();
|
||||
|
@ -721,9 +755,9 @@ public:
|
|||
}
|
||||
|
||||
bool HasMultibyteChars();
|
||||
intptr IndexOf(const StringImpl& subStr, bool ignoreCase = false) const;
|
||||
intptr IndexOf(const StringImpl& subStr, int32 startIdx) const;
|
||||
intptr IndexOf(const StringImpl& subStr, int64 startIdx) const;
|
||||
intptr IndexOf(const StringView& subStr, bool ignoreCase = false) const;
|
||||
intptr IndexOf(const StringView& subStr, int32 startIdx) const;
|
||||
intptr IndexOf(const StringView& subStr, int64 startIdx) const;
|
||||
intptr IndexOf(char c, intptr startIdx = 0) const;
|
||||
intptr LastIndexOf(char c) const;
|
||||
intptr LastIndexOf(char c, intptr startCheck) const;
|
||||
|
@ -732,8 +766,8 @@ public:
|
|||
{
|
||||
return IndexOf(c) != -1;
|
||||
}
|
||||
|
||||
bool Contains(const StringImpl& str) const
|
||||
|
||||
bool Contains(const StringView& str) const
|
||||
{
|
||||
return IndexOf(str) != -1;
|
||||
}
|
||||
|
@ -909,7 +943,7 @@ public: \
|
|||
using StringImpl::StringImpl; \
|
||||
using StringImpl::operator=; \
|
||||
StringT() { mPtr = NULL; mLength = 0; mAllocSizeAndFlags = 0; } \
|
||||
StringT(const char* str) { Init(str, (int_strsize)strlen(str)); } \
|
||||
explicit StringT(const char* str) { Init(str, (int_strsize)strlen(str)); } \
|
||||
StringT(const std::string& str) { Init(str.c_str(), (int_strsize)str.length()); } \
|
||||
StringT(const StringImpl& str) : StringImpl(str) {} \
|
||||
StringT(StringImpl&& str) : StringImpl(std::move(str)) {} \
|
||||
|
@ -927,7 +961,11 @@ BF_SPECIALIZE_STR(6)
|
|||
|
||||
String operator+(const StringImpl& lhs, const StringImpl& rhs);
|
||||
String operator+(const StringImpl& lhs, const StringView& rhs);
|
||||
String operator+(const StringImpl& lhs, const char* rhs);
|
||||
String operator+(const StringImpl& lhs, char rhs);
|
||||
String operator+(const char* lhs, const StringImpl& rhs);
|
||||
String operator+(const char* lhs, const StringView& rhs);
|
||||
|
||||
bool operator==(const char* lhs, const StringImpl& rhs);
|
||||
bool operator!=(const char* lhs, const StringImpl& rhs);
|
||||
// bool operator==(const StringView& lhs, const StringImpl& rhs);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue