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-r26
Browse files Browse the repository at this point in the history
  • Loading branch information
ufna committed Jun 14, 2019
2 parents 37e3c0a + 081f154 commit f050212
Show file tree
Hide file tree
Showing 12 changed files with 274 additions and 27 deletions.
Binary file modified Resources/Icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified SCREENSHOT.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion Source/.clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ BreakConstructorInitializersBeforeComma: true
ColumnLimit: 0
PointerAlignment: Left
SpacesInAngles: false
...
---
Language: ObjC
...
5 changes: 5 additions & 0 deletions Source/VaRestEditorPlugin/Private/VaRest_BreakJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,12 @@ void UVaRest_MakeJson::CreateProjectionPins(UEdGraphPin* Source)
UEdGraphNode::FCreatePinParams InputPinParams;
InputPinParams.ContainerType = (*it).bIsArray ? EPinContainerType::Array : EPinContainerType::None;
UEdGraphPin* InputPin = CreatePin(EGPD_Input, Type, TEXT(""), Subtype, FName(*(*it).Name), InputPinParams);

#if ENGINE_MINOR_VERSION >= 20
InputPin->SetSavePinIfOrphaned(false);
#else
InputPin->bSavePinIfOrphaned = false;
#endif
}
}

Expand Down
12 changes: 12 additions & 0 deletions Source/VaRestPlugin/Classes/VaRestJsonObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,21 @@ class VARESTPLUGIN_API UVaRestJsonObject : public UObject
/** Deserialize byte stream from reader */
void DecodeFromArchive(TUniquePtr<FArchive>& Reader);

//////////////////////////////////////////////////////////////////////////
// Serialize

public:
/** Save json to file */
bool WriteToFile(const FString& Path);

/**
* Blueprint Save json to filepath
*
* @param bIsRelativeToProjectDir If set to 'false' path is treated as absolute
*/
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
bool WriteToFilePath(const FString& Path, const bool bIsRelativeToProjectDir = true);

static bool WriteStringToArchive(FArchive& Ar, const TCHAR* StrPtr, int64 Len);

//////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions Source/VaRestPlugin/Classes/VaRestLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ class VARESTPLUGIN_API UVaRestLibrary : public UBlueprintFunctionLibrary
public:
/**
* Load JSON from formatted text file
* @param Path File name relative to the Content folder
* @param bIsRelativeToContentDir if set to 'false' path is treated as absolute
*/
UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (WorldContext = "WorldContextObject"))
static class UVaRestJsonObject* LoadJsonFromFile(UObject* WorldContextObject, const FString& Path);
static class UVaRestJsonObject* LoadJsonFromFile(UObject* WorldContextObject, const FString& Path, const bool bIsRelativeToContentDir = true);

//////////////////////////////////////////////////////////////////////////
// Easy URL processing
Expand Down
34 changes: 15 additions & 19 deletions Source/VaRestPlugin/Private/VaRestJsonObject.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// Copyright 2014 Vladimir Alyamkin. All Rights Reserved.

#include "VaRestJsonObject.h"

#include "VaRestJsonParser.h"
#include "VaRestJsonValue.h"
#include "VaRestPluginPrivatePCH.h"

#include "Runtime/Launch/Resources/Version.h"

typedef TJsonWriterFactory<TCHAR, TCondensedJsonPrintPolicy<TCHAR>> FCondensedJsonStringWriterFactory;
typedef TJsonWriter<TCHAR, TCondensedJsonPrintPolicy<TCHAR>> FCondensedJsonStringWriter;

Expand Down Expand Up @@ -543,28 +546,14 @@ int32 UVaRestJsonObject::DeserializeFromUTF8Bytes(const ANSICHAR* Bytes, int32 S
{
FJSONReader Reader;

#if ENGINE_MINOR_VERSION >= 19
// Get destLen
int32 DestinationLength = FUTF8ToTCHAR_Convert::ConvertedLength(Bytes, Size);
TCHAR* DestinationBuffer = new TCHAR[DestinationLength];

// CONVERT to TCHAR string
FUTF8ToTCHAR_Convert::Convert(DestinationBuffer, DestinationLength, Bytes, Size);

int32 i = 0;
while (i < DestinationLength)
{
if (!Reader.Read(DestinationBuffer[i++]))
{
break;
}
}
#else
const ANSICHAR* EndByte = Bytes + Size;
while (Bytes < EndByte)
{
#if ENGINE_MINOR_VERSION >= 19
TCHAR Char = FUtf8Helper::CodepointFromUtf8(Bytes, EndByte - Bytes);
#else
TCHAR Char = FUTF8ToTCHAR_Convert::utf8codepoint(&Bytes);

#endif
if (Char > 0xFFFF)
{
Char = UNICODE_BOGUS_CHAR_CODEPOINT;
Expand All @@ -575,7 +564,6 @@ int32 UVaRestJsonObject::DeserializeFromUTF8Bytes(const ANSICHAR* Bytes, int32 S
break;
}
}
#endif

SetRootObject(Reader.State.Root);
return Reader.State.Size;
Expand Down Expand Up @@ -657,6 +645,9 @@ void UVaRestJsonObject::DecodeFromArchive(TUniquePtr<FArchive>& Reader)
}
}

//////////////////////////////////////////////////////////////////////////
// Serialize

bool UVaRestJsonObject::WriteToFile(const FString& Path)
{
TUniquePtr<FArchive> FileWriter(IFileManager::Get().CreateFileWriter(*Path));
Expand Down Expand Up @@ -710,6 +701,11 @@ bool UVaRestJsonObject::WriteToFile(const FString& Path)
return true;
}

bool UVaRestJsonObject::WriteToFilePath(const FString& Path, const bool bIsRelativeToProjectDir)
{
return WriteToFile(bIsRelativeToProjectDir ? FPaths::ProjectDir() / Path : Path);
}

bool UVaRestJsonObject::WriteStringToArchive(FArchive& Ar, const TCHAR* StrPtr, int64 Len)
{
auto Src = StringCast<UCS2CHAR>(StrPtr, Len);
Expand Down
230 changes: 229 additions & 1 deletion Source/VaRestPlugin/Private/VaRestJsonParser.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,238 @@
// Copyright 2015-2019 Mail.Ru Group. All Rights Reserved.

#include "VaRestJsonParser.h"

#include "VaRestJsonObject.h"

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

uint32 FUtf8Helper::CodepointFromUtf8(const ANSICHAR*& SourceString, const uint32 SourceLengthRemaining)
{
checkSlow(SourceLengthRemaining > 0);

const ANSICHAR* OctetPtr = SourceString;

uint32 Codepoint = 0;
uint32 Octet = (uint32)((uint8)*SourceString);
uint32 Octet2, Octet3, Octet4;

if (Octet < 128) // one octet char: 0 to 127
{
++SourceString; // skip to next possible start of codepoint.
return Octet;
}
else if (Octet < 192) // bad (starts with 10xxxxxx).
{
// Apparently each of these is supposed to be flagged as a bogus
// char, instead of just resyncing to the next valid codepoint.
++SourceString; // skip to next possible start of codepoint.
return UNICODE_BOGUS_CHAR_CODEPOINT;
}
else if (Octet < 224) // two octets
{
// Ensure our string has enough characters to read from
if (SourceLengthRemaining < 2)
{
// Skip to end and write out a single char (we always have room for at least 1 char)
SourceString += SourceLengthRemaining;
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

Octet -= (128 + 64);
Octet2 = (uint32)((uint8) * (++OctetPtr));
if ((Octet2 & (128 + 64)) != 128) // Format isn't 10xxxxxx?
{
++SourceString; // Sequence was not valid UTF-8. Skip the first byte and continue.
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

Codepoint = ((Octet << 6) | (Octet2 - 128));
if ((Codepoint >= 0x80) && (Codepoint <= 0x7FF))
{
SourceString += 2; // skip to next possible start of codepoint.
return Codepoint;
}
}
else if (Octet < 240) // three octets
{
// Ensure our string has enough characters to read from
if (SourceLengthRemaining < 3)
{
// Skip to end and write out a single char (we always have room for at least 1 char)
SourceString += SourceLengthRemaining;
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

Octet -= (128 + 64 + 32);
Octet2 = (uint32)((uint8) * (++OctetPtr));
if ((Octet2 & (128 + 64)) != 128) // Format isn't 10xxxxxx?
{
++SourceString; // Sequence was not valid UTF-8. Skip the first byte and continue.
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

Octet3 = (uint32)((uint8) * (++OctetPtr));
if ((Octet3 & (128 + 64)) != 128) // Format isn't 10xxxxxx?
{
++SourceString; // Sequence was not valid UTF-8. Skip the first byte and continue.
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

Codepoint = (((Octet << 12)) | ((Octet2 - 128) << 6) | ((Octet3 - 128)));

// UTF-8 characters cannot be in the UTF-16 surrogates range
if (UE4StringConv_Private::IsHighSurrogate(Codepoint) || UE4StringConv_Private::IsLowSurrogate(Codepoint))
{
++SourceString; // Sequence was not valid UTF-8. Skip the first byte and continue.
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

// 0xFFFE and 0xFFFF are illegal, too, so we check them at the edge.
if ((Codepoint >= 0x800) && (Codepoint <= 0xFFFD))
{
SourceString += 3; // skip to next possible start of codepoint.
return Codepoint;
}
}
else if (Octet < 248) // four octets
{
// Ensure our string has enough characters to read from
if (SourceLengthRemaining < 4)
{
// Skip to end and write out a single char (we always have room for at least 1 char)
SourceString += SourceLengthRemaining;
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

Octet -= (128 + 64 + 32 + 16);
Octet2 = (uint32)((uint8) * (++OctetPtr));
if ((Octet2 & (128 + 64)) != 128) // Format isn't 10xxxxxx?
{
++SourceString; // Sequence was not valid UTF-8. Skip the first byte and continue.
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

Octet3 = (uint32)((uint8) * (++OctetPtr));
if ((Octet3 & (128 + 64)) != 128) // Format isn't 10xxxxxx?
{
++SourceString; // Sequence was not valid UTF-8. Skip the first byte and continue.
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

Octet4 = (uint32)((uint8) * (++OctetPtr));
if ((Octet4 & (128 + 64)) != 128) // Format isn't 10xxxxxx?
{
++SourceString; // Sequence was not valid UTF-8. Skip the first byte and continue.
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

Codepoint = (((Octet << 18)) | ((Octet2 - 128) << 12) |
((Octet3 - 128) << 6) | ((Octet4 - 128)));
if ((Codepoint >= 0x10000) && (Codepoint <= 0x10FFFF))
{
SourceString += 4; // skip to next possible start of codepoint.
return Codepoint;
}
}
// Five and six octet sequences became illegal in rfc3629.
// We throw the codepoint away, but parse them to make sure we move
// ahead the right number of bytes and don't overflow the buffer.
else if (Octet < 252) // five octets
{
// Ensure our string has enough characters to read from
if (SourceLengthRemaining < 5)
{
// Skip to end and write out a single char (we always have room for at least 1 char)
SourceString += SourceLengthRemaining;
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

Octet = (uint32)((uint8) * (++OctetPtr));
if ((Octet & (128 + 64)) != 128) // Format isn't 10xxxxxx?
{
++SourceString; // Sequence was not valid UTF-8. Skip the first byte and continue.
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

Octet = (uint32)((uint8) * (++OctetPtr));
if ((Octet & (128 + 64)) != 128) // Format isn't 10xxxxxx?
{
++SourceString; // Sequence was not valid UTF-8. Skip the first byte and continue.
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

Octet = (uint32)((uint8) * (++OctetPtr));
if ((Octet & (128 + 64)) != 128) // Format isn't 10xxxxxx?
{
++SourceString; // Sequence was not valid UTF-8. Skip the first byte and continue.
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

Octet = (uint32)((uint8) * (++OctetPtr));
if ((Octet & (128 + 64)) != 128) // Format isn't 10xxxxxx?
{
++SourceString; // Sequence was not valid UTF-8. Skip the first byte and continue.
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

SourceString += 5; // skip to next possible start of codepoint.
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

else // six octets
{
// Ensure our string has enough characters to read from
if (SourceLengthRemaining < 6)
{
// Skip to end and write out a single char (we always have room for at least 1 char)
SourceString += SourceLengthRemaining;
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

Octet = (uint32)((uint8) * (++OctetPtr));
if ((Octet & (128 + 64)) != 128) // Format isn't 10xxxxxx?
{
++SourceString; // Sequence was not valid UTF-8. Skip the first byte and continue.
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

Octet = (uint32)((uint8) * (++OctetPtr));
if ((Octet & (128 + 64)) != 128) // Format isn't 10xxxxxx?
{
++SourceString; // Sequence was not valid UTF-8. Skip the first byte and continue.
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

Octet = (uint32)((uint8) * (++OctetPtr));
if ((Octet & (128 + 64)) != 128) // Format isn't 10xxxxxx?
{
++SourceString; // Sequence was not valid UTF-8. Skip the first byte and continue.
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

Octet = (uint32)((uint8) * (++OctetPtr));
if ((Octet & (128 + 64)) != 128) // Format isn't 10xxxxxx?
{
++SourceString; // Sequence was not valid UTF-8. Skip the first byte and continue.
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

Octet = (uint32)((uint8) * (++OctetPtr));
if ((Octet & (128 + 64)) != 128) // Format isn't 10xxxxxx?
{
++SourceString; // Sequence was not valid UTF-8. Skip the first byte and continue.
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

SourceString += 6; // skip to next possible start of codepoint.
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

++SourceString; // Sequence was not valid UTF-8. Skip the first byte and continue.
return UNICODE_BOGUS_CHAR_CODEPOINT; // catch everything else.
}

FJSONState::FJSONState()
: Notation(EJSONNotation::NONE)
Expand Down
6 changes: 6 additions & 0 deletions Source/VaRestPlugin/Private/VaRestJsonParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

#include "Json.h"

struct FUtf8Helper
{
/** @See FUTF8ToTCHAR_Convert::CodepointFromUtf8 */
static uint32 CodepointFromUtf8(const ANSICHAR*& SourceString, const uint32 SourceLengthRemaining);
};

class FJsonValueNonConstArray : public FJsonValueArray
{
public:
Expand Down
Loading

0 comments on commit f050212

Please sign in to comment.