-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFPathStructure.cpp
More file actions
177 lines (174 loc) · 4.18 KB
/
Copy pathFPathStructure.cpp
File metadata and controls
177 lines (174 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include "FPathStructure.h"
enum ECurrentFillingMode
{
World,
Level,
LevelIdx,
Actor,
ActorIdx,
Component,
ComponentIndex
};
bool FPathStructure::TryParse(const FString& Path, FString& ErrorMessage, FPathStructure& Result)
{
FString WorldName;
FString LevelName;
int32 LevelIndexNumber = 0;
FString ActorName;
int32 ActorIndexNumber = 0;
TArray<FString> ComponentNames;
TArray<int32> ComponentIndices;
FString WorldSection, LevelSection, ActorSection, ComponentSection, LevelIndexSection, ActorIndexSection,
ComponentIndexSection;
ECurrentFillingMode CurrentFillingMode = World;
bool SkipNext = false;
for (int32 i = 0; i < Path.Len(); ++i)
{
if (SkipNext)
{
SkipNext = false;
continue;
}
if (Path[i] == '@')
{
WorldName = WorldSection;
CurrentFillingMode = Level;
continue;
}
if (i < Path.Len() - 1 and Path[i] == ':' and Path[i + 1] == '/')
{
LevelName = LevelSection;
int32 LevelIndex = 0;
bool ParseResult = TryParseInt(LevelIndexSection, LevelIndex);
if (!ParseResult)
{
ErrorMessage = FString::Printf(TEXT("Failed to parse level index: %s"), *LevelIndexSection);
return false;
}
LevelIndexNumber = LevelIndex;
CurrentFillingMode = Actor;
SkipNext = true;
continue;
}
if (i < Path.Len() - 1 and Path[i] == '-' and Path[i + 1] == '>')
{
CurrentFillingMode = Component;
SkipNext = true;
continue;
}
if (Path[i] == '[' and CurrentFillingMode == Level)
{
CurrentFillingMode = LevelIdx;
continue;
}
if (Path[i] == ']' and CurrentFillingMode == LevelIdx)
{
CurrentFillingMode = Level;
continue;
}
if (Path[i] == '[' and CurrentFillingMode == Actor)
{
CurrentFillingMode = ActorIdx;
continue;
}
if (Path[i] == ']' and CurrentFillingMode == ActorIdx)
{
ActorName = ActorSection;
int32 ActorIndex = 0;
bool ParseResult = TryParseInt(ActorIndexSection, ActorIndex);
if (!ParseResult)
{
ErrorMessage = FString::Printf(TEXT("Failed to parse actor index: %s"), *ActorIndexSection);
return false;
}
ActorIndexNumber = ActorIndex;
CurrentFillingMode = Actor;
continue;
}
if (Path[i] == '[' and CurrentFillingMode == Component)
{
CurrentFillingMode = ComponentIndex;
continue;
}
if (Path[i] == ']' and CurrentFillingMode == ComponentIndex)
{
CurrentFillingMode = Component;
continue;
}
if (Path[i] == '/' and CurrentFillingMode == Component)
{
ComponentNames.Add(ComponentSection);
int32 ComponentIndex = 0;
bool ParseResult = TryParseInt(ComponentIndexSection, ComponentIndex);
if (!ParseResult)
{
ErrorMessage = FString::Printf(TEXT("Failed to parse component index: %s"), *ComponentIndexSection);
return false;
}
ComponentIndices.Add(ComponentIndex);
ComponentSection = "";
ComponentIndexSection = "";
continue;
}
if (CurrentFillingMode == World)
{
WorldSection += Path[i];
}
if (CurrentFillingMode == Level)
{
LevelSection += Path[i];
}
if (CurrentFillingMode == Actor)
{
ActorSection += Path[i];
}
if (CurrentFillingMode == Component)
{
ComponentSection += Path[i];
}
if (CurrentFillingMode == LevelIdx)
{
LevelIndexSection += Path[i];
}
if (CurrentFillingMode == ActorIdx)
{
ActorIndexSection += Path[i];
}
if (CurrentFillingMode == ComponentIndex)
{
ComponentIndexSection += Path[i];
}
}
if (WorldName.IsEmpty() or LevelName.IsEmpty() or ActorName.IsEmpty())
{
ErrorMessage = TEXT("Missing required path components");
return false;
}
if (ComponentNames.Num() != ComponentIndices.Num())
{
ErrorMessage = TEXT("Component names and indices must be the same length");
return false;
}
Result.WorldName = WorldName;
Result.LevelName = LevelName;
Result.LevelIndex = LevelIndexNumber;
Result.ActorName = ActorName;
Result.ActorIndex = ActorIndexNumber;
Result.ComponentNames = ComponentNames;
Result.ComponentIndices = ComponentIndices;
return true;
}
bool FPathStructure::TryParseInt(const FString& NumberString, int32& Result)
{
Result = 0;
for (int32 i = 0; i < NumberString.Len(); ++i)
{
if (NumberString[i] < '0' or NumberString[i] > '9')
{
return false;
}
Result *= 10;
Result += NumberString[i] - '0';
}
return true;
}