Browse Source

Reworked how Jupiter::File reads

release/0.19
Jessica James 8 years ago
parent
commit
79b53cfe04
  1. 86
      Jupiter/File.cpp
  2. 2
      Jupiter/Jupiter.h
  3. BIN
      Jupiter/Jupiter.rc
  4. BIN
      Release/Jupiter.lib

86
Jupiter/File.cpp

@ -142,42 +142,84 @@ bool Jupiter::File::load(const Jupiter::ReadableString &file)
bool Jupiter::File::load(FILE *file)
{
Jupiter::String buffer(defaultBufferSize);
int c = fgetc(file);
if (c == EOF)
return false;
if (containsSymbol(ENDL, static_cast<char>(c)))
int chr;
while (true)
{
chr = fgetc(file);
if (chr == EOF)
{
if (buffer.isNotEmpty())
{
Jupiter::File::data_->lines.add(new Jupiter::StringS(buffer));
c = fgetc(file);
if (c == EOF)
return true;
if (containsSymbol(ENDL, static_cast<char>(c)) == false)
buffer.concat(static_cast<char>(c));
}
else
buffer.concat(static_cast<char>(c));
for (;;)
return Jupiter::File::data_->lines.size() != 0;
}
if (static_cast<char>(chr) == '\r') // new line
{
new_line_r:
Jupiter::File::data_->lines.add(new Jupiter::StringS(buffer));
buffer.erase();
// check for optional trailing \n
chr = fgetc(file);
switch (chr)
{
c = fgetc(file);
if (c == EOF)
case EOF:
return true;
if (containsSymbol(ENDL, static_cast<char>(c)))
case '\r':
goto new_line_r;
case '\n':
continue;
default:
buffer += static_cast<char>(chr);
}
continue;
}
if (static_cast<char>(chr) == '\n') // new line
{
new_line_n:
Jupiter::File::data_->lines.add(new Jupiter::StringS(buffer));
buffer.truncate(buffer.size());
c = fgetc(file);
if (c == EOF)
buffer.erase();
// check for optional trailing \r
chr = fgetc(file);
switch (chr)
{
case EOF:
return true;
if (containsSymbol(ENDL, static_cast<char>(c)) == false)
buffer.concat(static_cast<char>(c));
case '\n':
goto new_line_n;
case '\r':
continue;
default:
buffer += static_cast<char>(chr);
}
else
buffer.concat(static_cast<char>(c));
continue;
}
return true;
buffer += static_cast<char>(chr);
}
}
void Jupiter::File::unload()

2
Jupiter/Jupiter.h

@ -36,7 +36,7 @@
#define JUPITER_API
#endif // _WIN32
#define JUPITER_VERSION "Jupiter 0.18" /** Version of this program at compile time. */
#define JUPITER_VERSION "Jupiter 0.18.1" /** Version of this program at compile time. */
#if defined __cplusplus
extern "C"

BIN
Jupiter/Jupiter.rc

Binary file not shown.

BIN
Release/Jupiter.lib

Binary file not shown.
Loading…
Cancel
Save