Branimir Karadžić 8 سال پیش
والد
کامیت
148bdc60fa
5فایلهای تغییر یافته به همراه32 افزوده شده و 30 حذف شده
  1. 9 15
      include/bx/inline/string.inl
  2. 8 8
      include/bx/string.h
  3. 14 0
      src/dtoa.cpp
  4. 0 6
      src/string.cpp
  5. 1 1
      tests/string_test.cpp

+ 9 - 15
include/bx/inline/string.inl

@@ -147,26 +147,20 @@ namespace bx
 	inline StringT<AllocatorT>::StringT(const StringT<AllocatorT>& _rhs)
 		: StringView()
 	{
-		set(_rhs.m_ptr, _rhs.m_len);
+		set(_rhs);
 	}
 
 	template<bx::AllocatorI** AllocatorT>
 	inline StringT<AllocatorT>& StringT<AllocatorT>::operator=(const StringT<AllocatorT>& _rhs)
 	{
-		set(_rhs.m_ptr, _rhs.m_len);
+		set(_rhs);
 		return *this;
 	}
 
-	template<bx::AllocatorI** AllocatorT>
-	inline StringT<AllocatorT>::StringT(const char* _ptr, int32_t _len)
-	{
-		set(_ptr, _len);
-	}
-
 	template<bx::AllocatorI** AllocatorT>
 	inline StringT<AllocatorT>::StringT(const StringView& _rhs)
 	{
-		set(_rhs.getPtr(), _rhs.getLength() );
+		set(_rhs);
 	}
 
 	template<bx::AllocatorI** AllocatorT>
@@ -176,22 +170,22 @@ namespace bx
 	}
 
 	template<bx::AllocatorI** AllocatorT>
-	inline void StringT<AllocatorT>::set(const char* _ptr, int32_t _len)
+	inline void StringT<AllocatorT>::set(const StringView& _str)
 	{
 		clear();
-		append(_ptr, _len);
+		append(_str);
 	}
 
 	template<bx::AllocatorI** AllocatorT>
-	inline void StringT<AllocatorT>::append(const char* _ptr, int32_t _len)
+	inline void StringT<AllocatorT>::append(const StringView& _str)
 	{
-		if (0 != _len)
+		if (0 != _str.getLength() )
 		{
 			int32_t old = m_len;
-			int32_t len = m_len + strLen(_ptr, _len);
+			int32_t len = m_len + strLen(_str);
 			char* ptr = (char*)BX_REALLOC(*AllocatorT, 0 != m_len ? const_cast<char*>(m_ptr) : NULL, len+1);
 			m_len = len;
-			strCopy(ptr + old, len-old+1, _ptr, _len);
+			strCopy(ptr + old, len-old+1, _str);
 
 			*const_cast<char**>(&m_ptr) = ptr;
 		}

+ 8 - 8
include/bx/string.h

@@ -84,9 +84,6 @@ namespace bx
 		///
 		StringT<AllocatorT>& operator=(const StringT<AllocatorT>& _rhs);
 
-		///
-		StringT(const char* _ptr, int32_t _len = INT32_MAX);
-
 		///
 		StringT(const StringView& _rhs);
 
@@ -94,10 +91,10 @@ namespace bx
 		~StringT();
 
 		///
-		void set(const char* _ptr, int32_t _len = INT32_MAX);
+		void set(const StringView& _str);
 
 		///
-		void append(const char* _ptr, int32_t _len = INT32_MAX);
+		void append(const StringView& _str);
 
 		///
 		void clear();
@@ -163,9 +160,6 @@ namespace bx
 	///
 	void toUpper(char* _inOutStr, int32_t _max = INT32_MAX);
 
-	///
-	bool toBool(const char* _str);
-
 	/// String compare.
 	int32_t strCmp(const StringView& _lhs, const StringView& _rhs, int32_t _max = INT32_MAX);
 
@@ -267,6 +261,9 @@ namespace bx
 	/// Convert size in bytes to human readable string kibi units.
 	int32_t prettify(char* _out, int32_t _count, uint64_t _value, Units::Enum _units = Units::Kibi);
 
+	///
+	int32_t toString(char* _out, int32_t _max, bool _value);
+
 	///
 	int32_t toString(char* _out, int32_t _max, double _value);
 
@@ -282,6 +279,9 @@ namespace bx
 	///
 	int32_t toString(char* _out, int32_t _max, uint64_t _value, uint32_t _base = 10);
 
+	///
+	bool fromString(bool* _out, const StringView& _str);
+
 	///
 	bool fromString(float* _out, const StringView& _str);
 

+ 14 - 0
src/dtoa.cpp

@@ -1043,6 +1043,20 @@ namespace bx
 		return hd.d;
 	}
 
+	int32_t toString(char* _out, int32_t _max, bool _value)
+	{
+		StringView str(_value ? "true" : "false");
+		strCopy(_out, _max, str);
+		return str.getLength();
+	}
+
+	bool fromString(bool* _out, const StringView& _str)
+	{
+		char ch = toLower(_str.getPtr()[0]);
+		*_out = ch == 't' ||  ch == '1';
+		return 0 != _str.getLength();
+	}
+
 	bool fromString(float* _out, const StringView& _str)
 	{
 		double dbl;

+ 0 - 6
src/string.cpp

@@ -153,12 +153,6 @@ namespace bx
 		toUpperUnsafe(_inOutStr, len);
 	}
 
-	bool toBool(const char* _str)
-	{
-		char ch = toLower(_str[0]);
-		return ch == 't' ||  ch == '1';
-	}
-
 	typedef char (*CharFn)(char _ch);
 
 	inline char toNoop(char _ch)

+ 1 - 1
tests/string_test.cpp

@@ -352,7 +352,7 @@ TEST_CASE("StringView", "")
 	st.append("test");
 	REQUIRE(8 == st.getLength() );
 
-	st.append("test", 2);
+	st.append(bx::StringView("test", 2) );
 	REQUIRE(10 == st.getLength() );
 
 	REQUIRE(0 == bx::strCmp(st.getPtr(), "testtestte") );