Share ArrayString and Str helper methods.

Placing these string helper methods allows us to re-use them in
the relevant place of the shader translator.

BUG=angle:466

Change-Id: Idd638542027d3b1035bc79fc941e80bf436c82af
Reviewed-on: https://chromium-review.googlesource.com/206567
Reviewed-by: Nicolas Capens <capn@chromium.org>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/common/angleutils.h b/src/common/angleutils.h
index 1cec920..ec9afe8 100644
--- a/src/common/angleutils.h
+++ b/src/common/angleutils.h
@@ -14,6 +14,7 @@
 #include <stddef.h>
 #include <string>
 #include <set>
+#include <sstream>
 
 // A macro to disallow the copy constructor and operator= functions
 // This must be used in the private: declarations for a class
@@ -115,6 +116,31 @@
     return strings.insert(str).first->c_str();
 }
 
+inline std::string ArrayString(unsigned int i)
+{
+    // We assume UINT_MAX and GL_INVALID_INDEX are equal
+    // See DynamicHLSL.cpp
+    if (i == UINT_MAX)
+    {
+        return "";
+    }
+
+    std::stringstream strstr;
+
+    strstr << "[";
+    strstr << i;
+    strstr << "]";
+
+    return strstr.str();
+}
+
+inline std::string Str(int i)
+{
+    std::stringstream strstr;
+    strstr << i;
+    return strstr.str();
+}
+
 #if defined(_MSC_VER)
 #define snprintf _snprintf
 #endif
diff --git a/src/libGLESv2/DynamicHLSL.cpp b/src/libGLESv2/DynamicHLSL.cpp
index c32b407..78cbf15 100644
--- a/src/libGLESv2/DynamicHLSL.cpp
+++ b/src/libGLESv2/DynamicHLSL.cpp
@@ -17,12 +17,8 @@
 #include "libGLESv2/formatutils.h"
 #include "common/blocklayout.h"
 
-static std::string Str(int i)
-{
-    char buffer[20];
-    snprintf(buffer, sizeof(buffer), "%d", i);
-    return buffer;
-}
+// For use with ArrayString, see angleutils.h
+META_ASSERT(GL_INVALID_INDEX == UINT_MAX);
 
 namespace gl_d3d
 {
@@ -77,11 +73,6 @@
 namespace gl
 {
 
-std::string ArrayString(unsigned int i)
-{
-    return (i == GL_INVALID_INDEX ? "" : "[" + Str(i) + "]");
-}
-
 const std::string VERTEX_ATTRIBUTE_STUB_STRING = "@@ VERTEX ATTRIBUTES @@";
 const std::string PIXEL_OUTPUT_STUB_STRING = "@@ PIXEL OUTPUT @@";
 
diff --git a/src/libGLESv2/DynamicHLSL.h b/src/libGLESv2/DynamicHLSL.h
index 4309dc8..68abd6e 100644
--- a/src/libGLESv2/DynamicHLSL.h
+++ b/src/libGLESv2/DynamicHLSL.h
@@ -91,9 +91,6 @@
     std::string generateAttributeConversionHLSL(const VertexFormat &vertexFormat, const sh::ShaderVariable &shaderAttrib) const;
 };
 
-// Utility method shared between ProgramBinary and DynamicHLSL
-std::string ArrayString(unsigned int i);
-
 }
 
 #endif // LIBGLESV2_DYNAMIC_HLSL_H_