Explorar el Código

Added findIdentifierMatch.

Branimir Karadžić hace 12 años
padre
commit
679ce64c7c
Se han modificado 2 ficheros con 45 adiciones y 2 borrados
  1. 2 2
      include/bx/bx.h
  2. 43 0
      include/bx/string.h

+ 2 - 2
include/bx/bx.h

@@ -20,13 +20,13 @@ namespace bx
 
 	// Template for avoiding MSVC: C4127: conditional expression is constant
 	template<bool>
-	BX_FORCE_INLINE bool isEnabled()
+	inline bool isEnabled()
 	{
 		return true;
 	}
 
 	template<>
-	BX_FORCE_INLINE bool isEnabled<false>()
+	inline bool isEnabled<false>()
 	{
 		return false;
 	}

+ 43 - 0
include/bx/string.h

@@ -176,6 +176,49 @@ namespace bx
 		}
 	}
 
+	// Finds identifier.
+	inline const char* findIdentifierMatch(const char* _str, const char* _word)
+	{
+		size_t len = strlen(_word);
+		const char* ptr = strstr(_str, _word);
+		for (; NULL != ptr; ptr = strstr(ptr + len, _word) )
+		{
+			if (ptr != _str)
+			{
+				char ch = *(ptr - 1);
+				if (isalnum(ch) || '_' == ch)
+				{
+					continue;
+				}
+			}
+
+			char ch = ptr[len];
+			if (isalnum(ch) || '_' == ch)
+			{
+				continue;
+			}
+
+			return ptr;
+		}
+
+		return ptr;
+	}
+
+	// Finds any identifier from NULL terminated array of identifiers.
+	inline const char* findIdentifierMatch(const char* _str, const char* _words[])
+	{
+		for (const char* word = *_words; NULL != word; ++_words, word = *_words)
+		{
+			const char* match = findIdentifierMatch(_str, word);
+			if (NULL != match)
+			{
+				return match;
+			}
+		}
+
+		return NULL;
+	}
+
 	/// Cross platform implementation of vsnprintf that returns number of
 	/// characters which would have been written to the final string if
 	/// enough space had been available.