Refactor uniform array name parsing to a utility function.

BUG=angleproject:882

Change-Id: I00fd6d3cfaa107561cee5e4c82d3c60438052963
Reviewed-on: https://chromium-review.googlesource.com/265723
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Kenneth Russell <kbr@chromium.org>
Tested-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/common/utilities.cpp b/src/common/utilities.cpp
index 501e9c2..a5332e3 100644
--- a/src/common/utilities.cpp
+++ b/src/common/utilities.cpp
@@ -462,6 +462,37 @@
     }
 }
 
+std::string ParseUniformName(const std::string &name, size_t *outSubscript)
+{
+    // Strip any trailing array operator and retrieve the subscript
+    size_t open = name.find_last_of('[');
+    size_t close = name.find_last_of(']');
+    bool hasIndex = (open != std::string::npos) && (close == name.length() - 1);
+    if (!hasIndex)
+    {
+        if (outSubscript)
+        {
+            *outSubscript = GL_INVALID_INDEX;
+        }
+        return name;
+    }
+
+    if (outSubscript)
+    {
+        int index = atoi(name.substr(open + 1).c_str());
+        if (index >= 0)
+        {
+            *outSubscript = index;
+        }
+        else
+        {
+            *outSubscript = GL_INVALID_INDEX;
+        }
+    }
+
+    return name.substr(0, open);
+}
+
 }
 
 #if !defined(ANGLE_ENABLE_WINDOWS_STORE)