Просмотр исходного кода

Improve detection of a function call

Popov72 4 лет назад
Родитель
Сommit
48f98a4013
1 измененных файлов с 14 добавлено и 0 удалено
  1. 14 0
      src/Engines/Processors/shaderCodeInliner.ts

+ 14 - 0
src/Engines/Processors/shaderCodeInliner.ts

@@ -239,6 +239,14 @@ export class ShaderCodeInliner {
         return index;
     }
 
+    private _isIdentifierChar(c: string): boolean {
+        const v = c.charCodeAt(0);
+        return (v >= 48 && v <= 57) || // 0-9
+            (v >= 65 && v <= 90) || // A-Z
+            (v >= 97 && v <= 122) || // a-z
+            (v == 95); // _
+    }
+
     private _removeComments(block: string): string {
         let currPos = 0,
             waitForChar = '',
@@ -315,6 +323,12 @@ export class ShaderCodeInliner {
                     break;
                 }
 
+                // Make sure "name" is not part of a bigger string
+                if (functionCallIndex === 0 || this._isIdentifierChar(this._sourceCode.charAt(functionCallIndex - 1))) {
+                    startIndex = functionCallIndex + name.length;
+                    continue;
+                }
+
                 // Find the opening parenthesis
                 const callParamsStartIndex = this._skipWhitespaces(this._sourceCode, functionCallIndex + name.length);
                 if (callParamsStartIndex === this._sourceCode.length || this._sourceCode.charAt(callParamsStartIndex) !== '(') {