diff options
author | Alexis211 <alexis211@gmail.com> | 2009-09-20 12:35:43 +0200 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-09-20 12:35:43 +0200 |
commit | a43236e7017b6500e6563aa8654c8d8f56226615 (patch) | |
tree | bacaaf9af1171c6ea5de0a8ea7b30301a105c6f0 | |
parent | 0d5f4201217272f93d608be86e644d58f181725a (diff) | |
download | Melon-a43236e7017b6500e6563aa8654c8d8f56226615.tar.gz Melon-a43236e7017b6500e6563aa8654c8d8f56226615.zip |
Oops... TextFile.class.* wasn't included in previous commit...
-rw-r--r-- | Source/Kernel/VFS/TextFile.class.cpp | 21 | ||||
-rw-r--r-- | Source/Kernel/VFS/TextFile.class.h | 21 |
2 files changed, 42 insertions, 0 deletions
diff --git a/Source/Kernel/VFS/TextFile.class.cpp b/Source/Kernel/VFS/TextFile.class.cpp new file mode 100644 index 0000000..a877392 --- /dev/null +++ b/Source/Kernel/VFS/TextFile.class.cpp @@ -0,0 +1,21 @@ +#include "TextFile.class.h" + +bool TextFile::write(String str, bool addnl) { + ByteArray a(str, m_encoding); + if (addnl) a += (u8int)'\n'; + return File::write(a); +} + +String TextFile::readLine(char separator) { + ByteArray buffer; + while (1) { + char c; + if (read(1, (u8int*)&c) == 0) { + return buffer.toString(m_encoding); + } + if (c == separator) { + return buffer.toString(m_encoding); + } + buffer += (u8int)c; + } +} diff --git a/Source/Kernel/VFS/TextFile.class.h b/Source/Kernel/VFS/TextFile.class.h new file mode 100644 index 0000000..a0cd505 --- /dev/null +++ b/Source/Kernel/VFS/TextFile.class.h @@ -0,0 +1,21 @@ +#ifndef DEF_TEXTFILE_CLASS_H +#define DEF_TEXTFILE_CLASS_H + +#include <VFS/File.class.h> + +class TextFile : public File { + private: + u8int m_encoding; + + public: + TextFile(u8int encoding = UE_UTF8) : File() { m_encoding = encoding; } + TextFile(String filename, u8int mode = FM_READ, FSNode* start = 0, u8int encoding = UE_UTF8) + : File(filename, mode, start) { m_encoding = encoding; } + ~TextFile() {} + + void setEncoding(u8int encoding = UE_UTF8) { m_encoding = encoding; } + bool write(String str, bool addnl = false); // Addnl = wether or not to add \n at end + String readLine(char separator = '\n'); +}; + +#endif |