Бранимир Караџић 6 лет назад
Родитель
Сommit
6124940cde
2 измененных файлов с 64 добавлено и 0 удалено
  1. 39 0
      include/bx/inline/string.inl
  2. 25 0
      include/bx/string.h

+ 39 - 0
include/bx/inline/string.inl

@@ -241,4 +241,43 @@ namespace bx
 		return StringView(_str, _start, _len);
 		return StringView(_str, _start, _len);
 	}
 	}
 
 
+	inline LineReader::LineReader(const bx::StringView& _str)
+		: m_str(_str)
+	{
+		reset();
+	}
+
+	inline void LineReader::reset()
+	{
+		m_curr = m_str;
+		m_line = 0;
+	}
+
+	inline StringView LineReader::next()
+	{
+		if (m_curr.getPtr() != m_str.getTerm() )
+		{
+			++m_line;
+
+			StringView curr(m_curr);
+			m_curr = bx::strFindNl(m_curr);
+
+			StringView line(curr.getPtr(), m_curr.getPtr() );
+
+			return strRTrim(line, "\n\r");
+		}
+
+		return m_curr;
+	}
+
+	inline bool LineReader::isDone() const
+	{
+		return m_curr.getPtr() == m_str.getTerm();
+	}
+
+	inline uint32_t LineReader::getLine() const
+	{
+		return m_line;
+	}
+
 } // namespace bx
 } // namespace bx

+ 25 - 0
include/bx/string.h

@@ -321,6 +321,31 @@ namespace bx
 	/// Converts string to 32-bit unsigned integer value.
 	/// Converts string to 32-bit unsigned integer value.
 	bool fromString(uint32_t* _out, const StringView& _str);
 	bool fromString(uint32_t* _out, const StringView& _str);
 
 
+	///
+	class LineReader
+	{
+	public:
+		///
+		LineReader(const bx::StringView& _str);
+
+		///
+		void reset();
+
+		///
+		StringView next();
+
+		///
+		bool isDone() const;
+
+		///
+		uint32_t getLine() const;
+
+	private:
+		const bx::StringView m_str;
+		bx::StringView m_curr;
+		uint32_t m_line;
+	};
+
 } // namespace bx
 } // namespace bx
 
 
 #include "inline/string.inl"
 #include "inline/string.inl"