Parse a StringBuilder and take out the param type token. Called from requestHandler @param cmd a value of type 'StringBuilder' @param start index on which parsing will start @return an array with the parameter names
(StringBuilder cmd, int start)
| 196 | * @return an array with the parameter names |
| 197 | */ |
| 198 | protected String[] parseParamNames(StringBuilder cmd, int start) { |
| 199 | // Count parameters first |
| 200 | int count = 0; |
| 201 | int bIdx = start; |
| 202 | // Tracks the quote character that will close any currently quoted text. 0 means not currently quoted. |
| 203 | char endQuote = 0; |
| 204 | boolean escaped = false; |
| 205 | while (bIdx < cmd.length()) { |
| 206 | char c = cmd.charAt(bIdx); |
| 207 | if (escaped) { |
| 208 | escaped = false; |
| 209 | } else if (c == '\\') { |
| 210 | escaped = true; |
| 211 | } else if (endQuote == 0 && (c == '"' || c == '\'' || c == '`')) { |
| 212 | endQuote = c; |
| 213 | } else if (endQuote == c) { |
| 214 | endQuote = 0; |
| 215 | } else if (c == '=' && endQuote == 0) { |
| 216 | count++; |
| 217 | } |
| 218 | bIdx++; |
| 219 | } |
| 220 | String[] retString = new String[count]; |
| 221 | // Extract parameter names (characters between spaces and the first unquoted '=') |
| 222 | bIdx = start; |
| 223 | int idx = 0; |
| 224 | StringBuilder nameBuf = new StringBuilder(); |
| 225 | boolean collectingName = false; |
| 226 | endQuote = 0; |
| 227 | escaped = false; |
| 228 | while (bIdx < cmd.length() && idx < count) { |
| 229 | char c = cmd.charAt(bIdx); |
| 230 | if (escaped) { |
| 231 | escaped = false; |
| 232 | if (collectingName && endQuote == 0) { |
| 233 | nameBuf.append(c); |
| 234 | } |
| 235 | } else if (c == '\\') { |
| 236 | escaped = true; |
| 237 | if (collectingName && endQuote == 0) { |
| 238 | nameBuf.append(c); |
| 239 | } |
| 240 | } else if (endQuote == 0 && (c == '"' || c == '\'' || c == '`')) { |
| 241 | endQuote = c; |
| 242 | } else if (endQuote == c) { |
| 243 | endQuote = 0; |
| 244 | } else if (endQuote == 0 && isSpace(c)) { |
| 245 | if (collectingName) { |
| 246 | nameBuf.setLength(0); |
| 247 | collectingName = false; |
| 248 | } |
| 249 | } else if (endQuote == 0 && c == '=') { |
| 250 | retString[idx++] = nameBuf.toString().trim(); |
| 251 | nameBuf.setLength(0); |
| 252 | collectingName = false; |
| 253 | } else if (endQuote == 0) { |
| 254 | collectingName = true; |
| 255 | nameBuf.append(c); |