MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / parseFuncParams

Function parseFuncParams

web/pgadmin/static/js/utils.js:113–177  ·  view source on GitHub ↗
(label)

Source from the content-addressed store, hash-verified

111}
112
113export function parseFuncParams(label) {
114 let paramArr = [],
115 funcName = '',
116 paramStr = '';
117
118 if(label.endsWith('()')) {
119 funcName = label.substring(0, label.length-2);
120 } else if(!label.endsWith(')')) {
121 funcName = label;
122 } else if(!label.endsWith('()') && label.endsWith(')')) {
123 let i = 0,
124 startBracketPos = label.length;
125
126 /* Parse through the characters in reverse to find the param start bracket */
127 i = label.length-2;
128 while(i >= 0) {
129 if(label[i] == '(') {
130 startBracketPos = i;
131 break;
132 } else if(label[i] == '"') {
133 /* If quotes, skip all the chars till next quote */
134 i--;
135 while(label[i] != '"') i--;
136 }
137 i--;
138 }
139
140 funcName = label.substring(0, startBracketPos);
141 paramStr = label.substring(startBracketPos+1, label.length-1);
142
143 let paramStart = 0,
144 paramName = '',
145 paramModes = ['IN', 'OUT', 'INOUT', 'VARIADIC'];
146
147 i = 0;
148 while(i < paramStr.length) {
149 if(paramStr[i] == '"') {
150 /* If quotes, skip all the chars till next quote */
151 i++;
152 while(paramStr[i] != '"') i++;
153 } else if (paramStr[i] == ' ') {
154 /* if paramName is already set, ignore till comma
155 * Or if paramName is parsed as one of the modes, reset.
156 */
157 if(paramName == '' || paramModes.indexOf(paramName) > -1 ) {
158 paramName = paramStr.substring(paramStart, i);
159 paramStart = i+1;
160 }
161 }
162 else if (paramStr[i] == ',') {
163 paramArr.push([paramName, paramStr.substring(paramStart, i)]);
164 paramName = '';
165 paramStart = i+1;
166 }
167 i++;
168 }
169 paramArr.push([paramName, paramStr.substring(paramStart)]);
170 }

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected