mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-14 14:24:10 +02:00
Cleanup, fixing error when last line is not newline-terminated
This commit is contained in:
parent
7dbfd15292
commit
d0de2cca64
1 changed files with 10 additions and 189 deletions
|
@ -82,10 +82,7 @@ namespace Beefy.utils
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
//if (mIsOpen)
|
mStructuredData.Close();
|
||||||
{
|
|
||||||
mStructuredData.Close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result<StringView> GetNext() mut
|
public Result<StringView> GetNext() mut
|
||||||
|
@ -283,24 +280,6 @@ namespace Beefy.utils
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public Values Current
|
|
||||||
{
|
|
||||||
get { return mCurrent; }
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*protected override void GCMarkMembers()
|
|
||||||
{
|
|
||||||
// We do this because these containers are held in the bump allocator so they don't get marked
|
|
||||||
GC.Mark(mKeys.[Friend]mItems);
|
|
||||||
GC.Mark(mNextValues.[Friend]mItems);
|
|
||||||
GC.Mark(mNextKeys.[Friend]mItems);
|
|
||||||
if (mMap != null)
|
|
||||||
{
|
|
||||||
GC.Mark(mMap.[Friend]mBuckets);
|
|
||||||
GC.Mark(mMap.[Friend]mEntries);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
static int32 sIdx;
|
static int32 sIdx;
|
||||||
int32 mIdx = sIdx++;
|
int32 mIdx = sIdx++;
|
||||||
public void ToLeakString(String str)
|
public void ToLeakString(String str)
|
||||||
|
@ -319,19 +298,6 @@ namespace Beefy.utils
|
||||||
|
|
||||||
let namedValues = (NamedValues)current;
|
let namedValues = (NamedValues)current;
|
||||||
|
|
||||||
/*if (mMap != null)
|
|
||||||
return mMap.TryGetValue(name, out value);
|
|
||||||
|
|
||||||
if (mKeys.Count > 32)
|
|
||||||
{
|
|
||||||
mMap = new Dictionary<String, Object>();
|
|
||||||
|
|
||||||
// Only create a map for large lists
|
|
||||||
for (int32 i = 0; i < mKeys.Count; i++)
|
|
||||||
mMap[mKeys[i]] = mValues[i];
|
|
||||||
return mMap.TryGetValue(name, out value);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
int32 checkKey = namedValues.mKeyIdx;
|
int32 checkKey = namedValues.mKeyIdx;
|
||||||
int32 checkValue = namedValues.mValueIdx;
|
int32 checkValue = namedValues.mValueIdx;
|
||||||
while (checkKey != -1)
|
while (checkKey != -1)
|
||||||
|
@ -364,19 +330,6 @@ namespace Beefy.utils
|
||||||
|
|
||||||
namedValues = (NamedValues)current;
|
namedValues = (NamedValues)current;
|
||||||
|
|
||||||
/*if (mMap != null)
|
|
||||||
return mMap.TryGetValue(name, out value);
|
|
||||||
|
|
||||||
if (mKeys.Count > 32)
|
|
||||||
{
|
|
||||||
mMap = new Dictionary<String, Object>();
|
|
||||||
|
|
||||||
// Only create a map for large lists
|
|
||||||
for (int32 i = 0; i < mKeys.Count; i++)
|
|
||||||
mMap[mKeys[i]] = mValues[i];
|
|
||||||
return mMap.TryGetValue(name, out value);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
int32 checkKey = namedValues.mKeyIdx;
|
int32 checkKey = namedValues.mKeyIdx;
|
||||||
int32 checkValue = namedValues.mValueIdx;
|
int32 checkValue = namedValues.mValueIdx;
|
||||||
while (checkKey != -1)
|
while (checkKey != -1)
|
||||||
|
@ -481,12 +434,6 @@ namespace Beefy.utils
|
||||||
|
|
||||||
public Object GetCurrent()
|
public Object GetCurrent()
|
||||||
{
|
{
|
||||||
/*int32 checkValue = mCurrent.mValues.mValueIdx;
|
|
||||||
for (int i < idx)
|
|
||||||
{
|
|
||||||
checkValue = mNextValues[checkValue];
|
|
||||||
}
|
|
||||||
return mValues[checkValue];*/
|
|
||||||
if (mCurrent.mLastValue == -1)
|
if (mCurrent.mLastValue == -1)
|
||||||
return null;
|
return null;
|
||||||
return mValues[mCurrent.mLastValue];
|
return mValues[mCurrent.mLastValue];
|
||||||
|
@ -919,22 +866,6 @@ namespace Beefy.utils
|
||||||
return enumerator;
|
return enumerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*IEnumerator IEnumerable.GetEnumerator()
|
|
||||||
{
|
|
||||||
return new Enumerator(this);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*public Enumerator GetEnumerator()
|
|
||||||
{
|
|
||||||
return Enumerator(this, mCurrent.mValues);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*public IEnumerable<StructuredData> GetValues(String name)
|
|
||||||
{
|
|
||||||
Open(name);
|
|
||||||
return this;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
IDisposable GetDisposeProxy()
|
IDisposable GetDisposeProxy()
|
||||||
{
|
{
|
||||||
if (mStructuredDisposeProxy == null)
|
if (mStructuredDisposeProxy == null)
|
||||||
|
@ -946,62 +877,15 @@ namespace Beefy.utils
|
||||||
return mStructuredDisposeProxy;
|
return mStructuredDisposeProxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IDisposable Open(int index)
|
/*public IDisposable Open(int index)
|
||||||
{
|
{
|
||||||
ThrowUnimplemented();
|
ThrowUnimplemented();
|
||||||
|
|
||||||
/*if (mStructuredDisposeProxy == null)
|
|
||||||
{
|
|
||||||
mStructuredDisposeProxy = new DisposeProxy();
|
|
||||||
mStructuredDisposeProxy.mDisposeProxyDelegate = new => Close;
|
|
||||||
}
|
|
||||||
|
|
||||||
mOpenStack.Add(mCurrent);
|
|
||||||
|
|
||||||
Object val = Get(index);
|
|
||||||
if (let values = val as Values)
|
|
||||||
{
|
|
||||||
mCurrent = CurrentEntry(values);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (mEmptyData == null)
|
|
||||||
{
|
|
||||||
mEmptyData = new NamedValues();
|
|
||||||
}
|
|
||||||
mCurrent = CurrentEntry(mEmptyData);
|
|
||||||
}
|
|
||||||
|
|
||||||
return mStructuredDisposeProxy;*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IDisposable Open(Enumerator enumerator)
|
public IDisposable Open(Enumerator enumerator)
|
||||||
{
|
{
|
||||||
ThrowUnimplemented();
|
ThrowUnimplemented();
|
||||||
/*if (mStructuredDisposeProxy == null)
|
}*/
|
||||||
{
|
|
||||||
mStructuredDisposeProxy = new DisposeProxy();
|
|
||||||
mStructuredDisposeProxy.mDisposeProxyDelegate = new => Close;
|
|
||||||
}
|
|
||||||
|
|
||||||
mOpenStack.Add(mCurrent);
|
|
||||||
|
|
||||||
Object val = mValues[enumerator.[Friend]mValueIdx];
|
|
||||||
if (let values = val as Values)
|
|
||||||
{
|
|
||||||
mCurrent = CurrentEntry(values);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (mEmptyData == null)
|
|
||||||
{
|
|
||||||
mEmptyData = new NamedValues();
|
|
||||||
}
|
|
||||||
mCurrent = CurrentEntry(mEmptyData);
|
|
||||||
}
|
|
||||||
|
|
||||||
return mStructuredDisposeProxy;*/
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CreateNew()
|
public void CreateNew()
|
||||||
{
|
{
|
||||||
|
@ -1023,7 +907,6 @@ namespace Beefy.utils
|
||||||
|
|
||||||
public IDisposable CreateObject(bool forceInline = false)
|
public IDisposable CreateObject(bool forceInline = false)
|
||||||
{
|
{
|
||||||
//NamedValues values = new:mBumpAllocator NamedValues();
|
|
||||||
NamedValues values;
|
NamedValues values;
|
||||||
if (forceInline)
|
if (forceInline)
|
||||||
values = new:mBumpAllocator InlineNamedValues();
|
values = new:mBumpAllocator InlineNamedValues();
|
||||||
|
@ -1038,8 +921,6 @@ namespace Beefy.utils
|
||||||
|
|
||||||
public IDisposable CreateArray(String name, bool forceInline = false)
|
public IDisposable CreateArray(String name, bool forceInline = false)
|
||||||
{
|
{
|
||||||
//Values values = new:mBumpAllocator Values();
|
|
||||||
|
|
||||||
Values values;
|
Values values;
|
||||||
if (forceInline)
|
if (forceInline)
|
||||||
values = new:mBumpAllocator InlineValues();
|
values = new:mBumpAllocator InlineValues();
|
||||||
|
@ -1066,11 +947,6 @@ namespace Beefy.utils
|
||||||
return GetDisposeProxy();
|
return GetDisposeProxy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ForceInline()
|
|
||||||
{
|
|
||||||
//mCurrent.mValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void StringEncode(String outString, StringView theString)
|
static void StringEncode(String outString, StringView theString)
|
||||||
{
|
{
|
||||||
outString.Append('"');
|
outString.Append('"');
|
||||||
|
@ -1387,9 +1263,7 @@ namespace Beefy.utils
|
||||||
|
|
||||||
public void ToJSON(String str, bool humanReadable = false)
|
public void ToJSON(String str, bool humanReadable = false)
|
||||||
{
|
{
|
||||||
//String aStringBuilder = new String();
|
|
||||||
ToJSONHelper(mCurrent.mValues, str, humanReadable, "");
|
ToJSONHelper(mCurrent.mValues, str, humanReadable, "");
|
||||||
//return aStringBuilder.ToString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ToTOML(String outStr)
|
public void ToTOML(String outStr)
|
||||||
|
@ -1656,10 +1530,7 @@ namespace Beefy.utils
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//String aStringBuilder = new String();
|
|
||||||
|
|
||||||
EncodeValues(mCurrent.mValues);
|
EncodeValues(mCurrent.mValues);
|
||||||
//return aStringBuilder.ToString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ToString(String str)
|
public override void ToString(String str)
|
||||||
|
@ -1687,12 +1558,7 @@ namespace Beefy.utils
|
||||||
bool keyHadSlash = false;
|
bool keyHadSlash = false;
|
||||||
|
|
||||||
bool returningValues = false;
|
bool returningValues = false;
|
||||||
/*defer
|
|
||||||
{
|
|
||||||
if (!returningValues)
|
|
||||||
delete values;
|
|
||||||
};*/
|
|
||||||
|
|
||||||
int length = string.Length;
|
int length = string.Length;
|
||||||
char8* cPtr = string.Ptr;
|
char8* cPtr = string.Ptr;
|
||||||
for (int32 char8Idx = idx; char8Idx < length; char8Idx++)
|
for (int32 char8Idx = idx; char8Idx < length; char8Idx++)
|
||||||
|
@ -1727,7 +1593,6 @@ namespace Beefy.utils
|
||||||
{
|
{
|
||||||
if ((valueStartIdx != -1) && (valueHadWhitespace))
|
if ((valueStartIdx != -1) && (valueHadWhitespace))
|
||||||
return .Err(.FormatError(lineNum));
|
return .Err(.FormatError(lineNum));
|
||||||
//Runtime.FatalError("Preceding comma expected");
|
|
||||||
|
|
||||||
valueStartIdx = char8Idx;
|
valueStartIdx = char8Idx;
|
||||||
inQuote = true;
|
inQuote = true;
|
||||||
|
@ -1764,7 +1629,6 @@ namespace Beefy.utils
|
||||||
{
|
{
|
||||||
if (values != null)
|
if (values != null)
|
||||||
{
|
{
|
||||||
//valueData = ETry!(LoadJSONHelper(theString, ref char8Idx, ref lineNum));
|
|
||||||
var result = LoadJSONHelper(string, ref char8Idx, ref lineNum);
|
var result = LoadJSONHelper(string, ref char8Idx, ref lineNum);
|
||||||
if (result case .Err(var err))
|
if (result case .Err(var err))
|
||||||
return .Err(err);
|
return .Err(err);
|
||||||
|
@ -1825,11 +1689,6 @@ namespace Beefy.utils
|
||||||
return .Err(Error.FormatError(lineNum));
|
return .Err(Error.FormatError(lineNum));
|
||||||
aValue = valueData;
|
aValue = valueData;
|
||||||
valueData = null;
|
valueData = null;
|
||||||
|
|
||||||
//WTF was this?
|
|
||||||
/*Values values = aValue as StructuredDataa;
|
|
||||||
if (valueStructuredData != null)
|
|
||||||
valueStructuredData.mParent = values;*/
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1838,9 +1697,6 @@ namespace Beefy.utils
|
||||||
|
|
||||||
if (cPtr[valueStartIdx] == '"')
|
if (cPtr[valueStartIdx] == '"')
|
||||||
{
|
{
|
||||||
//String str = new:mBumpAllocator String();
|
|
||||||
//theString.Substring(valueStartIdx + 1, valueEndIdx - valueStartIdx - 1, str);
|
|
||||||
|
|
||||||
if (hadSlash)
|
if (hadSlash)
|
||||||
{
|
{
|
||||||
String str = new:mBumpAllocator String(string, valueStartIdx + 1, valueEndIdx - valueStartIdx - 1);
|
String str = new:mBumpAllocator String(string, valueStartIdx + 1, valueEndIdx - valueStartIdx - 1);
|
||||||
|
@ -1854,12 +1710,8 @@ namespace Beefy.utils
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//String str = scope String(string, valueStartIdx, valueEndIdx - valueStartIdx + 1);
|
|
||||||
|
|
||||||
StringView strView = StringView(string, valueStartIdx, valueEndIdx - valueStartIdx + 1);
|
StringView strView = StringView(string, valueStartIdx, valueEndIdx - valueStartIdx + 1);
|
||||||
|
|
||||||
//string.Substring(valueStartIdx, valueEndIdx - valueStartIdx + 1, str);
|
|
||||||
|
|
||||||
char8 lastC = strView.Ptr[strView.Length - 1];
|
char8 lastC = strView.Ptr[strView.Length - 1];
|
||||||
switch (lastC)
|
switch (lastC)
|
||||||
{
|
{
|
||||||
|
@ -1887,13 +1739,7 @@ namespace Beefy.utils
|
||||||
aValue = new:mBumpAllocator box intVal;
|
aValue = new:mBumpAllocator box intVal;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//TODO: Is temporary
|
return .Err(Error.ParseError);
|
||||||
/*if (str.StartsWith("Int@"))
|
|
||||||
aValue = new:mBumpAllocator box (int)0;
|
|
||||||
else if (str.StartsWith("Double@"))
|
|
||||||
aValue = new:mBumpAllocator box 0.0f;
|
|
||||||
else*/
|
|
||||||
return .Err(Error.ParseError);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1904,8 +1750,7 @@ namespace Beefy.utils
|
||||||
{
|
{
|
||||||
if (keyStartIdx != -1)
|
if (keyStartIdx != -1)
|
||||||
return .Err(Error.KeyInArray);
|
return .Err(Error.KeyInArray);
|
||||||
//DoAdd(ref currentEntry, aValue);
|
|
||||||
|
|
||||||
int valueIdx = mValues.Count;
|
int valueIdx = mValues.Count;
|
||||||
if (currentEntry.mLastValue != -1)
|
if (currentEntry.mLastValue != -1)
|
||||||
mNextValues[currentEntry.mLastValue] = (int32)valueIdx;
|
mNextValues[currentEntry.mLastValue] = (int32)valueIdx;
|
||||||
|
@ -1968,14 +1813,11 @@ namespace Beefy.utils
|
||||||
if (atEnd)
|
if (atEnd)
|
||||||
{
|
{
|
||||||
idx = char8Idx;
|
idx = char8Idx;
|
||||||
//values.mCanWrite = false;
|
|
||||||
returningValues = true;
|
returningValues = true;
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (values != null)
|
|
||||||
//values.mCanWrite = false;
|
|
||||||
returningValues = true;
|
returningValues = true;
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
@ -2253,14 +2095,9 @@ namespace Beefy.utils
|
||||||
|
|
||||||
switch (nextC)
|
switch (nextC)
|
||||||
{
|
{
|
||||||
case 0: fallthrough;
|
case 0:
|
||||||
case ' ': fallthrough;
|
break ValueStrLoop;
|
||||||
case '\t': fallthrough;
|
case ' ', '\t', '\r', '\n', ',', ']', '}':
|
||||||
case '\r': fallthrough;
|
|
||||||
case '\n': fallthrough;
|
|
||||||
case ',': fallthrough;
|
|
||||||
case ']': fallthrough;
|
|
||||||
case '}':
|
|
||||||
idx--;
|
idx--;
|
||||||
break ValueStrLoop;
|
break ValueStrLoop;
|
||||||
}
|
}
|
||||||
|
@ -2359,16 +2196,6 @@ namespace Beefy.utils
|
||||||
|
|
||||||
bool isArray = outerIsArray && !hasMoreParts;
|
bool isArray = outerIsArray && !hasMoreParts;
|
||||||
|
|
||||||
/*if (loadSection.IsArray)
|
|
||||||
{
|
|
||||||
if (hasMoreParts)
|
|
||||||
{
|
|
||||||
if (loadSection.mSectionList.Count == 0)
|
|
||||||
return .Err(.FormatError);
|
|
||||||
loadSection = loadSection.mSectionList.Back;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
String* keyPtr;
|
String* keyPtr;
|
||||||
LoadSection* valuePtr;
|
LoadSection* valuePtr;
|
||||||
if (loadSection.mSectionDict.TryAdd(entryName, out keyPtr, out valuePtr))
|
if (loadSection.mSectionDict.TryAdd(entryName, out keyPtr, out valuePtr))
|
||||||
|
@ -2422,12 +2249,8 @@ namespace Beefy.utils
|
||||||
loadSection.mSectionList.Add(newSection);
|
loadSection.mSectionList.Add(newSection);
|
||||||
DoAdd(ref loadSection.mCurrentEntry, newSection.mCurrentEntry.mValues);
|
DoAdd(ref loadSection.mCurrentEntry, newSection.mCurrentEntry.mValues);
|
||||||
loadSection = newSection;
|
loadSection = newSection;
|
||||||
//currentEntry = loadSection.mCurrentEntry;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//currentEntry = loadSection.mCurrentEntry;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (hasMoreParts)
|
if (hasMoreParts)
|
||||||
{
|
{
|
||||||
|
@ -2509,7 +2332,6 @@ namespace Beefy.utils
|
||||||
|
|
||||||
if (var values = objResult as Values)
|
if (var values = objResult as Values)
|
||||||
{
|
{
|
||||||
//mCurrent = CurrentEntry(values);
|
|
||||||
int valIdx = mValues.Count;
|
int valIdx = mValues.Count;
|
||||||
|
|
||||||
mHeadValues = new:mBumpAllocator Values();
|
mHeadValues = new:mBumpAllocator Values();
|
||||||
|
@ -2523,7 +2345,6 @@ namespace Beefy.utils
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//delete obj;
|
|
||||||
return .Err(Error.FormatError(aLineNum));
|
return .Err(Error.FormatError(aLineNum));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue