Browse Source

StringView cleanup.

Branimir Karadžić 7 years ago
parent
commit
6bff345637

+ 3 - 3
examples/common/entry/cmd.cpp

@@ -37,7 +37,7 @@ struct CmdContext
 
 	void exec(const char* _cmd)
 	{
-		for (const char* next = _cmd; '\0' != *next; _cmd = next)
+		for (bx::StringView next(_cmd); !next.isEmpty(); _cmd = next.getPtr() )
 		{
 			char commandLine[1024];
 			uint32_t size = sizeof(commandLine);
@@ -62,14 +62,14 @@ struct CmdContext
 
 				case -1:
 					{
-						stl::string tmp(_cmd, next-_cmd - (*next == '\0' ? 0 : 1) );
+						stl::string tmp(_cmd, next.getPtr()-_cmd - (next.isEmpty() ? 0 : 1) );
 						DBG("Command '%s' doesn't exist.", tmp.c_str() );
 					}
 					break;
 
 				default:
 					{
-						stl::string tmp(_cmd, next-_cmd - (*next == '\0' ? 0 : 1) );
+						stl::string tmp(_cmd, next.getPtr()-_cmd - (next.isEmpty() ? 0 : 1) );
 						DBG("Failed '%s' err: %d.", tmp.c_str(), err);
 					}
 					break;

+ 1 - 1
examples/common/entry/entry.cpp

@@ -603,7 +603,7 @@ restart:
 		for (AppI* app = getFirstApp(); NULL != app; app = app->getNext() )
 		{
 			if (NULL == selected
-			&&  bx::strFindI(app->getName(), find) )
+			&&  !bx::strFindI(app->getName(), find).isEmpty() )
 			{
 				selected = app;
 			}

BIN
examples/runtime/meshes/bunny.bin


+ 4 - 4
src/bgfx.cpp

@@ -510,13 +510,13 @@ namespace bgfx
 
 	static uint8_t parseAttrTo(char*& _ptr, char _to, uint8_t _default)
 	{
-		const char* str = bx::strFind(_ptr, _to);
-		if (NULL != str
-		&&  3 > str-_ptr)
+		const bx::StringView str = bx::strFind(_ptr, _to);
+		if (!str.isEmpty()
+		&&  3 > str.getPtr()-_ptr)
 		{
 			char tmp[4];
 
-			int32_t len = int32_t(str-_ptr);
+			int32_t len = int32_t(str.getPtr()-_ptr);
 			bx::strCopy(tmp, sizeof(tmp), _ptr, len);
 
 			uint8_t attr = uint8_t(atoi(tmp) );

+ 1 - 1
src/dxgi.cpp

@@ -227,7 +227,7 @@ namespace bgfx
 							}
 
 							if (BX_ENABLED(BGFX_CONFIG_DEBUG_PERFHUD)
-							&&  0 != bx::strFind(description, "PerfHUD") )
+							&&  !bx::strFind(description, "PerfHUD").isEmpty() )
 							{
 								m_adapter = adapter;
 								m_driverType = D3D_DRIVER_TYPE_REFERENCE;

+ 1 - 1
src/renderer_d3d9.cpp

@@ -551,7 +551,7 @@ namespace bgfx { namespace d3d9
 							}
 
 							if (BX_ENABLED(BGFX_CONFIG_DEBUG_PERFHUD)
-							&&  0 != bx::strFind(desc.Description, "PerfHUD") )
+							&&  !bx::strFind(desc.Description, "PerfHUD").isEmpty() )
 							{
 								m_adapter = ii;
 								m_deviceType = D3DDEVTYPE_REF;

+ 63 - 64
src/renderer_gl.cpp

@@ -1073,10 +1073,10 @@ namespace bgfx { namespace gl
 			while (pos < end)
 			{
 				uint32_t len;
-				const char* space = bx::strFind(pos, ' ');
-				if (NULL != space)
+				bx::StringView space = bx::strFind(pos, ' ');
+				if (!space.isEmpty() )
 				{
-					len = bx::uint32_min(sizeof(name), (uint32_t)(space - pos) );
+					len = bx::uint32_min(sizeof(name), (uint32_t)(space.getPtr() - pos) );
 				}
 				else
 				{
@@ -1855,8 +1855,8 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
 				;
 
 			if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 31)
-			&&  0    == bx::strCmp(m_vendor, "Imagination Technologies")
-			&&  NULL != bx::strFind(m_version, "(SDK 3.5@3510720)") )
+			&&  0 == bx::strCmp(m_vendor, "Imagination Technologies")
+			&&  !bx::strFind(m_version, "(SDK 3.5@3510720)").isEmpty() )
 			{
 				// Skip initializing extensions that are broken in emulator.
 				s_extension[Extension::ARB_program_interface_query     ].m_initialize =
@@ -1864,8 +1864,8 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
 			}
 
 			if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES)
-			&&  0    == bx::strCmp(m_vendor, "Imagination Technologies")
-			&&  NULL != bx::strFind(m_version, "1.8@905891") )
+			&&  0 == bx::strCmp(m_vendor, "Imagination Technologies")
+			&&  !bx::strFind(m_version, "1.8@905891").isEmpty() )
 			{
 				m_workaround.m_detachShader = false;
 			}
@@ -1883,10 +1883,10 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
 					while (pos < end)
 					{
 						uint32_t len;
-						const char* space = bx::strFind(pos, ' ');
-						if (NULL != space)
+						const bx::StringView space = bx::strFind(pos, ' ');
+						if (!space.isEmpty() )
 						{
-							len = bx::uint32_min(sizeof(name), (uint32_t)(space - pos) );
+							len = bx::uint32_min(sizeof(name), (uint32_t)(space.getPtr() - pos) );
 						}
 						else
 						{
@@ -4279,19 +4279,14 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
 
 			num = bx::uint32_max(num, 1);
 
-			int offset = 0;
-			char* array = const_cast<char*>(bx::strFind(name, '[') );
-			if (NULL != array)
+			int32_t offset = 0;
+			const bx::StringView array = bx::strFind(name, '[');
+			if (!array.isEmpty() )
 			{
+				name[array.getPtr() - name] = '\0';
 				BX_TRACE("--- %s", name);
-				*array = '\0';
-				array++;
-				char* end = const_cast<char*>(bx::strFind(array, ']') );
-				if (NULL != end)
-				{ // Some devices (Amazon Fire) might not return terminating brace.
-					*end = '\0';
-					offset = atoi(array);
-				}
+				const bx::StringView end = bx::strFind(array.getPtr()+1, ']');
+				bx::fromString(&offset, bx::StringView(array.getPtr()+1, end.getPtr() ) );
 			}
 
 			switch (gltype)
@@ -5318,15 +5313,14 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
 		m_id = glCreateShader(m_type);
 		BX_WARN(0 != m_id, "Failed to create shader.");
 
-		const char* code = (const char*)reader.getDataPtr();
+		bx::StringView code( (const char*)reader.getDataPtr(), shaderSize);
 
 		if (0 != m_id)
 		{
 			if (GL_COMPUTE_SHADER != m_type
 			&&  0 != bx::strCmp(code, "#version 430", 12) )
 			{
-				int32_t codeLen = (int32_t)bx::strLen(code);
-				int32_t tempLen = codeLen + (4<<10);
+				int32_t tempLen = code.getLength() + (4<<10);
 				char* temp = (char*)alloca(tempLen);
 				bx::StaticMemoryBlockWriter writer(temp, tempLen);
 
@@ -5341,22 +5335,22 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
 						);
 
 					bool usesDerivatives = s_extension[Extension::OES_standard_derivatives].m_supported
-						&& bx::findIdentifierMatch(code, s_OES_standard_derivatives)
+						&& !bx::findIdentifierMatch(code, s_OES_standard_derivatives).isEmpty()
 						;
 
-					bool usesFragData  = !!bx::findIdentifierMatch(code, "gl_FragData");
+					bool usesFragData  = !bx::findIdentifierMatch(code, "gl_FragData").isEmpty();
 
-					bool usesFragDepth = !!bx::findIdentifierMatch(code, "gl_FragDepth");
+					bool usesFragDepth = !bx::findIdentifierMatch(code, "gl_FragDepth").isEmpty();
 
-					bool usesShadowSamplers = !!bx::findIdentifierMatch(code, s_EXT_shadow_samplers);
+					bool usesShadowSamplers = !bx::findIdentifierMatch(code, s_EXT_shadow_samplers).isEmpty();
 
 					bool usesTexture3D = s_extension[Extension::OES_texture_3D].m_supported
-						&& bx::findIdentifierMatch(code, s_texture3D)
+						&& !bx::findIdentifierMatch(code, s_texture3D).isEmpty()
 						;
 
-					bool usesTextureLod = !!bx::findIdentifierMatch(code, s_EXT_shader_texture_lod);
+					bool usesTextureLod = !bx::findIdentifierMatch(code, s_EXT_shader_texture_lod).isEmpty();
 
-					bool usesFragmentOrdering = !!bx::findIdentifierMatch(code, "beginFragmentShaderOrdering");
+					bool usesFragmentOrdering = !bx::findIdentifierMatch(code, "beginFragmentShaderOrdering").isEmpty();
 
 					if (usesDerivatives)
 					{
@@ -5479,30 +5473,35 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
 							, m_type == GL_FRAGMENT_SHADER ? "mediump" : "highp"
 							);
 
-					bx::write(&writer, code, codeLen);
+					bx::write(&writer, code);
 					bx::write(&writer, '\0');
 
 					if (insertFragDepth)
 					{
-						const char* entry = bx::strFind(temp, "void main ()");
-						if (NULL != entry)
+						bx::StringView shader(temp);
+						bx::StringView entry = bx::strFind(shader, "void main ()");
+						if (!entry.isEmpty() )
 						{
-							char* brace = const_cast<char*>(bx::strFind(entry, "{") );
-							if (NULL != brace)
+							entry.set(entry.getTerm(), shader.getTerm() );
+							bx::StringView brace = bx::strFind(entry, "{");
+							if (!brace.isEmpty() )
 							{
-								const char* end = bx::strmb(brace, '{', '}');
+								const char* end = bx::strmb(brace.getPtr(), '{', '}');
 								if (NULL != end)
 								{
-									strins(brace+1, "\n  float bgfx_FragDepth = 0.0;\n");
+									strins(const_cast<char*>(brace.getPtr()+1), "\n  float bgfx_FragDepth = 0.0;\n");
 								}
 							}
 						}
 					}
 
 					// Replace all instances of gl_FragDepth with bgfx_FragDepth.
-					for (const char* fragDepth = bx::findIdentifierMatch(temp, "gl_FragDepth"); NULL != fragDepth; fragDepth = bx::findIdentifierMatch(fragDepth, "gl_FragDepth") )
+					for (bx::StringView fragDepth = bx::findIdentifierMatch(temp, "gl_FragDepth")
+						; !fragDepth.isEmpty()
+						; fragDepth = bx::findIdentifierMatch(fragDepth, "gl_FragDepth")
+						)
 					{
-						char* insert = const_cast<char*>(fragDepth);
+						char* insert = const_cast<char*>(fragDepth.getPtr() );
 						strins(insert, "bg");
 						bx::memCopy(insert + 2, "fx", 2);
 					}
@@ -5512,18 +5511,18 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
 				{
 					const bool usesTextureLod = true
 						&& s_extension[Extension::ARB_shader_texture_lod].m_supported
-						&& bx::findIdentifierMatch(code, s_ARB_shader_texture_lod)
+						&& !bx::findIdentifierMatch(code, s_ARB_shader_texture_lod).isEmpty()
 						;
-					const bool usesGpuShader4   = !!bx::findIdentifierMatch(code, s_EXT_gpu_shader4);
-					const bool usesGpuShader5   = !!bx::findIdentifierMatch(code, s_ARB_gpu_shader5);
-					const bool usesIUsamplers   = !!bx::findIdentifierMatch(code, s_uisamplers);
-					const bool usesUint         = !!bx::findIdentifierMatch(code, s_uint);
-					const bool usesTexelFetch   = !!bx::findIdentifierMatch(code, s_texelFetch);
-					const bool usesTextureArray = !!bx::findIdentifierMatch(code, s_textureArray);
-					const bool usesTexture3D    = !!bx::findIdentifierMatch(code, s_texture3D);
-					const bool usesTextureMS    = !!bx::findIdentifierMatch(code, s_ARB_texture_multisample);
-					const bool usesPacking      = !!bx::findIdentifierMatch(code, s_ARB_shading_language_packing);
-					const bool usesInterpQ      = !!bx::findIdentifierMatch(code, s_intepolationQualifier);
+					const bool usesGpuShader4   = !bx::findIdentifierMatch(code, s_EXT_gpu_shader4).isEmpty();
+					const bool usesGpuShader5   = !bx::findIdentifierMatch(code, s_ARB_gpu_shader5).isEmpty();
+					const bool usesIUsamplers   = !bx::findIdentifierMatch(code, s_uisamplers).isEmpty();
+					const bool usesUint         = !bx::findIdentifierMatch(code, s_uint).isEmpty();
+					const bool usesTexelFetch   = !bx::findIdentifierMatch(code, s_texelFetch).isEmpty();
+					const bool usesTextureArray = !bx::findIdentifierMatch(code, s_textureArray).isEmpty();
+					const bool usesTexture3D    = !bx::findIdentifierMatch(code, s_texture3D).isEmpty();
+					const bool usesTextureMS    = !bx::findIdentifierMatch(code, s_ARB_texture_multisample).isEmpty();
+					const bool usesPacking      = !bx::findIdentifierMatch(code, s_ARB_shading_language_packing).isEmpty();
+					const bool usesInterpQ      = !bx::findIdentifierMatch(code, s_intepolationQualifier).isEmpty();
 
 					uint32_t version = BX_ENABLED(BX_PLATFORM_OSX) ? 120
 						:  usesTextureArray
@@ -5617,13 +5616,13 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
 
 						uint32_t fragData = 0;
 
-						if (!!bx::findIdentifierMatch(code, "gl_FragData") )
+						if (!bx::findIdentifierMatch(code, "gl_FragData").isEmpty() )
 						{
 							for (uint32_t ii = 0, num = g_caps.limits.maxFBAttachments; ii < num; ++ii)
 							{
 								char tmpFragData[16];
 								bx::snprintf(tmpFragData, BX_COUNTOF(tmpFragData), "gl_FragData[%d]", ii);
-								fragData = bx::uint32_max(fragData, NULL == bx::strFind(code, tmpFragData) ? 0 : ii+1);
+								fragData = bx::uint32_max(fragData, bx::strFind(code, tmpFragData).isEmpty() ? 0 : ii+1);
 							}
 
 							BGFX_FATAL(0 != fragData, Fatal::InvalidShader, "Unable to find and patch gl_FragData!");
@@ -5669,7 +5668,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
 							);
 					}
 
-					bx::write(&writer, code, codeLen);
+					bx::write(&writer, code);
 					bx::write(&writer, '\0');
 				}
 				else if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL   >= 31)
@@ -5717,19 +5716,19 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
 
 						uint32_t fragData = 0;
 
-						if (!!bx::findIdentifierMatch(code, "gl_FragData") )
+						if (!bx::findIdentifierMatch(code, "gl_FragData").isEmpty() )
 						{
 							for (uint32_t ii = 0, num = g_caps.limits.maxFBAttachments; ii < num; ++ii)
 							{
 								char tmpFragData[16];
 								bx::snprintf(tmpFragData, BX_COUNTOF(tmpFragData), "gl_FragData[%d]", ii);
-								fragData = bx::uint32_max(fragData, NULL == bx::strFind(code, tmpFragData) ? 0 : ii+1);
+								fragData = bx::uint32_max(fragData, bx::strFind(code, tmpFragData).isEmpty() ? 0 : ii+1);
 							}
 
 							BGFX_FATAL(0 != fragData, Fatal::InvalidShader, "Unable to find and patch gl_FragData!");
 						}
 
-						if (!!bx::findIdentifierMatch(code, "beginFragmentShaderOrdering") )
+						if (!bx::findIdentifierMatch(code, "beginFragmentShaderOrdering").isEmpty() )
 						{
 							if (s_extension[Extension::INTEL_fragment_shader_ordering].m_supported)
 							{
@@ -5741,7 +5740,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
 							}
 						}
 
-						if (!!bx::findIdentifierMatch(code, s_ARB_texture_multisample) )
+						if (!bx::findIdentifierMatch(code, s_ARB_texture_multisample).isEmpty() )
 						{
 							writeString(&writer, "#extension GL_ARB_texture_multisample : enable\n");
 						}
@@ -5772,11 +5771,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
 								);
 					}
 
-					bx::write(&writer, code, codeLen);
+					bx::write(&writer, code.getPtr(), code.getLength() );
 					bx::write(&writer, '\0');
 				}
 
-				code = temp;
+				code.set(temp);
 			}
 			else if (GL_COMPUTE_SHADER == m_type)
 			{
@@ -5793,7 +5792,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
 				writeString(&writer, "#define texture3DGrad   textureGrad\n");
 				writeString(&writer, "#define textureCubeGrad textureGrad\n");
 
-				bx::write(&writer, code+bx::strLen("#version 430"), codeLen);
+				bx::write(&writer, code.getPtr()+bx::strLen("#version 430"), codeLen);
 				bx::write(&writer, '\0');
 
 				code = temp;
@@ -5817,10 +5816,10 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
 					if (err.isOk() )
 					{
 						str[len] = '\0';
-						const char* eol = bx::streol(str);
-						if (eol != str)
+						bx::StringView eol = bx::strFindEol(str);
+						if (eol.getPtr() != str)
 						{
-							*const_cast<char*>(eol) = '\0';
+							*const_cast<char*>(eol.getPtr() ) = '\0';
 						}
 						BX_TRACE("%3d %s", line, str);
 					}

+ 8 - 1
src/renderer_gl.h

@@ -1544,6 +1544,13 @@ namespace bgfx { namespace gl
 		{
 		}
 
+		LineReader(const bx::StringView& _str)
+			: m_str(_str.getPtr() )
+			, m_pos(0)
+			, m_size(_str.getLength() )
+		{
+		}
+
 		virtual int32_t read(void* _data, int32_t _size, bx::Error* _err) override
 		{
 			if (m_str[m_pos] == '\0'
@@ -1555,7 +1562,7 @@ namespace bgfx { namespace gl
 
 			uint32_t pos = m_pos;
 			const char* str = &m_str[pos];
-			const char* nl = bx::strnl(str);
+			const char* nl = bx::strFindNl(str).getPtr();
 			pos += (uint32_t)(nl - str);
 
 			const char* eol = &m_str[pos];

+ 49 - 42
tools/geometryc/geometryc.cpp

@@ -504,10 +504,11 @@ int main(int _argc, const char* _argv[])
 	uint32_t len = sizeof(commandLine);
 	int argc;
 	char* argv[64];
-	const char* next = data;
-	do
+
+	for (bx::StringView next(data, size); !next.isEmpty(); )
 	{
 		next = bx::tokenizeCommandLine(next, commandLine, len, argc, argv, BX_COUNTOF(argv), '\n');
+
 		if (0 < argc)
 		{
 			if (0 == bx::strCmp(argv[0], "#") )
@@ -537,60 +538,63 @@ int main(int _argc, const char* _argv[])
 					}
 					else
 					{
-						index.m_vbc = 0;
+						index.m_vbc = 0; 
 					}
 
-					const char* vertex = argv[edge+1];
-					char* texcoord = const_cast<char*>(bx::strFind(vertex, '/') );
-					if (NULL != texcoord)
 					{
-						*texcoord++ = '\0';
-
-						char* normal = const_cast<char*>(bx::strFind(texcoord, '/') );
-						if (NULL != normal)
+						bx::StringView triplet(argv[edge + 1]);
+						bx::StringView vertex(triplet);
+						bx::StringView texcoord = bx::strFind(triplet, '/');
+						if (!texcoord.isEmpty())
 						{
-							*normal++ = '\0';
-							int32_t nn;
-							bx::fromString(&nn, normal);
-							index.m_normal = (nn < 0) ? nn+numNormals : nn-1;
-						}
+							vertex.set(vertex.getPtr(), texcoord.getPtr());
 
-						// https://en.wikipedia.org/wiki/Wavefront_.obj_file#Vertex_Normal_Indices_Without_Texture_Coordinate_Indices
-						if(*texcoord != '\0')
-						{
-							int32_t tex;
-							bx::fromString(&tex, texcoord);
-							index.m_texcoord = (tex < 0) ? tex+numTexcoords : tex-1;
+							const bx::StringView normal = bx::strFind(bx::StringView(texcoord.getPtr() + 1, triplet.getTerm()), '/');
+							if (!normal.isEmpty())
+							{
+								int32_t nn;
+								bx::fromString(&nn, bx::StringView(normal.getPtr() + 1, triplet.getTerm()));
+								index.m_normal = (nn < 0) ? nn + numNormals : nn - 1;
+							}
+
+							texcoord.set(texcoord.getPtr() + 1, normal.getPtr());
+
+							// https://en.wikipedia.org/wiki/Wavefront_.obj_file#Vertex_Normal_Indices_Without_Texture_Coordinate_Indices
+							if (!texcoord.isEmpty())
+							{
+								int32_t tex;
+								bx::fromString(&tex, texcoord);
+								index.m_texcoord = (tex < 0) ? tex + numTexcoords : tex - 1;
+							}
 						}
-					}
 
-					int32_t pos;
-					bx::fromString(&pos, vertex);
-					index.m_position = (pos < 0) ? pos+numPositions : pos-1;
+						int32_t pos;
+						bx::fromString(&pos, vertex);
+						index.m_position = (pos < 0) ? pos + numPositions : pos - 1;
+					}
 
-					uint64_t hash0 = index.m_position;
-					uint64_t hash1 = uint64_t(index.m_texcoord)<<20;
-					uint64_t hash2 = uint64_t(index.m_normal)<<40;
-					uint64_t hash3 = uint64_t(index.m_vbc)<<60;
-					uint64_t hash = hash0^hash1^hash2^hash3;
+					const uint64_t hash0 = uint64_t(index.m_position)<< 0;
+					const uint64_t hash1 = uint64_t(index.m_texcoord)<<20;
+					const uint64_t hash2 = uint64_t(index.m_normal  )<<40;
+					const uint64_t hash3 = uint64_t(index.m_vbc     )<<60;
+					const uint64_t hash  = hash0^hash1^hash2^hash3;
 
 					stl::pair<Index3Map::iterator, bool> result = indexMap.insert(stl::make_pair(hash, index) );
 					if (!result.second)
 					{
 						Index3& oldIndex = result.first->second;
 						BX_UNUSED(oldIndex);
-						BX_CHECK(oldIndex.m_position == index.m_position
+						BX_CHECK(true
+							&& oldIndex.m_position == index.m_position
 							&& oldIndex.m_texcoord == index.m_texcoord
-							&& oldIndex.m_normal == index.m_normal
+							&& oldIndex.m_normal   == index.m_normal
 							, "Hash collision!"
 							);
 					}
 
 					switch (edge)
 					{
-					case 0:
-					case 1:
-					case 2:
+					case 0:	case 1:	case 2:
 						triangle.m_index[edge] = hash;
 						if (2 == edge)
 						{
@@ -613,6 +617,7 @@ int main(int _argc, const char* _argv[])
 							triangle.m_index[1] = triangle.m_index[2];
 							triangle.m_index[2] = hash;
 						}
+
 						triangles.push_back(triangle);
 						break;
 					}
@@ -660,7 +665,8 @@ int main(int _argc, const char* _argv[])
 					{
 					case 4:
 						texcoord.z = (float)atof(argv[3]);
-						// fallthrough
+						BX_FALLTHROUGH;
+
 					case 3:
 						texcoord.y = (float)atof(argv[2]);
 						break;
@@ -726,7 +732,6 @@ int main(int _argc, const char* _argv[])
 
 		++num;
 	}
-	while ('\0' != *next);
 
 	group.m_numTriangles = (uint32_t)(triangles.size() ) - group.m_startTriangle;
 	if (0 < group.m_numTriangles)
@@ -838,6 +843,7 @@ int main(int _argc, const char* _argv[])
 			break;
 		}
 	}
+
 	decl.end();
 
 	uint32_t stride = decl.getStride();
@@ -877,7 +883,7 @@ int main(int _argc, const char* _argv[])
 		for (uint32_t tri = groupIt->m_startTriangle, end = tri + groupIt->m_numTriangles; tri < end; ++tri)
 		{
 			if (0 != bx::strCmp(material.c_str(), groupIt->m_material.c_str() )
-			||  65533 < numVertices)
+			||  65533 <= numVertices)
 			{
 				prim.m_numVertices = numVertices - prim.m_startVertex;
 				prim.m_numIndices  = numIndices  - prim.m_startIndex;
@@ -900,7 +906,8 @@ int main(int _argc, const char* _argv[])
 					triangleReorder(indexData + prim1.m_startIndex, prim1.m_numIndices, numVertices, 32);
 					if (compress)
 					{
-						triangleCompress(&memWriter
+						triangleCompress(
+							  &memWriter
 							, indexData  + prim1.m_startIndex
 							, prim1.m_numIndices
 							, vertexData + prim1.m_startVertex
@@ -930,11 +937,11 @@ int main(int _argc, const char* _argv[])
 				}
 
 				vertices = vertexData;
-				indices = indexData;
+				indices  = indexData;
 				numVertices = 0;
-				numIndices = 0;
+				numIndices  = 0;
 				prim.m_startVertex = 0;
-				prim.m_startIndex = 0;
+				prim.m_startIndex  = 0;
 				++numPrimitives;
 
 				material = groupIt->m_material;

+ 96 - 94
tools/shaderc/shaderc.cpp

@@ -478,12 +478,12 @@ namespace bgfx
 		replace[len] = '\0';
 
 		BX_CHECK(len >= bx::strLen(_replace), "");
-		for (const char* ptr = bx::strFind(_str, _find)
-			; NULL != ptr
-			; ptr = bx::strFind(ptr + len, _find)
+		for (bx::StringView ptr = bx::strFind(_str, _find)
+			; !ptr.isEmpty()
+			; ptr = bx::strFind(ptr.getPtr() + len, _find)
 			)
 		{
-			bx::memCopy(const_cast<char*>(ptr), replace, len);
+			bx::memCopy(const_cast<char*>(ptr.getPtr() ), replace, len);
 		}
 	}
 
@@ -619,16 +619,16 @@ namespace bgfx
 		{
 			char* start = scratch(_includeDir);
 
-			for (char* split = const_cast<char*>(bx::strFind(start, ';') )
-				; NULL != split
-				; split = const_cast<char*>(bx::strFind(start, ';') )
+			for (bx::StringView split = bx::strFind(start, ';')
+				; !split.isEmpty()
+				; split = bx::strFind(start, ';')
 				)
 			{
-				*split = '\0';
+				*const_cast<char*>(split.getPtr() ) = '\0';
 				m_tagptr->tag = FPPTAG_INCLUDE_DIR;
 				m_tagptr->data = start;
 				m_tagptr++;
-				start = split + 1;
+				start = const_cast<char*>(split.getPtr() ) + 1;
 			}
 
 			m_tagptr->tag = FPPTAG_INCLUDE_DIR;
@@ -734,7 +734,7 @@ namespace bgfx
 	uint32_t parseInOut(InOut& _inout, const char* _str, const char* _eol)
 	{
 		uint32_t hash = 0;
-		_str = bx::strws(_str);
+		_str = bx::strLTrimSpace(_str).getPtr();
 
 		if (_str < _eol)
 		{
@@ -748,7 +748,7 @@ namespace bgfx
 					std::string token;
 					token.assign(_str, delim-_str);
 					_inout.push_back(token);
-					_str = bx::strws(delim + 1);
+					_str = bx::strLTrimSpace(delim + 1).getPtr();
 				}
 			}
 			while (delim < _eol && _str < _eol && NULL != delim);
@@ -798,8 +798,8 @@ namespace bgfx
 		bx::FilePath fp(_filePath);
 		char tmp[bx::kMaxFilePath];
 		bx::strCopy(tmp, BX_COUNTOF(tmp), fp.getFileName() );
-		const char* base = bx::strFind(_filePath, tmp);
-		return base;
+		bx::StringView base = bx::strFind(_filePath, tmp);
+		return base.isEmpty() ? NULL : base.getPtr();
 	}
 
 	// c - compute
@@ -1049,20 +1049,25 @@ namespace bgfx
 
 		VaryingMap varyingMap;
 		const char* parse = _varying;
+		bx::StringView term(parse);
 
 		bool usesInterpolationQualifiers = false;
 
 		while (NULL !=  parse
 		&&     '\0' != *parse)
 		{
-			parse = bx::strws(parse);
-			const char* eol = bx::strFind(parse, ';');
-			if (NULL == eol)
+			parse = bx::strLTrimSpace(parse).getPtr();
+			bx::StringView eol = bx::strFind(parse, ';');
+			if (eol.isEmpty() )
 			{
-				eol = bx::streol(parse);
+				eol = bx::strFindEol(parse);
+			}
+			else
+			{
+				eol.set(eol.getPtr(), term.getTerm() );
 			}
 
-			if (NULL != eol)
+			if (!eol.isEmpty() )
 			{
 				const char* precision = NULL;
 				const char* interpolation = NULL;
@@ -1073,7 +1078,7 @@ namespace bgfx
 				||  0 == bx::strCmp(typen, "highp", 5) )
 				{
 					precision = typen;
-					typen = parse = bx::strws(bx::strSkipWord(parse) );
+					typen = parse = bx::strLTrimSpace(bx::strSkipWord(parse) ).getPtr();
 				}
 
 				if (0 == bx::strCmp(typen, "flat", 4)
@@ -1082,21 +1087,21 @@ namespace bgfx
 				||  0 == bx::strCmp(typen, "centroid", 8) )
 				{
 					interpolation = typen;
-					typen = parse = bx::strws(bx::strSkipWord(parse) );
+					typen = parse = bx::strLTrimSpace(bx::strSkipWord(parse) ).getPtr();
 					usesInterpolationQualifiers = true;
 				}
 
-				const char* name      = parse = bx::strws(bx::strSkipWord(parse) );
-				const char* column    = parse = bx::strws(bx::strSkipWord(parse) );
-				const char* semantics = parse = bx::strws( (*parse == ':' ? ++parse : parse) );
-				const char* assign    = parse = bx::strws(bx::strSkipWord(parse) );
-				const char* init      = parse = bx::strws( (*parse == '=' ? ++parse : parse) );
+				const char* name      = parse = bx::strLTrimSpace(bx::strSkipWord(parse) ).getPtr();
+				const char* column    = parse = bx::strLTrimSpace(bx::strSkipWord(parse) ).getPtr();
+				const char* semantics = parse = bx::strLTrimSpace( (*parse == ':' ? ++parse : parse) ).getPtr();
+				const char* assign    = parse = bx::strLTrimSpace(bx::strSkipWord(parse) ).getPtr();
+				const char* init      = parse = bx::strLTrimSpace( (*parse == '=' ? ++parse : parse) ).getPtr();
 
-				if (typen < eol
-				&&  name < eol
-				&&  column < eol
+				if (typen < eol.getPtr()
+				&&  name < eol.getPtr()
+				&&  column < eol.getPtr()
 				&&  ':' == *column
-				&&  semantics < eol)
+				&&  semantics < eol.getPtr() )
 				{
 					Varying var;
 					if (NULL != precision)
@@ -1119,17 +1124,17 @@ namespace bgfx
 						var.m_semantics = "BINORMAL";
 					}
 
-					if (assign < eol
+					if (assign < eol.getPtr()
 					&&  '=' == *assign
-					&&  init < eol)
+					&&  init < eol.getPtr() )
 					{
-						var.m_init.assign(init, eol-init);
+						var.m_init.assign(init, eol.getPtr()-init);
 					}
 
 					varyingMap.insert(std::make_pair(var.m_name, var) );
 				}
 
-				parse = bx::strws(bx::strnl(eol) );
+				parse = bx::strLTrimSpace(bx::strFindNl(eol) ).getPtr();
 			}
 		}
 
@@ -1169,27 +1174,27 @@ namespace bgfx
 
 			strNormalizeEol(data);
 
-			input = const_cast<char*>(bx::strws(data) );
+			input = const_cast<char*>(bx::strLTrimSpace(data).getPtr() );
 			while (input[0] == '$')
 			{
-				const char* str = bx::strws(input+1);
-				const char* eol = bx::streol(str);
-				const char* nl  = bx::strnl(eol);
-				input = const_cast<char*>(nl);
+				const char* str = bx::strLTrimSpace(input+1).getPtr();
+				bx::StringView eol = bx::strFindEol(str);
+				bx::StringView nl  = bx::strFindNl(eol);
+				input = const_cast<char*>(nl.getPtr() );
 
 				if (0 == bx::strCmp(str, "input", 5) )
 				{
 					str += 5;
-					const char* comment = bx::strFind(str, "//");
-					eol = NULL != comment && comment < eol ? comment : eol;
-					inputHash = parseInOut(shaderInputs, str, eol);
+					bx::StringView comment = bx::strFind(str, "//");
+					eol = !comment.isEmpty() && comment.getPtr() < eol.getPtr() ? comment.getPtr() : eol;
+					inputHash = parseInOut(shaderInputs, str, eol.getPtr() );
 				}
 				else if (0 == bx::strCmp(str, "output", 6) )
 				{
 					str += 6;
-					const char* comment = bx::strFind(str, "//");
-					eol = NULL != comment && comment < eol ? comment : eol;
-					outputHash = parseInOut(shaderOutputs, str, eol);
+					bx::StringView comment = bx::strFind(str, "//");
+					eol = !comment.isEmpty() && comment.getPtr() < eol.getPtr() ? comment.getPtr() : eol;
+					outputHash = parseInOut(shaderOutputs, str, eol.getPtr() );
 				}
 				else if (0 == bx::strCmp(str, "raw", 3) )
 				{
@@ -1197,7 +1202,7 @@ namespace bgfx
 					str += 3;
 				}
 
-				input = const_cast<char*>(bx::strws(input) );
+				input = const_cast<char*>(bx::strLTrimSpace(input).getPtr() );
 			}
 		}
 
@@ -1244,8 +1249,8 @@ namespace bgfx
 		}
 		else if ('c' == _options.shaderType) // Compute
 		{
-			char* entry = const_cast<char*>(bx::strFind(input, "void main()") );
-			if (NULL == entry)
+			bx::StringView entry = bx::strFind(input, "void main()");
+			if (entry.isEmpty() )
 			{
 				fprintf(stderr, "Shader entry point 'void main()' is not found.\n");
 			}
@@ -1281,17 +1286,17 @@ namespace bgfx
 						"#define mat4 float4x4\n"
 						);
 
-					entry[4] = '_';
+					*const_cast<char*>(entry.getPtr() + 4) = '_';
 
 					preprocessor.writef("#define void_main()");
 					preprocessor.writef(" \\\n\tvoid main(");
 
 					uint32_t arg = 0;
 
-					const bool hasLocalInvocationID    = NULL != bx::strFind(input, "gl_LocalInvocationID");
-					const bool hasLocalInvocationIndex = NULL != bx::strFind(input, "gl_LocalInvocationIndex");
-					const bool hasGlobalInvocationID   = NULL != bx::strFind(input, "gl_GlobalInvocationID");
-					const bool hasWorkGroupID          = NULL != bx::strFind(input, "gl_WorkGroupID");
+					const bool hasLocalInvocationID    = !bx::strFind(input, "gl_LocalInvocationID").isEmpty();
+					const bool hasLocalInvocationIndex = !bx::strFind(input, "gl_LocalInvocationIndex").isEmpty();
+					const bool hasGlobalInvocationID   = !bx::strFind(input, "gl_GlobalInvocationID").isEmpty();
+					const bool hasWorkGroupID          = !bx::strFind(input, "gl_WorkGroupID").isEmpty();
 
 					if (hasLocalInvocationID)
 					{
@@ -1415,8 +1420,9 @@ namespace bgfx
 		}
 		else // Vertex/Fragment
 		{
-			char* entry = const_cast<char*>(bx::strFind(input, "void main()") );
-			if (NULL == entry)
+			bx::StringView shader(input);
+			bx::StringView entry = bx::strFind(shader, "void main()");
+			if (entry.isEmpty() )
 			{
 				fprintf(stderr, "Shader entry point 'void main()' is not found.\n");
 			}
@@ -1516,21 +1522,21 @@ namespace bgfx
 							);
 					}
 
-					entry[4] = '_';
+					*const_cast<char*>(entry.getPtr() + 4) = '_';
 
 					if ('f' == _options.shaderType)
 					{
-						const char* insert = bx::strFind(entry, "{");
-						if (NULL != insert)
+						bx::StringView insert = bx::strFind(bx::StringView(entry.getPtr(), shader.getTerm() ), "{");
+						if (!insert.isEmpty() )
 						{
-							insert = strInsert(const_cast<char*>(insert+1), "\nvec4 bgfx_VoidFrag = vec4_splat(0.0);\n");
+							insert = strInsert(const_cast<char*>(insert.getPtr()+1), "\nvec4 bgfx_VoidFrag = vec4_splat(0.0);\n");
 						}
 
-						const bool hasFragColor   = NULL != bx::strFind(input, "gl_FragColor");
-						const bool hasFragCoord   = NULL != bx::strFind(input, "gl_FragCoord") || hlsl > 3 || hlsl == 2;
-						const bool hasFragDepth   = NULL != bx::strFind(input, "gl_FragDepth");
-						const bool hasFrontFacing = NULL != bx::strFind(input, "gl_FrontFacing");
-						const bool hasPrimitiveId = NULL != bx::strFind(input, "gl_PrimitiveID");
+						const bool hasFragColor   = !bx::strFind(input, "gl_FragColor").isEmpty();
+						const bool hasFragCoord   = !bx::strFind(input, "gl_FragCoord").isEmpty() || hlsl > 3 || hlsl == 2;
+						const bool hasFragDepth   = !bx::strFind(input, "gl_FragDepth").isEmpty();
+						const bool hasFrontFacing = !bx::strFind(input, "gl_FrontFacing").isEmpty();
+						const bool hasPrimitiveId = !bx::strFind(input, "gl_PrimitiveID").isEmpty();
 
 						bool hasFragData[8] = {};
 						uint32_t numFragData = 0;
@@ -1538,7 +1544,7 @@ namespace bgfx
 						{
 							char temp[32];
 							bx::snprintf(temp, BX_COUNTOF(temp), "gl_FragData[%d]", ii);
-							hasFragData[ii] = NULL != bx::strFind(input, temp);
+							hasFragData[ii] = !bx::strFind(input, temp).isEmpty();
 							numFragData += hasFragData[ii];
 						}
 
@@ -1553,11 +1559,11 @@ namespace bgfx
 							// targets.
 							hasFragData[0] |= hasFragColor || d3d < 11;
 
-							if (NULL != insert
+							if (!insert.isEmpty()
 							&&  d3d < 11
 							&&  !hasFragColor)
 							{
-								insert = strInsert(const_cast<char*>(insert+1), "\ngl_FragColor = bgfx_VoidFrag;\n");
+								insert = strInsert(const_cast<char*>(insert.getPtr()+1), "\ngl_FragColor = bgfx_VoidFrag;\n");
 							}
 						}
 
@@ -1663,13 +1669,13 @@ namespace bgfx
 					}
 					else if ('v' == _options.shaderType)
 					{
-						const bool hasVertexId    = NULL != bx::strFind(input, "gl_VertexID");
-						const bool hasInstanceId  = NULL != bx::strFind(input, "gl_InstanceID");
+						const bool hasVertexId    = !bx::strFind(input, "gl_VertexID").isEmpty();
+						const bool hasInstanceId  = !bx::strFind(input, "gl_InstanceID").isEmpty();
 
-						const char* brace = bx::strFind(entry, "{");
-						if (NULL != brace)
+						bx::StringView brace = bx::strFind(bx::StringView(entry.getPtr(), shader.getTerm() ), "{");
+						if (!brace.isEmpty() )
 						{
-							const char* end = bx::strmb(brace, '{', '}');
+							const char* end = bx::strmb(brace.getPtr(), '{', '}');
 							if (NULL != end)
 							{
 								strInsert(const_cast<char*>(end), "__RETURN__;\n");
@@ -1853,7 +1859,7 @@ namespace bgfx
 						||  0 != essl
 						||  0 != metal)
 						{
-							if (NULL != bx::strFind(preprocessor.m_preprocessed.c_str(), "layout(std430") )
+							if (!bx::strFind(preprocessor.m_preprocessed.c_str(), "layout(std430").isEmpty() )
 							{
 								glsl = 430;
 							}
@@ -1861,21 +1867,21 @@ namespace bgfx
 							if (glsl < 400)
 							{
 								const bool usesTextureLod   = false
-									|| !!bx::findIdentifierMatch(input, s_ARB_shader_texture_lod)
-									|| !!bx::findIdentifierMatch(input, s_EXT_shader_texture_lod)
+									|| !bx::findIdentifierMatch(input, s_ARB_shader_texture_lod).isEmpty()
+									|| !bx::findIdentifierMatch(input, s_EXT_shader_texture_lod).isEmpty()
 									;
-								const bool usesInstanceID   = !!bx::strFind(input, "gl_InstanceID");
-								const bool usesGpuShader4   = !!bx::findIdentifierMatch(input, s_EXT_gpu_shader4);
-								const bool usesGpuShader5   = !!bx::findIdentifierMatch(input, s_ARB_gpu_shader5);
-								const bool usesTexelFetch   = !!bx::findIdentifierMatch(input, s_texelFetch);
-								const bool usesTextureMS    = !!bx::findIdentifierMatch(input, s_ARB_texture_multisample);
-								const bool usesTextureArray = !!bx::findIdentifierMatch(input, s_textureArray);
-								const bool usesPacking      = !!bx::findIdentifierMatch(input, s_ARB_shading_language_packing);
+								const bool usesInstanceID   = !bx::findIdentifierMatch(input, "gl_InstanceID").isEmpty();
+								const bool usesGpuShader4   = !bx::findIdentifierMatch(input, s_EXT_gpu_shader4).isEmpty();
+								const bool usesGpuShader5   = !bx::findIdentifierMatch(input, s_ARB_gpu_shader5).isEmpty();
+								const bool usesTexelFetch   = !bx::findIdentifierMatch(input, s_texelFetch).isEmpty();
+								const bool usesTextureMS    = !bx::findIdentifierMatch(input, s_ARB_texture_multisample).isEmpty();
+								const bool usesTextureArray = !bx::findIdentifierMatch(input, s_textureArray).isEmpty();
+								const bool usesPacking      = !bx::findIdentifierMatch(input, s_ARB_shading_language_packing).isEmpty();
 
 								if (0 == essl)
 								{
 									const bool need130 = 120 == glsl && (false
-										|| bx::findIdentifierMatch(input, s_130)
+										|| !bx::findIdentifierMatch(input, s_130).isEmpty()
 										|| usesInterpolationQualifiers
 										|| usesTexelFetch
 										);
@@ -2072,17 +2078,17 @@ namespace bgfx
 											);
 									}
 
-									if (NULL != bx::findIdentifierMatch(input, s_OES_standard_derivatives) )
+									if (!bx::findIdentifierMatch(input, s_OES_standard_derivatives).isEmpty() )
 									{
 										bx::stringPrintf(code, "#extension GL_OES_standard_derivatives : enable\n");
 									}
 
-									if (NULL != bx::findIdentifierMatch(input, s_OES_texture_3D) )
+									if (!bx::findIdentifierMatch(input, s_OES_texture_3D).isEmpty() )
 									{
 										bx::stringPrintf(code, "#extension GL_OES_texture_3D : enable\n");
 									}
 
-									if (NULL != bx::findIdentifierMatch(input, s_EXT_shadow_samplers) )
+									if (!bx::findIdentifierMatch(input, s_EXT_shadow_samplers).isEmpty() )
 									{
 										bx::stringPrintf(code
 											, "#extension GL_EXT_shadow_samplers : enable\n"
@@ -2105,7 +2111,7 @@ namespace bgfx
 											);
 									}
 
-									if (NULL != bx::findIdentifierMatch(input, "gl_FragDepth") )
+									if (!bx::findIdentifierMatch(input, "gl_FragDepth").isEmpty() )
 									{
 										bx::stringPrintf(code
 											, "#extension GL_EXT_frag_depth : enable\n"
@@ -2357,15 +2363,11 @@ namespace bgfx
 		while (NULL != defines
 		&&    '\0'  != *defines)
 		{
-			defines = bx::strws(defines);
-			const char* eol = bx::strFind(defines, ';');
-			if (NULL == eol)
-			{
-				eol = defines + bx::strLen(defines);
-			}
-			std::string define(defines, eol);
+			defines = bx::strLTrimSpace(defines).getPtr();
+			bx::StringView eol = bx::strFind(defines, ';');
+			std::string define(defines, eol.getPtr() );
 			options.defines.push_back(define.c_str() );
-			defines = ';' == *eol ? eol+1 : eol;
+			defines = ';' == *eol.getPtr() ? eol.getPtr()+1 : eol.getPtr();
 		}
 
 		std::string commandLineComment = "// shaderc command line:\n//";

+ 1 - 1
tools/shaderc/shaderc.h

@@ -89,7 +89,7 @@ namespace bgfx
 
 			uint32_t pos = m_pos;
 			const char* str = &m_str[pos];
-			const char* nl = bx::strnl(str);
+			const char* nl = bx::strFindNl(str).getPtr();
 			pos += (uint32_t)(nl - str);
 
 			const char* eol = &m_str[pos];

+ 40 - 38
tools/shaderc/shaderc_glsl.cpp

@@ -72,7 +72,7 @@ namespace bgfx { namespace glsl
 		// Trim all directives.
 		while ('#' == *optimizedShader)
 		{
-			optimizedShader = bx::strnl(optimizedShader);
+			optimizedShader = bx::strFindNl(optimizedShader).getPtr();
 		}
 
 		{
@@ -107,14 +107,14 @@ namespace bgfx { namespace glsl
 			const char* parse = optimizedShader;
 
 			while (NULL != parse
-				&&  *parse != '\0')
+				&& *parse != '\0')
 			{
-				parse = bx::strws(parse);
-				const char* eol = bx::strFind(parse, ';');
-				if (NULL != eol)
+				parse = bx::strLTrimSpace(parse).getPtr();
+				const bx::StringView eol = bx::strFind(parse, ';');
+				if (!eol.isEmpty() )
 				{
 					const char* qualifier = parse;
-					parse = bx::strws(bx::strSkipWord(parse) );
+					parse = bx::strLTrimSpace(bx::strSkipWord(parse) ).getPtr();
 
 					if (0 == bx::strCmp(qualifier, "attribute", 9)
 					||  0 == bx::strCmp(qualifier, "varying",   7)
@@ -123,14 +123,14 @@ namespace bgfx { namespace glsl
 					   )
 					{
 						// skip attributes and varyings.
-						parse = eol + 1;
+						parse = eol.getPtr() + 1;
 						continue;
 					}
 
 					if (0 == bx::strCmp(parse, "tmpvar", 6) )
 					{
 						// skip temporaries
-						parse = eol + 1;
+						parse = eol.getPtr() + 1;
 						continue;
 					}
 
@@ -149,7 +149,7 @@ namespace bgfx { namespace glsl
 					||  0 == bx::strCmp(typen, "highp", 5) )
 					{
 						precision = typen;
-						typen = parse = bx::strws(bx::strSkipWord(parse) );
+						typen = parse = bx::strLTrimSpace(bx::strSkipWord(parse) ).getPtr();
 					}
 
 					BX_UNUSED(precision);
@@ -166,23 +166,23 @@ namespace bgfx { namespace glsl
 						bx::strCopy(uniformType, int32_t(parse-typen+1), typen);
 					}
 
-					const char* name = parse = bx::strws(parse);
+					const char* name = parse = bx::strLTrimSpace(parse).getPtr();
 
 					char uniformName[256];
 					uint8_t num = 1;
-					const char* array = bx::strFind(bx::StringView(name, int32_t(eol-parse) ), "[");
-					if (NULL != array)
+					bx::StringView array = bx::strFind(bx::StringView(name, int32_t(eol.getPtr()-parse) ), "[");
+					if (!array.isEmpty() )
 					{
-						bx::strCopy(uniformName, int32_t(array-name+1), name);
+						bx::strCopy(uniformName, int32_t(array.getPtr()-name+1), name);
 
 						char arraySize[32];
-						const char* end = bx::strFind(bx::StringView(array, int32_t(eol-array) ), "]");
-						bx::strCopy(arraySize, int32_t(end-array), array+1);
+						bx::StringView end = bx::strFind(bx::StringView(array.getPtr(), int32_t(eol.getPtr()-array.getPtr() ) ), "]");
+						bx::strCopy(arraySize, int32_t(end.getPtr()-array.getPtr() ), array.getPtr()+1);
 						num = uint8_t(atoi(arraySize) );
 					}
 					else
 					{
-						bx::strCopy(uniformName, int32_t(eol-name+1), name);
+						bx::strCopy(uniformName, int32_t(eol.getPtr() -name+1), name);
 					}
 
 					Uniform un;
@@ -199,49 +199,51 @@ namespace bgfx { namespace glsl
 						uniforms.push_back(un);
 					}
 
-					parse = eol + 1;
+					parse = eol.getPtr() + 1;
 				}
 			}
 		}
 		else
 		{
-			const char* parse = bx::strFind(optimizedShader, "struct xlatMtlShaderUniform {");
-			const char* end   = parse;
-			if (NULL != parse)
+			const bx::StringView optShader(optimizedShader);
+			bx::StringView parse = bx::strFind(optimizedShader, "struct xlatMtlShaderUniform {");
+			bx::StringView end   = parse;
+			if (!parse.isEmpty() )
 			{
-				parse += bx::strLen("struct xlatMtlShaderUniform {");
-				end   =  bx::strFind(parse, "};");
+				parse.set(parse.getPtr() + bx::strLen("struct xlatMtlShaderUniform {"), optShader.getTerm() );
+				end = bx::strFind(parse, "};");
 			}
 
-			while ( parse < end
-			&&     *parse != '\0')
+			while ( parse.getPtr() < end.getPtr()
+			&&     !parse.isEmpty() )
 			{
-				parse = bx::strws(parse);
-				const char* eol = bx::strFind(parse, ';');
-				if (NULL != eol)
+				parse.set(bx::strLTrimSpace(parse).getPtr(), optShader.getTerm() );
+				const bx::StringView eol = bx::strFind(parse, ';');
+				if (!eol.isEmpty() )
 				{
-					const char* typen = parse;
+					const char* typen = parse.getPtr();
 
 					char uniformType[256];
-					parse = bx::strSkipWord(parse);
-					bx::strCopy(uniformType, int32_t(parse-typen+1), typen);
-					const char* name = parse = bx::strws(parse);
+					parse = bx::strSkipWord(parse.getPtr() );
+					bx::strCopy(uniformType, int32_t(parse.getPtr()-typen+1), typen);
+					const char* name = bx::strLTrimSpace(parse).getPtr();
+					parse.set(name, optShader.getTerm() );
 
 					char uniformName[256];
 					uint8_t num = 1;
-					const char* array = bx::strFind(bx::StringView(name, int32_t(eol-parse) ), "[");
-					if (NULL != array)
+					bx::StringView array = bx::strFind(bx::StringView(name, int32_t(eol.getPtr()-parse.getPtr() ) ), "[");
+					if (!array.isEmpty() )
 					{
-						bx::strCopy(uniformName, int32_t(array-name+1), name);
+						bx::strCopy(uniformName, int32_t(array.getPtr()-name+1), name);
 
 						char arraySize[32];
-						const char* arrayEnd = bx::strFind(bx::StringView(array, int32_t(eol-array) ), "]");
-						bx::strCopy(arraySize, int32_t(arrayEnd-array), array+1);
+						bx::StringView arrayEnd = bx::strFind(bx::StringView(array.getPtr(), int32_t(eol.getPtr()-array.getPtr() ) ), "]");
+						bx::strCopy(arraySize, int32_t(arrayEnd.getPtr()-array.getPtr() ), array.getPtr()+1);
 						num = uint8_t(atoi(arraySize) );
 					}
 					else
 					{
-						bx::strCopy(uniformName, int32_t(eol-name+1), name);
+						bx::strCopy(uniformName, int32_t(eol.getPtr()-name+1), name);
 					}
 
 					Uniform un;
@@ -258,7 +260,7 @@ namespace bgfx { namespace glsl
 						uniforms.push_back(un);
 					}
 
-					parse = eol + 1;
+					parse = eol.getPtr() + 1;
 				}
 			}
 		}

+ 7 - 7
tools/shaderc/shaderc_hlsl.cpp

@@ -522,11 +522,11 @@ namespace bgfx { namespace hlsl
 						, bindDesc.BindCount
 						);
 
-					const char * end = bx::strFind(bindDesc.Name, "Sampler");
-					if (NULL != end)
+					bx::StringView end = bx::strFind(bindDesc.Name, "Sampler");
+					if (!end.isEmpty() )
 					{
 						Uniform un;
-						un.name.assign(bindDesc.Name, (end - bindDesc.Name) );
+						un.name.assign(bindDesc.Name, (end.getPtr() - bindDesc.Name) );
 						un.type = UniformType::Enum(BGFX_UNIFORM_SAMPLERBIT | UniformType::Int1);
 						un.num = 1;
 						un.regIndex = uint16_t(bindDesc.BindPoint);
@@ -626,10 +626,10 @@ namespace bgfx { namespace hlsl
 
 			if (!hlslfp.empty())
 			{
-				const char* logfp = bx::strFind(log, hlslfp.c_str());
-				if (NULL != logfp)
+				bx::StringView logfp = bx::strFind(log, hlslfp.c_str() );
+				if (!logfp.isEmpty() )
 				{
-					log = logfp + hlslfp.length();
+					log = logfp.getPtr() + hlslfp.length();
 				}
 			}
 
@@ -703,7 +703,7 @@ namespace bgfx { namespace hlsl
 							// included in the uniform blob that the application must upload
 							// we can't just remove them, because unused functions might still reference
 							// them and cause a compile error when they're gone
-							if (!!bx::findIdentifierMatch(strLine.c_str(), it->c_str() ) )
+							if (!bx::findIdentifierMatch(strLine.c_str(), it->c_str() ).isEmpty() )
 							{
 								strLine = strLine.replace(index, strLength, "static");
 								unusedUniforms.erase(it);

+ 4 - 4
tools/shaderc/shaderc_spirv.cpp

@@ -629,13 +629,13 @@ namespace bgfx { namespace spirv
 				int32_t start   = 0;
 				int32_t end     = INT32_MAX;
 
-				const char* err = bx::strFind(log, "ERROR:");
+				bx::StringView err = bx::strFind(log, "ERROR:");
 
 				bool found = false;
 
-				if (NULL != err)
+				if (!err.isEmpty() )
 				{
-					found = 2 == sscanf(err, "ERROR: %u:%u: '", &source, &line);
+					found = 2 == sscanf(err.getPtr(), "ERROR: %u:%u: '", &source, &line);
 					if (found)
 					{
 						++line;
@@ -703,7 +703,7 @@ namespace bgfx { namespace spirv
 									// included in the uniform blob that the application must upload
 									// we can't just remove them, because unused functions might still reference
 									// them and cause a compile error when they're gone
-									if (!!bx::findIdentifierMatch(strLine.c_str(), program->getUniformName(ii) ) )
+									if (!bx::findIdentifierMatch(strLine.c_str(), program->getUniformName(ii) ).isEmpty() )
 									{
 										found = true;
 										break;

+ 4 - 3
tools/texturev/texturev.cpp

@@ -634,10 +634,11 @@ struct View
 			{
 				if (0 == (item->d_type & DT_DIR) )
 				{
-					const char* ext = bx::strRFind(item->d_name, '.');
-					if (NULL != ext)
+					const bx::StringView fileName(item->d_name);
+					bx::StringView ext = bx::strRFind(fileName, '.');
+					if (!ext.isEmpty() )
 					{
-						ext += 1;
+						ext.set(ext.getPtr()+1, fileName.getTerm() );
 						bool supported = false;
 						for (uint32_t ii = 0; ii < BX_COUNTOF(s_supportedExt); ++ii)
 						{