MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / ReadAllText

Method ReadAllText

Source/Engine/Platform/Base/FileBase.cpp:95–176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

93}
94
95bool FileBase::ReadAllText(const StringView& path, String& data)
96{
97 PROFILE_CPU_NAMED("File::ReadAllText");
98 ZoneText(*path, path.Length());
99 data.Clear();
100
101 // Read data
102 Array<byte> bytes;
103 if (ReadAllBytes(path, bytes))
104 return true;
105
106 // Check for empty data
107 if (bytes.IsEmpty())
108 return false;
109
110 // Add null terminator char
111 int32 count = bytes.Count();
112 bytes.Add('\0');
113
114 // Check BOM char
115 // TODO: maybe let's check whole BOM????
116 switch (bytes[0])
117 {
118 case 0xEF: // UTF-8
119 {
120 // BOM: EF BB BF
121
122 // Eat BOM
123 count -= 3;
124 if (count < 0)
125 {
126 // Invalid data
127 return true;
128 }
129
130 // Convert to UTF-16
131 int32 utf16Length;
132 Char* utf16Data = StringUtils::ConvertUTF82UTF16(reinterpret_cast<char*>(bytes.Get()), count, utf16Length);
133 data.Set(utf16Data, utf16Length);
134 Allocator::Free(utf16Data);
135 }
136 break;
137 case 0xFE: // UTF-16 (BE)
138 {
139 // BOM: FE FF
140
141 // Eat BOM
142 count -= 2;
143 if (count < 0)
144 {
145 // Invalid data
146 return true;
147 }
148
149 data = (Char*)bytes.Get();
150 }
151 break;
152 case 0xFF: // UTF-16 (LE)

Callers 15

LoadMethod · 0.80
CreateModuleMethod · 0.80
RemoveModuleMethod · 0.80
CreateMethod · 0.80
CreateMethod · 0.80
CreateMethod · 0.80
CreateMethod · 0.80
CreateScriptMethod · 0.80
FindNewKeysMethod · 0.80
LoadMethod · 0.80
GetProjectGuidMethod · 0.80
GenerateAsciiSolutionMethod · 0.80

Calls 9

ReserveSpaceMethod · 0.80
FreeFunction · 0.50
LengthMethod · 0.45
ClearMethod · 0.45
IsEmptyMethod · 0.45
CountMethod · 0.45
AddMethod · 0.45
GetMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected