Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Finish v1.1-r32
Browse files Browse the repository at this point in the history
  • Loading branch information
ufna committed Jan 18, 2021
2 parents dd70965 + ed4195f commit a284dfd
Show file tree
Hide file tree
Showing 20 changed files with 331 additions and 95 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![statusIcon](https://teamcity.ufna.dev/app/rest/builds/buildType:(id:UfnaDev_VaRest_ClangFormatCheck)/statusIcon.svg)](https://teamcity.ufna.dev/viewType.html?buildTypeId=UfnaDev_VaRest_ClangFormatCheck&guest=1)
[![statusIcon](https://teamcity.ufna.dev/app/rest/builds/buildType:(id:UfnaDev_VaRest_BuildPlugin)/statusIcon.svg)](https://teamcity.ufna.dev/viewType.html?buildTypeId=UfnaDev_VaRest_BuildPlugin&guest=1)
![GitHub](https://img.shields.io/github/license/ufna/VaRest)
![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/ufna/VaRest?include_prereleases)

Expand All @@ -16,7 +16,7 @@ Key features:

Check the [Wiki](http://bit.ly/VaRest-Docs) for plugin usage examples and installation notes.

Current version: **1.1 R 30** (UE 4.25)
Current version: **1.1 R 32** (UE 4.26)

![SCREENSHOT](SCREENSHOT.jpg)

Expand All @@ -26,5 +26,5 @@ Legal info

Unreal® is a trademark or registered trademark of Epic Games, Inc. in the United States of America and elsewhere.

Unreal® Engine, Copyright 1998 – 2018, Epic Games, Inc. All rights reserved.
Unreal® Engine, Copyright 1998 – 2021, Epic Games, Inc. All rights reserved.

4 changes: 3 additions & 1 deletion Source/VaRest/Private/VaRest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#include "VaRest.h"

#include "VaRestDefines.h"
#include "VaRestLibrary.h"
#include "VaRestSettings.h"

#include "Developer/Settings/Public/ISettingsModule.h"
#include "UObject/Package.h"

#define LOCTEXT_NAMESPACE "FVaRestModule"

Expand All @@ -23,7 +25,7 @@ void FVaRestModule::StartupModule()
ModuleSettings);
}

UE_LOG(LogVaRest, Log, TEXT("%s: VaRest module started"), *VA_FUNC_LINE);
UE_LOG(LogVaRest, Log, TEXT("%s: VaRest (%s) module started"), *VA_FUNC_LINE, *UVaRestLibrary::GetVaRestVersion());
}

void FVaRestModule::ShutdownModule()
Expand Down
57 changes: 39 additions & 18 deletions Source/VaRest/Private/VaRestJsonObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void UVaRestJsonObject::SetRootObject(const TSharedPtr<FJsonObject>& JsonObject)
FString UVaRestJsonObject::EncodeJson() const
{
FString OutputString;
auto Writer = TJsonWriterFactory<>::Create(&OutputString);
const auto Writer = TJsonWriterFactory<>::Create(&OutputString);
FJsonSerializer::Serialize(JsonObj, Writer);

return OutputString;
Expand All @@ -55,7 +55,7 @@ FString UVaRestJsonObject::EncodeJson() const
FString UVaRestJsonObject::EncodeJsonToSingleString() const
{
FString OutputString;
auto Writer = FCondensedJsonStringWriterFactory::Create(&OutputString);
const auto Writer = FCondensedJsonStringWriterFactory::Create(&OutputString);
FJsonSerializer::Serialize(JsonObj, Writer);

return OutputString;
Expand All @@ -65,7 +65,7 @@ bool UVaRestJsonObject::DecodeJson(const FString& JsonString, bool bUseIncrement
{
if (bUseIncrementalParser)
{
int32 BytesRead = DeserializeFromTCHARBytes(JsonString.GetCharArray().GetData(), JsonString.Len());
const int32 BytesRead = DeserializeFromTCHARBytes(JsonString.GetCharArray().GetData(), JsonString.Len());

// JsonObj is always valid, but read bytes is zero when something went wrong
if (BytesRead > 0)
Expand All @@ -75,7 +75,7 @@ bool UVaRestJsonObject::DecodeJson(const FString& JsonString, bool bUseIncrement
}
else
{
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(*JsonString);
const TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(*JsonString);
TSharedPtr<FJsonObject> OutJsonObj;
if (FJsonSerializer::Deserialize(Reader, OutJsonObj))
{
Expand Down Expand Up @@ -197,6 +197,27 @@ void UVaRestJsonObject::SetIntegerField(const FString& FieldName, int32 Number)
JsonObj->SetNumberField(FieldName, Number);
}

int64 UVaRestJsonObject::GetInt64Field(const FString& FieldName) const
{
if (!JsonObj->HasTypedField<EJson::Number>(FieldName))
{
UE_LOG(LogVaRest, Warning, TEXT("No field with name %s of type Number"), *FieldName);
return 0;
}

return static_cast<int64>(JsonObj->GetNumberField(FieldName));
}

void UVaRestJsonObject::SetInt64Field(const FString& FieldName, int64 Number)
{
if (FieldName.IsEmpty())
{
return;
}

JsonObj->SetNumberField(FieldName, Number);
}

FString UVaRestJsonObject::GetStringField(const FString& FieldName) const
{
if (!JsonObj->HasTypedField<EJson::String>(FieldName))
Expand Down Expand Up @@ -277,7 +298,7 @@ void UVaRestJsonObject::SetArrayField(const FString& FieldName, const TArray<UVa
// Process input array and COPY original values
for (auto InVal : InArray)
{
TSharedPtr<FJsonValue> JsonVal = InVal->GetRootValue();
const TSharedPtr<FJsonValue> JsonVal = InVal->GetRootValue();

switch (InVal->GetType())
{
Expand Down Expand Up @@ -344,7 +365,7 @@ UVaRestJsonObject* UVaRestJsonObject::GetObjectField(const FString& FieldName) c
return nullptr;
}

TSharedPtr<FJsonObject> JsonObjField = JsonObj->GetObjectField(FieldName);
const TSharedPtr<FJsonObject> JsonObjField = JsonObj->GetObjectField(FieldName);

UVaRestJsonObject* OutRestJsonObj = NewObject<UVaRestJsonObject>();
OutRestJsonObj->SetRootObject(JsonObjField);
Expand Down Expand Up @@ -402,10 +423,10 @@ TArray<float> UVaRestJsonObject::GetNumberArrayField(const FString& FieldName) c
return NumberArray;
}

TArray<TSharedPtr<FJsonValue>> JsonArrayValues = JsonObj->GetArrayField(FieldName);
const TArray<TSharedPtr<FJsonValue>> JsonArrayValues = JsonObj->GetArrayField(FieldName);
for (TArray<TSharedPtr<FJsonValue>>::TConstIterator It(JsonArrayValues); It; ++It)
{
auto Value = (*It).Get();
const auto Value = (*It).Get();
if (Value->Type != EJson::Number)
{
UE_LOG(LogVaRest, Error, TEXT("Not Number element in array with field name %s"), *FieldName);
Expand Down Expand Up @@ -443,10 +464,10 @@ TArray<FString> UVaRestJsonObject::GetStringArrayField(const FString& FieldName)
return StringArray;
}

TArray<TSharedPtr<FJsonValue>> JsonArrayValues = JsonObj->GetArrayField(FieldName);
const TArray<TSharedPtr<FJsonValue>> JsonArrayValues = JsonObj->GetArrayField(FieldName);
for (TArray<TSharedPtr<FJsonValue>>::TConstIterator It(JsonArrayValues); It; ++It)
{
auto Value = (*It).Get();
const auto Value = (*It).Get();
if (Value->Type != EJson::String)
{
UE_LOG(LogVaRest, Error, TEXT("Not String element in array with field name %s"), *FieldName);
Expand Down Expand Up @@ -483,10 +504,10 @@ TArray<bool> UVaRestJsonObject::GetBoolArrayField(const FString& FieldName) cons
return BoolArray;
}

TArray<TSharedPtr<FJsonValue>> JsonArrayValues = JsonObj->GetArrayField(FieldName);
const TArray<TSharedPtr<FJsonValue>> JsonArrayValues = JsonObj->GetArrayField(FieldName);
for (TArray<TSharedPtr<FJsonValue>>::TConstIterator It(JsonArrayValues); It; ++It)
{
auto Value = (*It).Get();
const auto Value = (*It).Get();
if (Value->Type != EJson::Boolean)
{
UE_LOG(LogVaRest, Error, TEXT("Not Boolean element in array with field name %s"), *FieldName);
Expand Down Expand Up @@ -524,7 +545,7 @@ TArray<UVaRestJsonObject*> UVaRestJsonObject::GetObjectArrayField(const FString&
}

TArray<TSharedPtr<FJsonValue>> ValArray = JsonObj->GetArrayField(FieldName);
for (auto Value : ValArray)
for (const auto& Value : ValArray)
{
if (Value->Type != EJson::Object)
{
Expand Down Expand Up @@ -643,11 +664,11 @@ void UVaRestJsonObject::DecodeFromArchive(TUniquePtr<FArchive>& Reader)

if (bIsIntelByteOrder)
{
Char = CharCast<TCHAR>((UCS2CHAR)((uint16)SymbolBytes[0] + (uint16)SymbolBytes[1] * 256));
Char = CharCast<TCHAR>(static_cast<UCS2CHAR>(static_cast<uint16>(SymbolBytes[0]) + static_cast<uint16>(SymbolBytes[1]) * 256));
}
else
{
Char = CharCast<TCHAR>((UCS2CHAR)((uint16)SymbolBytes[1] + (uint16)SymbolBytes[0] * 256));
Char = CharCast<TCHAR>(static_cast<UCS2CHAR>(static_cast<uint16>(SymbolBytes[1]) + static_cast<uint16>(SymbolBytes[0]) * 256));
}

if (!JsonReader.Read(Char))
Expand All @@ -667,7 +688,7 @@ void UVaRestJsonObject::DecodeFromArchive(TUniquePtr<FArchive>& Reader)
//////////////////////////////////////////////////////////////////////////
// Serialize

bool UVaRestJsonObject::WriteToFile(const FString& Path)
bool UVaRestJsonObject::WriteToFile(const FString& Path) const
{
TUniquePtr<FArchive> FileWriter(IFileManager::Get().CreateFileWriter(*Path));
if (!FileWriter)
Expand Down Expand Up @@ -723,8 +744,8 @@ bool UVaRestJsonObject::WriteToFilePath(const FString& Path, const bool bIsRelat

bool UVaRestJsonObject::WriteStringToArchive(FArchive& Ar, const TCHAR* StrPtr, int64 Len)
{
auto Src = StringCast<UCS2CHAR>(StrPtr, Len);
Ar.Serialize((UCS2CHAR*)Src.Get(), Src.Length() * sizeof(UCS2CHAR));
const auto Src = StringCast<UCS2CHAR>(StrPtr, Len);
Ar.Serialize(const_cast<UCS2CHAR*>(Src.Get()), Src.Length() * sizeof(UCS2CHAR));

return true;
}
27 changes: 13 additions & 14 deletions Source/VaRest/Private/VaRestJsonParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include "Dom/JsonObject.h"
#include "Dom/JsonValue.h"
#include "Logging/LogMacros.h"

uint32 FUtf8Helper::CodepointFromUtf8(const ANSICHAR*& SourceString, const uint32 SourceLengthRemaining)
{
Expand Down Expand Up @@ -294,7 +293,7 @@ void FJSONState::PopObject()
{
if (Objects.Num() > 0)
{
auto Object = Objects.Pop(false);
const auto Object = Objects.Pop(false);
if (Object->Type == EJson::Object)
{
return;
Expand All @@ -308,7 +307,7 @@ void FJSONState::PopArray()
{
if (Objects.Num() > 0)
{
auto Object = Objects.Pop(false);
const auto Object = Objects.Pop(false);
if (Object->Type == EJson::Array)
{
return;
Expand All @@ -322,7 +321,7 @@ void FJSONState::PopValue(bool bCheckType)
{
if (Objects.Num() > 0)
{
auto Value = Objects.Last(0);
const auto Value = Objects.Last(0);
if (Value->Type == EJson::Object || Value->Type == EJson::Array)
{
if (bCheckType)
Expand All @@ -339,7 +338,7 @@ void FJSONState::PopValue(bool bCheckType)
{
case EJson::Null:
{
auto LowerCase = Data.ToLower();
const auto LowerCase = Data.ToLower();
if (LowerCase != TEXT("null"))
{
bError = true;
Expand All @@ -356,7 +355,7 @@ void FJSONState::PopValue(bool bCheckType)
}
case EJson::Number:
{
FString LowerCase = Data.ToLower();
const FString LowerCase = Data.ToLower();
int32 ePosition = INDEX_NONE;
LowerCase.FindChar('e', ePosition);
if (ePosition == INDEX_NONE)
Expand All @@ -372,8 +371,8 @@ void FJSONState::PopValue(bool bCheckType)
}
else if (LowerCase.Len() > ePosition + 2)
{
FString Left = LowerCase.Left(ePosition);
FString Rigth = LowerCase.Right(LowerCase.Len() - ePosition - 1);
const FString Left = LowerCase.Left(ePosition);
const FString Rigth = LowerCase.Right(LowerCase.Len() - ePosition - 1);
if (Left.IsNumeric() && Rigth.IsNumeric())
{
((FJsonValueNonConstNumber*)Value.Get())->AsNonConstNumber() = FCString::Atod(*Left) * FMath::Pow(10.f, FCString::Atoi(*Rigth));
Expand All @@ -391,7 +390,7 @@ void FJSONState::PopValue(bool bCheckType)
}
case EJson::Boolean:
{
auto LowerCase = Data.ToLower();
const auto LowerCase = Data.ToLower();
if (LowerCase == TEXT("true"))
{
((FJsonValueNonConstBoolean*)Value.Get())->AsNonConstBool() = true;
Expand All @@ -415,7 +414,7 @@ void FJSONState::PopValue(bool bCheckType)

ClearData();

auto Container = Objects.Last(0);
const auto Container = Objects.Last(0);
if (Container->Type == EJson::Object)
{
if (Key.Len() > 0)
Expand Down Expand Up @@ -502,7 +501,7 @@ TSharedPtr<FJsonValueObject> FJSONState::PushObject(TSharedPtr<FJsonObject> Obje

TSharedPtr<FJsonValueNonConstArray> FJSONState::PushArray()
{
TArray<TSharedPtr<FJsonValue>> Empty;
const TArray<TSharedPtr<FJsonValue>> Empty;
TSharedPtr<FJsonValueNonConstArray> Result(new FJsonValueNonConstArray(Empty));
Objects.Add(Result);
Size += sizeof(TSharedPtr<FJsonValueNonConstArray>) + sizeof(FJsonValueNonConstArray);
Expand Down Expand Up @@ -627,7 +626,7 @@ void FJSONReader::UpdateNotation()
if (State.Key.Len() > 0)
{
State.Notation = EJSONNotation::OBJECT;
auto Value = State.GetObject();
const auto Value = State.GetObject();
if (Value != nullptr)
{
Value->AsObject()->SetField(State.Key, State.PushObject());
Expand Down Expand Up @@ -709,7 +708,7 @@ void FJSONReader::UpdateNotation()
State.Notation = EJSONNotation::ARRAY;
if (State.Key.Len() > 0)
{
auto Value = State.GetObject();
const auto Value = State.GetObject();
if (Value != nullptr)
{
Value->AsObject()->SetField(State.Key, State.PushArray());
Expand Down Expand Up @@ -1100,7 +1099,7 @@ void FJSONWriter::Write(TSharedPtr<FJsonValue> JsonValue, FArchive* Writer, bool
}
default:
{
FString Value = JsonValue->AsString();
const FString Value = JsonValue->AsString();

const TCHAR* BufferPtr = *Value;
for (int i = 0; i < Value.Len(); ++i)
Expand Down
31 changes: 29 additions & 2 deletions Source/VaRest/Private/VaRestJsonValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ UVaRestJsonValue::UVaRestJsonValue(const FObjectInitializer& ObjectInitializer)
{
}

void UVaRestJsonValue::Reset()
{
JsonVal = nullptr;
}

TSharedPtr<FJsonValue>& UVaRestJsonValue::GetRootValue()
{
return JsonVal;
Expand Down Expand Up @@ -111,7 +116,29 @@ float UVaRestJsonValue::AsNumber() const
return 0.f;
}

return JsonVal->AsNumber();
return static_cast<float>(JsonVal->AsNumber());
}

int32 UVaRestJsonValue::AsInt32() const
{
if (!JsonVal.IsValid())
{
ErrorMessage(TEXT("Number"));
return 0.f;
}

return static_cast<int32>(JsonVal->AsNumber());
}

int32 UVaRestJsonValue::AsInt64() const
{
if (!JsonVal.IsValid())
{
ErrorMessage(TEXT("Number"));
return 0.f;
}

return static_cast<int64>(JsonVal->AsNumber());
}

FString UVaRestJsonValue::AsString() const
Expand Down Expand Up @@ -166,7 +193,7 @@ UVaRestJsonObject* UVaRestJsonValue::AsObject()
return nullptr;
}

TSharedPtr<FJsonObject> NewObj = JsonVal->AsObject();
const TSharedPtr<FJsonObject> NewObj = JsonVal->AsObject();

UVaRestJsonObject* JsonObj = NewObject<UVaRestJsonObject>();
JsonObj->SetRootObject(NewObj);
Expand Down
Loading

0 comments on commit a284dfd

Please sign in to comment.