OSDN Git Service

UniFile.*: Add ReadStringAll(), GetBase() and GetFileSize() function
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Wed, 5 May 2021 13:35:46 +0000 (22:35 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Wed, 5 May 2021 13:35:46 +0000 (22:35 +0900)
Src/Common/UniFile.cpp
Src/Common/UniFile.h

index 54dd053..9fbd377 100644 (file)
@@ -331,6 +331,24 @@ bool UniMemFile::ReadString(String & line, bool * lossy)
        return ReadString(line, eol, lossy);
 }
 
+bool UniMemFile::ReadStringAll(String& text)
+{
+       text.clear();
+       bool lossy = false, lossytmp = false;
+       text.reserve(m_filesize);
+       bool last = false;
+       do
+       {
+               String tmp, eol;
+               last = ReadString(tmp, eol, &lossytmp);
+               text += tmp;
+               text += eol;
+               if (lossytmp)
+                       lossy = true;
+       } while (last);
+       return lossy;
+}
+
 /**
  * @brief Append characters to string.
  * This function appends characters to the string. The storage for the string
@@ -814,6 +832,12 @@ bool UniStdioFile::ReadString(String & line, String & eol, bool * lossy)
        return false;
 }
 
+bool UniStdioFile::ReadStringAll(String & line)
+{
+       assert(false); // unimplemented -- currently cannot read from a UniStdioFile!
+       return false;
+}
+
 /** @brief Write BOM (byte order mark) if Unicode file */
 int UniStdioFile::WriteBom()
 {
index a049bf4..f37a165 100644 (file)
@@ -53,6 +53,7 @@ public:
 public:
        virtual bool ReadString(String & line, bool * lossy) = 0;
        virtual bool ReadString(String & line, String & eol, bool * lossy) = 0;
+       virtual bool ReadStringAll(String & line) = 0;
        virtual int GetLineNumber() const = 0;
        virtual int64_t GetPosition() const = 0;
        virtual bool WriteString(const String & line) = 0;
@@ -138,6 +139,7 @@ public:
 
        virtual int GetLineNumber() const override { return m_lineno; }
        virtual const txtstats & GetTxtStats() const override { return m_txtstats; }
+       virtual int64_t GetFileSize() const{ return m_filesize; }
 
        bool IsUnicode() override;
 
@@ -192,8 +194,10 @@ public:
 public:
        virtual bool ReadString(String & line, bool * lossy) override;
        virtual bool ReadString(String & line, String & eol, bool * lossy) override;
+       virtual bool ReadStringAll(String & line) override;
        virtual int64_t GetPosition() const override { return m_current - m_base; }
        virtual bool WriteString(const String & line) override;
+       unsigned char* GetBase() const { return m_base; }
 
 // Implementation methods
 protected:
@@ -262,6 +266,7 @@ public:
 protected:
        virtual bool ReadString(String & line, bool * lossy) override;
        virtual bool ReadString(String & line, String & eol, bool * lossy) override;
+       virtual bool ReadStringAll(String & line) override;
 
 public:
        virtual int64_t GetPosition() const override;