Browse Source

Reworked how Jupiter::File reads

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

98
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)))
{
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));
int chr;
for (;;)
while (true)
{
c = fgetc(file);
if (c == EOF)
return true;
if (containsSymbol(ENDL, static_cast<char>(c)))
chr = fgetc(file);
if (chr == EOF)
{
if (buffer.isNotEmpty())
{
Jupiter::File::data_->lines.add(new Jupiter::StringS(buffer));
return true;
}
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.truncate(buffer.size());
c = fgetc(file);
if (c == EOF)
buffer.erase();
// check for optional trailing \n
chr = fgetc(file);
switch (chr)
{
case EOF:
return true;
if (containsSymbol(ENDL, static_cast<char>(c)) == false)
buffer.concat(static_cast<char>(c));
case '\r':
goto new_line_r;
case '\n':
continue;
default:
buffer += static_cast<char>(chr);
}
continue;
}
else
buffer.concat(static_cast<char>(c));
}
return true;
if (static_cast<char>(chr) == '\n') // new line
{
new_line_n:
Jupiter::File::data_->lines.add(new Jupiter::StringS(buffer));
buffer.erase();
// check for optional trailing \r
chr = fgetc(file);
switch (chr)
{
case EOF:
return true;
case '\n':
goto new_line_n;
case '\r':
continue;
default:
buffer += static_cast<char>(chr);
}
continue;
}
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