Branimir Karadžić před 8 roky
rodič
revize
4e530af94c
3 změnil soubory, kde provedl 18 přidání a 22 odebrání
  1. 4 8
      include/bx/url.h
  2. 10 10
      src/url.cpp
  3. 4 4
      tests/url_test.cpp

+ 4 - 8
include/bx/url.h

@@ -11,8 +11,9 @@
 namespace bx
 namespace bx
 {
 {
 	///
 	///
-	struct UrlToken
+	class UrlView
 	{
 	{
+	public:
 		enum Enum
 		enum Enum
 		{
 		{
 			Scheme,
 			Scheme,
@@ -26,12 +27,7 @@ namespace bx
 
 
 			Count
 			Count
 		};
 		};
-	};
 
 
-	///
-	class UrlView
-	{
-	public:
 		///
 		///
 		UrlView();
 		UrlView();
 
 
@@ -42,10 +38,10 @@ namespace bx
 		bool parse(const StringView& _url);
 		bool parse(const StringView& _url);
 
 
 		///
 		///
-		const StringView& get(UrlToken::Enum _token) const;
+		const StringView& get(Enum _token) const;
 
 
 	private:
 	private:
-		StringView m_tokens[UrlToken::Count];
+		StringView m_tokens[Count];
 	};
 	};
 
 
 	///
 	///

+ 10 - 10
src/url.cpp

@@ -13,7 +13,7 @@ namespace bx
 
 
 	void UrlView::clear()
 	void UrlView::clear()
 	{
 	{
-		for (uint32_t ii = 0; ii < UrlToken::Count; ++ii)
+		for (uint32_t ii = 0; ii < Count; ++ii)
 		{
 		{
 			m_tokens[ii].clear();
 			m_tokens[ii].clear();
 		}
 		}
@@ -45,7 +45,7 @@ namespace bx
 				return false;
 				return false;
 			}
 			}
 
 
-			m_tokens[UrlToken::Scheme].set(scheme);
+			m_tokens[Scheme].set(scheme);
 		}
 		}
 
 
 		if (NULL != pathStart)
 		if (NULL != pathStart)
@@ -59,7 +59,7 @@ namespace bx
 				return false;
 				return false;
 			}
 			}
 
 
-			m_tokens[UrlToken::Path].set(pathStart
+			m_tokens[Path].set(pathStart
 				, NULL != queryStart    ? queryStart
 				, NULL != queryStart    ? queryStart
 				: NULL != fragmentStart ? fragmentStart
 				: NULL != fragmentStart ? fragmentStart
 				: term
 				: term
@@ -67,7 +67,7 @@ namespace bx
 
 
 			if (NULL != queryStart)
 			if (NULL != queryStart)
 			{
 			{
-				m_tokens[UrlToken::Query].set(queryStart+1
+				m_tokens[Query].set(queryStart+1
 					, NULL != fragmentStart ? fragmentStart
 					, NULL != fragmentStart ? fragmentStart
 					: term
 					: term
 					);
 					);
@@ -75,7 +75,7 @@ namespace bx
 
 
 			if (NULL != fragmentStart)
 			if (NULL != fragmentStart)
 			{
 			{
-				m_tokens[UrlToken::Fragment].set(fragmentStart+1, term);
+				m_tokens[Fragment].set(fragmentStart+1, term);
 			}
 			}
 
 
 			term = pathStart;
 			term = pathStart;
@@ -86,32 +86,32 @@ namespace bx
 		hostStart = NULL != userPassEnd ? userPassEnd+1 : hostStart;
 		hostStart = NULL != userPassEnd ? userPassEnd+1 : hostStart;
 		const char* portStart = strFind(StringView(hostStart, term), ':');
 		const char* portStart = strFind(StringView(hostStart, term), ':');
 
 
-		m_tokens[UrlToken::Host].set(hostStart, NULL != portStart ? portStart : term);
+		m_tokens[Host].set(hostStart, NULL != portStart ? portStart : term);
 
 
 		if (NULL != portStart)
 		if (NULL != portStart)
 		{
 		{
-			m_tokens[UrlToken::Port].set(portStart+1, term);
+			m_tokens[Port].set(portStart+1, term);
 		}
 		}
 
 
 		if (NULL != userPassStart)
 		if (NULL != userPassStart)
 		{
 		{
 			const char* passStart = strFind(StringView(userPassStart, userPassEnd), ':');
 			const char* passStart = strFind(StringView(userPassStart, userPassEnd), ':');
 
 
-			m_tokens[UrlToken::UserName].set(userPassStart
+			m_tokens[UserName].set(userPassStart
 				, NULL != passStart ? passStart
 				, NULL != passStart ? passStart
 				: userPassEnd
 				: userPassEnd
 				);
 				);
 
 
 			if (NULL != passStart)
 			if (NULL != passStart)
 			{
 			{
-				m_tokens[UrlToken::Password].set(passStart+1, userPassEnd);
+				m_tokens[Password].set(passStart+1, userPassEnd);
 			}
 			}
 		}
 		}
 
 
 		return true;
 		return true;
 	}
 	}
 
 
-	const StringView& UrlView::get(UrlToken::Enum _token) const
+	const StringView& UrlView::get(Enum _token) const
 	{
 	{
 		return m_tokens[_token];
 		return m_tokens[_token];
 	}
 	}

+ 4 - 4
tests/url_test.cpp

@@ -11,7 +11,7 @@ struct UrlTest
 {
 {
 	bool result;
 	bool result;
 	const char* url;
 	const char* url;
-	const char* tokens[bx::UrlToken::Count];
+	const char* tokens[bx::UrlView::Count];
 };
 };
 
 
 static const UrlTest s_urlTest[] =
 static const UrlTest s_urlTest[] =
@@ -56,13 +56,13 @@ TEST_CASE("tokenizeUrl", "")
 
 
 		if (result)
 		if (result)
 		{
 		{
-			for (uint32_t token = 0; token < bx::UrlToken::Count; ++token)
+			for (uint32_t token = 0; token < bx::UrlView::Count; ++token)
 			{
 			{
 //				char tmp[1024];
 //				char tmp[1024];
-//				strCopy(tmp, BX_COUNTOF(tmp), url.get(bx::UrlToken::Enum(token)) );
+//				strCopy(tmp, BX_COUNTOF(tmp), url.get(bx::UrlView::Enum(token)) );
 //				printf("`%s`, expected: `%s`\n", tmp, urlTest.tokens[token]);
 //				printf("`%s`, expected: `%s`\n", tmp, urlTest.tokens[token]);
 
 
-				REQUIRE(0 == bx::strCmp(urlTest.tokens[token], url.get(bx::UrlToken::Enum(token)) ) );
+				REQUIRE(0 == bx::strCmp(urlTest.tokens[token], url.get(bx::UrlView::Enum(token)) ) );
 			}
 			}
 		}
 		}
 	}
 	}