Browse Source

StringView cleanup.

Branimir Karadžić 7 years ago
parent
commit
0af3748629

+ 1 - 1
include/bx/commandline.h

@@ -12,7 +12,7 @@ namespace bx
 {
 	/// Reference:
 	/// http://msdn.microsoft.com/en-us/library/a1y7w461.aspx
-	const char* tokenizeCommandLine(const StringView& _commandLine, char* _buffer, uint32_t& _bufferSize, int32_t& _argc, char* _argv[], int32_t _maxArgvs, char _term = '\0');
+	StringView tokenizeCommandLine(const StringView& _commandLine, char* _buffer, uint32_t& _bufferSize, int32_t& _argc, char* _argv[], int32_t _maxArgvs, char _term = '\0');
 
 	///
 	class CommandLine

+ 4 - 4
include/bx/filepath.h

@@ -85,19 +85,19 @@ namespace bx
 
 		/// If path is `/abv/gd/555/333/pod.mac` returns `/abv/gd/555/333/`.
 		///
-		const StringView getPath() const;
+		StringView getPath() const;
 
 		/// If path is `/abv/gd/555/333/pod.mac` returns `pod.mac`.
 		///
-		const StringView getFileName() const;
+		StringView getFileName() const;
 
 		/// If path is `/abv/gd/555/333/pod.mac` returns `pod`.
 		///
-		const StringView getBaseName() const;
+		StringView getBaseName() const;
 
 		/// If path is `/abv/gd/555/333/pod.mac` returns `.mac`.
 		///
-		const StringView getExt() const;
+		StringView getExt() const;
 
 		/// Returns true if file path is absolute.
 		///

+ 27 - 6
include/bx/inline/string.inl

@@ -75,6 +75,21 @@ namespace bx
 		return *this;
 	}
 
+	inline StringView::StringView(char* _ptr)
+	{
+		set(_ptr, INT32_MAX);
+	}
+
+	inline StringView::StringView(const char* _ptr)
+	{
+		set(_ptr, INT32_MAX);
+	}
+
+	inline StringView::StringView(char* _ptr, int32_t _len)
+	{
+		set(_ptr, _len);
+	}
+
 	inline StringView::StringView(const char* _ptr, int32_t _len)
 	{
 		set(_ptr, _len);
@@ -91,18 +106,24 @@ namespace bx
 		set(_container);
 	}
 
+	inline void StringView::set(char* _ptr)
+	{
+		set(_ptr, INT32_MAX);
+	}
+
+	inline void StringView::set(const char* _ptr)
+	{
+		set(_ptr, INT32_MAX);
+	}
+
 	inline void StringView::set(const char* _ptr, int32_t _len)
 	{
 		clear();
 
 		if (NULL != _ptr)
 		{
-			int32_t len = strLen(_ptr, _len);
-			if (0 != len)
-			{
-				m_len = len;
-				m_ptr = _ptr;
-			}
+			m_len = INT32_MAX == _len ? strLen(_ptr) : _len;
+			m_ptr = _ptr;
 		}
 	}
 

+ 31 - 25
include/bx/string.h

@@ -37,7 +37,16 @@ namespace bx
 		StringView& operator=(const StringView& _rhs);
 
 		///
-		StringView(const char* _ptr, int32_t _len = INT32_MAX);
+		StringView(char* _ptr);
+
+		///
+		StringView(const char* _ptr);
+
+		///
+		StringView(char* _ptr, int32_t _len);
+
+		///
+		StringView(const char* _ptr, int32_t _len);
 
 		///
 		StringView(const char* _ptr, const char* _term);
@@ -47,7 +56,13 @@ namespace bx
 		explicit StringView(const Ty& _container);
 
 		///
-		void set(const char* _ptr, int32_t _len = INT32_MAX);
+		void set(char* _ptr);
+
+		///
+		void set(const char* _ptr);
+
+		///
+		void set(const char* _ptr, int32_t _len);
 
 		///
 		void set(const char* _ptr, const char* _term);
@@ -198,20 +213,26 @@ namespace bx
 	int32_t strCat(char* _dst, int32_t _dstSize, const StringView& _str, int32_t _num = INT32_MAX);
 
 	/// Find character in string. Limit search to _max characters.
-	const char* strFind(const StringView& _str, char _ch);
+	StringView strFind(const StringView& _str, char _ch);
 
 	/// Find character in string in reverse. Limit search to _max characters.
-	const char* strRFind(const StringView& _str, char _ch);
+	StringView strRFind(const StringView& _str, char _ch);
 
 	/// Find substring in string. Limit search to _max characters.
-	const char* strFind(const StringView& _str, const StringView& _find, int32_t _num = INT32_MAX);
+	StringView strFind(const StringView& _str, const StringView& _find, int32_t _num = INT32_MAX);
 
 	/// Find substring in string. Case insensitive. Limit search to _max characters.
-	const char* strFindI(const StringView& _str, const StringView& _find, int32_t _num = INT32_MAX);
+	StringView strFindI(const StringView& _str, const StringView& _find, int32_t _num = INT32_MAX);
 
 	/// Returns string view with characters _chars trimmed from left.
 	StringView strLTrim(const StringView& _str, const StringView& _chars);
 
+	/// Returns string view with whitespace characters trimmed from left.
+	StringView strLTrimSpace(const StringView& _str);
+
+	/// Returns string view with non-whitespace characters trimmed from left.
+	StringView strLTrimNonSpace(const StringView& _str);
+
 	/// Returns string view with characters _chars trimmed from right.
 	StringView strRTrim(const StringView& _str, const StringView& _chars);
 
@@ -219,25 +240,10 @@ namespace bx
 	StringView strTrim(const StringView& _str, const StringView& _chars);
 
 	/// Find new line. Returns pointer after new line terminator.
-	const char* strnl(const char* _str);
-
-	/// Find end of line. Retuns pointer to new line terminator.
-	const char* streol(const char* _str);
+	StringView strFindNl(const StringView& _str);
 
 	/// Find end of line. Retuns pointer to new line terminator.
-	const StringView strFindEol(const StringView& _str);
-
-	/// Skip whitespace.
-	const char* strws(const char* _str);
-
-	/// Skip whitespace.
-	const StringView strSkipSpace(const StringView& _str);
-
-	/// Skip non-whitespace.
-	const char* strnws(const char* _str);
-
-	/// Skip non-whitespace.
-	const StringView strSkipNonSpace(const StringView& _str);
+	StringView strFindEol(const StringView& _str);
 
 	/// Returns pointer to first character after word.
 	const char* strSkipWord(const char* _str, int32_t _max = INT32_MAX);
@@ -252,10 +258,10 @@ namespace bx
 	void eolLF(char* _out, int32_t _size, const char* _str);
 
 	// Finds identifier.
-	const char* findIdentifierMatch(const char* _str, const char* _word);
+	StringView findIdentifierMatch(const StringView& _str, const StringView& _word);
 
 	/// Finds any identifier from NULL terminated array of identifiers.
-	const char* findIdentifierMatch(const char* _str, const char* _words[]);
+	StringView findIdentifierMatch(const StringView& _str, const char** _words);
 
 	/// Cross platform implementation of vsnprintf that returns number of
 	/// characters which would have been written to the final string if

+ 3 - 3
src/commandline.cpp

@@ -12,7 +12,7 @@ namespace bx
 	// Reference:
 	// - https://web.archive.org/web/20180629044234/https://msdn.microsoft.com/en-us/library/a1y7w461.aspx
 	//
-	const char* tokenizeCommandLine(const StringView& _commandLine, char* _buffer, uint32_t& _bufferSize, int32_t& _argc, char* _argv[], int32_t _maxArgvs, char _term)
+	StringView tokenizeCommandLine(const StringView& _commandLine, char* _buffer, uint32_t& _bufferSize, int32_t& _argc, char* _argv[], int32_t _maxArgvs, char _term)
 	{
 		int32_t argc = 0;
 		const char* curr = _commandLine.getPtr();
@@ -66,7 +66,7 @@ namespace bx
 						state = Escape;
 					}
 					else if ('"' == *curr
-						&&  '"' != term)
+					     &&  '"' != term)
 					{
 						sub = !sub;
 					}
@@ -137,7 +137,7 @@ namespace bx
 			++curr;
 		}
 
-		return curr;
+		return StringView(curr, _commandLine.getTerm() );
 	}
 
 	CommandLine::CommandLine(int32_t _argc, char const* const* _argv)

+ 7 - 6
src/dtoa.cpp

@@ -1120,11 +1120,12 @@ namespace bx
 
 	bool fromString(int32_t* _out, const StringView& _str)
 	{
-		const char* str  = _str.getPtr();
-		const char* term = _str.getTerm();
+		StringView str = bx::strLTrimSpace(_str);
 
-		str = strws(str);
-		char ch = *str++;
+		const char* ptr  = str.getPtr();
+		const char* term = str.getTerm();
+
+		char ch = *ptr++;
 		bool neg = false;
 		switch (ch)
 		{
@@ -1133,13 +1134,13 @@ namespace bx
 			break;
 
 		default:
-			--str;
+			--ptr;
 			break;
 		}
 
 		int32_t result = 0;
 
-		for (ch = *str++; isNumeric(ch) && str <= term; ch = *str++)
+		for (ch = *ptr++; isNumeric(ch) && ptr <= term; ch = *ptr++)
 		{
 			result = 10*result - (ch - '0');
 		}

+ 19 - 20
src/filepath.cpp

@@ -336,37 +336,37 @@ namespace bx
 		return m_filePath;
 	}
 
-	const StringView FilePath::getPath() const
+	StringView FilePath::getPath() const
 	{
-		const char* end = strRFind(m_filePath, '/');
-		if (NULL != end)
+		StringView end = strRFind(m_filePath, '/');
+		if (!end.isEmpty() )
 		{
-			return StringView(m_filePath, end+1);
+			return StringView(m_filePath, end.getPtr()+1);
 		}
 
 		return StringView();
 	}
 
-	const StringView FilePath::getFileName() const
+	StringView FilePath::getFileName() const
 	{
-		const char* fileName = strRFind(m_filePath, '/');
-		if (NULL != fileName)
+		StringView fileName = strRFind(m_filePath, '/');
+		if (!fileName.isEmpty() )
 		{
-			return StringView(fileName+1);
+			return StringView(fileName.getPtr()+1);
 		}
 
 		return get();
 	}
 
-	const StringView FilePath::getBaseName() const
+	StringView FilePath::getBaseName() const
 	{
 		const StringView fileName = getFileName();
 		if (!fileName.isEmpty() )
 		{
-			const char* ext = strFind(fileName, '.');
-			if (ext != NULL)
+			StringView ext = strFind(fileName, '.');
+			if (!ext.isEmpty() )
 			{
-				return StringView(fileName.getPtr(), ext);
+				return StringView(fileName.getPtr(), ext.getPtr() );
 			}
 
 			return fileName;
@@ -375,13 +375,12 @@ namespace bx
 		return StringView();
 	}
 
-	const StringView FilePath::getExt() const
+	StringView FilePath::getExt() const
 	{
 		const StringView fileName = getFileName();
 		if (!fileName.isEmpty() )
 		{
-			const char* ext = strFind(fileName, '.');
-			return StringView(ext);
+			return strFind(fileName, '.');
 		}
 
 		return StringView();
@@ -450,13 +449,13 @@ namespace bx
 			return false;
 		}
 
-		const StringView dir = strRTrim(_filePath.get(), "/");
-		const char* slash = strRFind(dir, '/');
+		const StringView dir   = strRTrim(_filePath.get(), "/");
+		const StringView slash = strRFind(dir, '/');
 
-		if (NULL != slash
-		&&  slash - dir.getPtr() > 1)
+		if (!slash.isEmpty()
+		&&  slash.getPtr() - dir.getPtr() > 1)
 		{
-			if (!makeAll(StringView(dir.getPtr(), slash), _err) )
+			if (!makeAll(StringView(dir.getPtr(), slash.getPtr() ), _err) )
 			{
 				return false;
 			}

+ 97 - 105
src/string.cpp

@@ -361,9 +361,15 @@ namespace bx
 		return strFindUnsafe(_str, strLen(_str, _max), _ch);
 	}
 
-	const char* strFind(const StringView& _str, char _ch)
+	StringView strFind(const StringView& _str, char _ch)
 	{
-		return strFind(_str.getPtr(), _str.getLength(), _ch);
+		const char* ptr = strFindUnsafe(_str.getPtr(), _str.getLength(), _ch);
+		if (NULL == ptr)
+		{
+			return StringView(_str.getTerm(), _str.getTerm() );
+		}
+
+		return StringView(ptr, ptr+1);
 	}
 
 	inline const char* strRFindUnsafe(const char* _str, int32_t _len, char _ch)
@@ -379,14 +385,15 @@ namespace bx
 		return NULL;
 	}
 
-	inline const char* strRFind(const char* _str, int32_t _max, char _ch)
+	StringView strRFind(const StringView& _str, char _ch)
 	{
-		return strRFindUnsafe(_str, strLen(_str, _max), _ch);
-	}
+		const char* ptr = strRFindUnsafe(_str.getPtr(), _str.getLength(), _ch);
+		if (NULL == ptr)
+		{
+			return StringView(_str.getTerm(), _str.getTerm() );
+		}
 
-	const char* strRFind(const StringView& _str, char _ch)
-	{
-		return strRFind(_str.getPtr(), _str.getLength(), _ch);
+		return StringView(ptr, ptr+1);
 	}
 
 	template<CharFn fn>
@@ -430,24 +437,42 @@ namespace bx
 		return NULL;
 	}
 
-	const char* strFind(const StringView& _str, const StringView& _find, int32_t _num)
+	StringView strFind(const StringView& _str, const StringView& _find, int32_t _num)
 	{
-		return strFind<toNoop>(
+		int32_t len = min(_find.getLength(), _num);
+
+		const char* ptr = strFind<toNoop>(
 			  _str.getPtr()
 			, _str.getLength()
 			, _find.getPtr()
-			, min(_find.getLength(), _num)
+			, len
 			);
+
+		if (NULL == ptr)
+		{
+			return StringView(_str.getTerm(), _str.getTerm() );
+		}
+
+		return StringView(ptr, len);
 	}
 
-	const char* strFindI(const StringView& _str, const StringView& _find, int32_t _num)
+	StringView strFindI(const StringView& _str, const StringView& _find, int32_t _num)
 	{
-		return strFind<toLower>(
+		int32_t len = min(_find.getLength(), _num);
+
+		const char* ptr = strFind<toLower>(
 			  _str.getPtr()
 			, _str.getLength()
 			, _find.getPtr()
-			, min(_find.getLength(), _num)
+			, len
 			);
+
+		if (NULL == ptr)
+		{
+			return StringView(_str.getTerm(), _str.getTerm() );
+		}
+
+		return StringView(ptr, len);
 	}
 
 	StringView strLTrim(const StringView& _str, const StringView& _chars)
@@ -464,132 +489,102 @@ namespace bx
 			}
 		}
 
-		return StringView();
+		return _str;
 	}
 
-	StringView strRTrim(const StringView& _str, const StringView& _chars)
+	StringView strLTrimSpace(const StringView& _str)
 	{
-		if (_str.isEmpty() )
-		{
-			return StringView();
-		}
-
-		const char* ptr   = _str.getPtr();
-		const char* chars = _chars.getPtr();
-		const uint32_t charsLen = _chars.getLength();
-
-		for (int32_t len = _str.getLength(), ii = len-1; 0 <= ii; --ii)
+		for (const char* ptr = _str.getPtr(), *term = _str.getTerm(); ptr != term; ++ptr)
 		{
-			if (NULL == strFindUnsafe(chars, charsLen, ptr[ii]) )
+			if (!isSpace(*ptr) )
 			{
-				return StringView(ptr, ii+1);
+				return StringView(ptr, term);
 			}
 		}
 
-		return StringView();
-	}
-
-	StringView strTrim(const StringView& _str, const StringView& _chars)
-	{
-		return strLTrim(strRTrim(_str, _chars), _chars);
+		return StringView(_str.getTerm(), _str.getTerm() );
 	}
 
-	const char* strnl(const char* _str)
+	StringView strLTrimNonSpace(const StringView& _str)
 	{
-		for (; '\0' != *_str; _str += strLen(_str, 1024) )
+		for (const char* ptr = _str.getPtr(), *term = _str.getTerm(); ptr != term; ++ptr)
 		{
-			const char* eol = strFind(StringView(_str, 1024), "\r\n");
-			if (NULL != eol)
-			{
-				return eol + 2;
-			}
-
-			eol = strFind(StringView(_str, 1024), "\n");
-			if (NULL != eol)
+			if (isSpace(*ptr) )
 			{
-				return eol + 1;
+				return StringView(ptr, term);
 			}
 		}
 
-		return _str;
+		return StringView(_str.getTerm(), _str.getTerm() );
 	}
 
-	const char* streol(const char* _str)
+	StringView strRTrim(const StringView& _str, const StringView& _chars)
 	{
-		for (; '\0' != *_str; _str += strLen(_str, 1024) )
+		if (!_str.isEmpty() )
 		{
-			const char* eol = strFind(StringView(_str, 1024), "\r\n");
-			if (NULL != eol)
-			{
-				return eol;
-			}
+			const char* ptr = _str.getPtr();
+			const char* chars = _chars.getPtr();
+			const uint32_t charsLen = _chars.getLength();
 
-			eol = strFind(StringView(_str, 1024), "\n");
-			if (NULL != eol)
+			for (int32_t len = _str.getLength(), ii = len - 1; 0 <= ii; --ii)
 			{
-				return eol;
+				if (NULL == strFindUnsafe(chars, charsLen, ptr[ii]))
+				{
+					return StringView(ptr, ii + 1);
+				}
 			}
 		}
 
 		return _str;
 	}
 
-	const StringView strFindEol(const StringView& _str)
+	StringView strTrim(const StringView& _str, const StringView& _chars)
+	{
+		return strLTrim(strRTrim(_str, _chars), _chars);
+	}
+
+	StringView strFindNl(const StringView& _str)
 	{
 		StringView str(_str);
 
 		for (; str.getPtr() != _str.getTerm()
-			 ; str = StringView(str.getPtr()+1024, min(str.getPtr()+1024, _str.getTerm() ) )
+			; str = StringView(str.getPtr() + 1024, min(str.getPtr() + 1024, _str.getTerm()))
 			)
 		{
-			const char* eol = strFind(str, "\r\n");
-			if (NULL != eol)
+			StringView eol = strFind(str, "\r\n");
+			if (!eol.isEmpty() )
 			{
-				return StringView(eol, _str.getTerm() );
+				return StringView(eol.getTerm(), _str.getTerm() );
 			}
 
 			eol = strFind(str, "\n");
-			if (NULL != eol)
+			if (!eol.isEmpty() )
 			{
-				return StringView(eol, _str.getTerm() );
+				return StringView(eol.getTerm(), _str.getTerm() );
 			}
 		}
 
 		return StringView(_str.getTerm(), _str.getTerm() );
 	}
 
-	const char* strws(const char* _str)
+	StringView strFindEol(const StringView& _str)
 	{
-		for (; isSpace(*_str); ++_str) {};
-		return _str;
-	}
+		StringView str(_str);
 
-	const StringView strSkipSpace(const StringView& _str)
-	{
-		for (const char* ptr = _str.getPtr(), *term = _str.getTerm(); ptr != term; ++ptr)
+		for (; str.getPtr() != _str.getTerm()
+			 ; str = StringView(str.getPtr()+1024, min(str.getPtr()+1024, _str.getTerm() ) )
+			)
 		{
-			if (!isSpace(*ptr) )
+			StringView eol = strFind(str, "\r\n");
+			if (!eol.isEmpty() )
 			{
-				return StringView(ptr, term);
+				return StringView(eol.getPtr(), _str.getTerm() );
 			}
-		}
-
-		return StringView(_str.getTerm(), _str.getTerm() );
-	}
 
-	const char* strnws(const char* _str)
-	{
-		for (; !isSpace(*_str); ++_str) {};
-		return _str;
-	}
-
-	const StringView strSkipNonSpace(const StringView& _str)
-	{
-		for (const char* ptr = _str.getPtr(), *term = _str.getTerm(); ptr != term; ++ptr)
-		{
-			if (isSpace(*ptr) )
+			eol = strFind(str, "\n");
+			if (!eol.isEmpty() )
 			{
-				return StringView(ptr, term);
+				return StringView(eol.getPtr(), _str.getTerm() );
 			}
 		}
 
@@ -648,22 +643,19 @@ namespace bx
 		}
 	}
 
-	const char* findIdentifierMatch(const char* _str, const char* _word)
+	StringView findIdentifierMatch(const StringView& _str, const StringView& _word)
 	{
-		int32_t len = strLen(_word);
-		const char* ptr = strFind(_str, _word);
-		for (; NULL != ptr; ptr = strFind(ptr + len, _word) )
+		const int32_t len = _word.getLength();
+		StringView ptr = strFind(_str, _word);
+		for (; !ptr.isEmpty(); ptr = strFind(StringView(ptr.getPtr() + len, _str.getTerm() ), _word) )
 		{
-			if (ptr != _str)
+			char ch = *(ptr.getPtr() - 1);
+			if (isAlphaNum(ch) || '_' == ch)
 			{
-				char ch = *(ptr - 1);
-				if (isAlphaNum(ch) || '_' == ch)
-				{
-					continue;
-				}
+				continue;
 			}
 
-			char ch = ptr[len];
+			ch = *(ptr.getPtr() + len);
 			if (isAlphaNum(ch) || '_' == ch)
 			{
 				continue;
@@ -672,21 +664,21 @@ namespace bx
 			return ptr;
 		}
 
-		return ptr;
+		return StringView(_str.getTerm(), _str.getTerm() );
 	}
 
-	const char* findIdentifierMatch(const char* _str, const char* _words[])
+	StringView findIdentifierMatch(const StringView& _str, const char** _words)
 	{
-		for (const char* word = *_words; NULL != word; ++_words, word = *_words)
+		for (StringView word = *_words; !word.isEmpty(); ++_words, word = *_words)
 		{
-			const char* match = findIdentifierMatch(_str, word);
-			if (NULL != match)
+			StringView match = findIdentifierMatch(_str, word);
+			if (!match.isEmpty() )
 			{
 				return match;
 			}
 		}
 
-		return NULL;
+		return StringView(_str.getTerm(), _str.getTerm() );
 	}
 
 	namespace

+ 35 - 35
src/url.cpp

@@ -24,22 +24,21 @@ namespace bx
 	{
 		clear();
 
-		const char* start = _url.getPtr();
 		const char* term  = _url.getTerm();
-		const char* schemeEnd = strFind(StringView(start, term), "://");
-		const char* hostStart = NULL != schemeEnd ? schemeEnd+3 : start;
-		const char* pathStart = strFind(StringView(hostStart, term), '/');
+		StringView schemeEnd = strFind(_url, "://");
+		const char* hostStart = !schemeEnd.isEmpty() ? schemeEnd.getTerm() : _url.getPtr();
+		StringView path = strFind(StringView(hostStart, term), '/');
 
-		if (NULL == schemeEnd
-		&&  NULL == pathStart)
+		if (schemeEnd.isEmpty()
+		&&  path.isEmpty() )
 		{
 			return false;
 		}
 
-		if (NULL != schemeEnd
-		&& (NULL == pathStart || pathStart > schemeEnd) )
+		if (!schemeEnd.isEmpty()
+		&& (path.isEmpty() || path.getPtr() > schemeEnd.getPtr() ) )
 		{
-			StringView scheme(start, schemeEnd);
+			const StringView scheme(_url.getPtr(), schemeEnd.getPtr() );
 
 			if (!isAlpha(scheme) )
 			{
@@ -49,63 +48,64 @@ namespace bx
 			m_tokens[Scheme].set(scheme);
 		}
 
-		if (NULL != pathStart)
+		if (!path.isEmpty() )
 		{
-			const char* queryStart    = strFind(StringView(pathStart, term), '?');
-			const char* fragmentStart = strFind(StringView(pathStart, term), '#');
+			path.set(path.getPtr(), term);
+			const StringView query    = strFind(path, '?');
+			const StringView fragment = strFind(path, '#');
 
-			if (NULL != fragmentStart
-			&&  fragmentStart < queryStart)
+			if (!fragment.isEmpty()
+			&&   fragment.getPtr() < query.getPtr() )
 			{
 				return false;
 			}
 
-			m_tokens[Path].set(pathStart
-				, NULL != queryStart    ? queryStart
-				: NULL != fragmentStart ? fragmentStart
+			m_tokens[Path].set(path.getPtr()
+				, !query.isEmpty()    ? query.getPtr()
+				: !fragment.isEmpty() ? fragment.getPtr()
 				: term
 				);
 
-			if (NULL != queryStart)
+			if (!query.isEmpty() )
 			{
-				m_tokens[Query].set(queryStart+1
-					, NULL != fragmentStart ? fragmentStart
+				m_tokens[Query].set(query.getPtr()+1
+					, !fragment.isEmpty() ? fragment.getPtr()
 					: term
 					);
 			}
 
-			if (NULL != fragmentStart)
+			if (!fragment.isEmpty() )
 			{
-				m_tokens[Fragment].set(fragmentStart+1, term);
+				m_tokens[Fragment].set(fragment.getPtr()+1, term);
 			}
 
-			term = pathStart;
+			term = path.getPtr();
 		}
 
-		const char* userPassEnd   = strFind(StringView(hostStart, term), '@');
-		const char* userPassStart = NULL != userPassEnd ? hostStart : NULL;
-		hostStart = NULL != userPassEnd ? userPassEnd+1 : hostStart;
-		const char* portStart = strFind(StringView(hostStart, term), ':');
+		const StringView userPassEnd = strFind(StringView(hostStart, term), '@');
+		const char* userPassStart = !userPassEnd.isEmpty() ? hostStart : NULL;
+		hostStart = !userPassEnd.isEmpty() ? userPassEnd.getPtr()+1 : hostStart;
+		const StringView portStart = strFind(StringView(hostStart, term), ':');
 
-		m_tokens[Host].set(hostStart, NULL != portStart ? portStart : term);
+		m_tokens[Host].set(hostStart, !portStart.isEmpty() ? portStart.getPtr() : term);
 
-		if (NULL != portStart)
+		if (!portStart.isEmpty())
 		{
-			m_tokens[Port].set(portStart+1, term);
+			m_tokens[Port].set(portStart.getPtr()+1, term);
 		}
 
 		if (NULL != userPassStart)
 		{
-			const char* passStart = strFind(StringView(userPassStart, userPassEnd), ':');
+			StringView passStart = strFind(StringView(userPassStart, userPassEnd.getPtr() ), ':');
 
 			m_tokens[UserName].set(userPassStart
-				, NULL != passStart ? passStart
-				: userPassEnd
+				, !passStart.isEmpty() ? passStart.getPtr()
+				: userPassEnd.getPtr()
 				);
 
-			if (NULL != passStart)
+			if (!passStart.isEmpty() )
 			{
-				m_tokens[Password].set(passStart+1, userPassEnd);
+				m_tokens[Password].set(passStart.getPtr()+1, userPassEnd.getPtr() );
 			}
 		}
 

+ 1 - 0
tests/nlalloc_test.cpp

@@ -100,6 +100,7 @@ namespace bx
 	public:
 		NonLocalAllocator()
 		{
+			reset();
 		}
 
 		~NonLocalAllocator()

+ 24 - 24
tests/string_test.cpp

@@ -181,19 +181,19 @@ TEST_CASE("strCmpV sort", "")
 TEST_CASE("strRFind", "")
 {
 	const char* test = "test";
-	REQUIRE(NULL == bx::strRFind(bx::StringView(test, 0), 's') );
-	REQUIRE(NULL == bx::strRFind(bx::StringView(test, 1), 's') );
-	REQUIRE(&test[2] == bx::strRFind(test, 's') );
+	REQUIRE(bx::strRFind(bx::StringView(test, 0), 's').isEmpty() );
+	REQUIRE(bx::strRFind(bx::StringView(test, 1), 's').isEmpty() );
+	REQUIRE(&test[2] == bx::strRFind(test, 's').getPtr() );
 }
 
 TEST_CASE("strFindI", "")
 {
 	const char* test = "The Quick Brown Fox Jumps Over The Lazy Dog.";
 
-	REQUIRE(NULL == bx::strFindI(bx::StringView(test, 8), "quick") );
-	REQUIRE(NULL == bx::strFindI(test, "quick1") );
-	REQUIRE(&test[4] == bx::strFindI(bx::StringView(test, 9), "quick") );
-	REQUIRE(&test[4] == bx::strFindI(test, "quick") );
+	REQUIRE(bx::strFindI(bx::StringView(test, 8), "quick").isEmpty() );
+	REQUIRE(bx::strFindI(test, "quick1").isEmpty() );
+	REQUIRE(&test[4] == bx::strFindI(bx::StringView(test, 9), "quick").getPtr() );
+	REQUIRE(&test[4] == bx::strFindI(test, "quick").getPtr() );
 }
 
 TEST_CASE("strFind", "")
@@ -201,25 +201,25 @@ TEST_CASE("strFind", "")
 	{
 		const char* test = "test";
 
-		REQUIRE(NULL == bx::strFind(bx::StringView(test, 0), 's') );
-		REQUIRE(NULL == bx::strFind(bx::StringView(test, 2), 's') );
-		REQUIRE(&test[2] == bx::strFind(test, 's') );
+		REQUIRE(bx::strFind(bx::StringView(test, 0), 's').isEmpty() );
+		REQUIRE(bx::strFind(bx::StringView(test, 2), 's').isEmpty() );
+		REQUIRE(&test[2] == bx::strFind(test, 's').getPtr() );
 	}
 
 	{
 		const char* test = "The Quick Brown Fox Jumps Over The Lazy Dog.";
 
-		REQUIRE(NULL == bx::strFind(bx::StringView(test, 8), "quick") );
-		REQUIRE(NULL == bx::strFind(test, "quick1") );
-		REQUIRE(NULL == bx::strFind(bx::StringView(test, 9), "quick") );
-		REQUIRE(NULL == bx::strFind(test, "quick") );
+		REQUIRE(bx::strFind(bx::StringView(test, 8), "quick").isEmpty() );
+		REQUIRE(bx::strFind(test, "quick1").isEmpty() );
+		REQUIRE(bx::strFind(bx::StringView(test, 9), "quick").isEmpty() );
+		REQUIRE(bx::strFind(test, "quick").isEmpty() );
 
-		REQUIRE(NULL == bx::strFind(bx::StringView(test, 8), "Quick") );
-		REQUIRE(NULL == bx::strFind(test, "Quick1") );
-		REQUIRE(&test[4] == bx::strFind(bx::StringView(test, 9), "Quick") );
-		REQUIRE(&test[4] == bx::strFind(test, "Quick") );
+		REQUIRE(bx::strFind(bx::StringView(test, 8), "Quick").isEmpty() );
+		REQUIRE(bx::strFind(test, "Quick1").isEmpty() );
+		REQUIRE(&test[4] == bx::strFind(bx::StringView(test, 9), "Quick").getPtr() );
+		REQUIRE(&test[4] == bx::strFind(test, "Quick").getPtr() );
 
-		REQUIRE(NULL == bx::strFind("vgd", 'a') );
+		REQUIRE(bx::strFind("vgd", 'a').isEmpty() );
 	}
 }
 
@@ -227,15 +227,15 @@ TEST_CASE("strSkip", "")
 {
 	const bx::StringView t0("   test X");
 
-	const bx::StringView t1 = bx::strSkipSpace(t0);
+	const bx::StringView t1 = bx::strLTrimSpace(t0);
 	REQUIRE(0 == bx::strCmp(t1, "test", 4) );
 
-	const bx::StringView t2 = bx::strSkipNonSpace(t1);
+	const bx::StringView t2 = bx::strLTrimNonSpace(t1);
 	REQUIRE(0 == bx::strCmp(t2, " X", 2) );
 
 	const bx::StringView t3("test");
 
-	const bx::StringView t4 = bx::strSkipNonSpace(t3);
+	const bx::StringView t4 = bx::strLTrimNonSpace(t3);
 	REQUIRE(t4.getTerm() == t4.getPtr() );
 }
 
@@ -433,11 +433,11 @@ TEST_CASE("StringView", "")
 TEST_CASE("Trim", "")
 {
 	REQUIRE(0 == bx::strCmp(bx::strLTrim("abvgd", "ab"), "vgd") );
-	REQUIRE(0 == bx::strCmp(bx::strLTrim("abvgd", "vagbd"), "") );
+	REQUIRE(0 == bx::strCmp(bx::strLTrim("abvgd", "vagbd"), "abvgd") );
 	REQUIRE(0 == bx::strCmp(bx::strLTrim("abvgd", "vgd"), "abvgd") );
 	REQUIRE(0 == bx::strCmp(bx::strLTrim("/555333/podmac/", "/"), "555333/podmac/") );
 
-	REQUIRE(0 == bx::strCmp(bx::strRTrim("abvgd", "vagbd"), "") );
+	REQUIRE(0 == bx::strCmp(bx::strRTrim("abvgd", "vagbd"), "abvgd") );
 	REQUIRE(0 == bx::strCmp(bx::strRTrim("abvgd", "abv"), "abvgd") );
 	REQUIRE(0 == bx::strCmp(bx::strRTrim("/555333/podmac/", "/"), "/555333/podmac") );
 

+ 1 - 1
tests/uint32_test.cpp

@@ -78,7 +78,7 @@ TEST_CASE("uint32_testpow2", "")
 	{
 		if (bx::uint32_testpow2(ii) )
 		{
-			REQUIRE(ii == 1 << shift);
+			REQUIRE(ii == 1u << shift);
 			++shift;
 		}
 	}