예제 #1
0
   bool data_stream::write_line(const dynamic_string& str)
   {
      if (!str.is_empty())
         return write(str.get_ptr(), str.get_len()) == str.get_len();

      return true;
   }
예제 #2
0
    bool data_stream::read_line(dynamic_string &str)
    {
        str.empty();

        for (;;)
        {
            const int c = read_byte();

            const bool prev_got_cr = m_got_cr;
            m_got_cr = false;

            if (c < 0)
            {
                if (!str.is_empty())
                    break;

                return false;
            }
            // ignores DOS EOF, assumes it's at the very end of the file
            else if ((26 == c) || (!c))
                continue;
            else if (13 == c)
            {
                m_got_cr = true;
                break;
            }
            else if (10 == c)
            {
                if (prev_got_cr)
                    continue;

                break;
            }

            str.append_char(static_cast<char>(c));
        }

        return true;
    }
예제 #3
0
    bool data_stream::read_line(dynamic_string &str)
    {
        str.empty();

        for (;;)
        {
            // Can't be const--need to deal with Mac OS9 style line endings via substition
            const int c = read_byte();

            if (c < 0)
            {
                if (!str.is_empty())
                    break;

                return false;
            }
            // ignores DOS EOF, assumes it's at the very end of the file
            else if ((26 == c) || (!c))
                continue;
            else if (c_CR == c)
            {
                // This path handles OS9 and Windows style line endings.
                // Check to see if the next character is a LF, if so eat that one too.
                if (c_LF == peek_byte()) {
                    read_byte();
                }
                break;
            }
            else if (c_LF == c)
            {
                // UNIX style line endings.
                break;
            }

            str.append_char(static_cast<char>(c));
        }

        return true;
    }