eric7/DebugClients/Python/DebugUtilities.py

branch
eric7
changeset 8921
8459c7e1b904
parent 8881
54e42bc2437a
child 8925
8375eb895f70
equal deleted inserted replaced
8920:fe16c3cf165d 8921:8459c7e1b904
395 @return list of command arguments 395 @return list of command arguments
396 @rtype list of str 396 @rtype list of str
397 @exception RuntimeError raised to indicate an illegal arguments parsing 397 @exception RuntimeError raised to indicate an illegal arguments parsing
398 condition 398 condition
399 """ 399 """
400 # see http:#msdn.microsoft.com/en-us/library/a1y7w461.aspx 400 # see http://msdn.microsoft.com/en-us/library/a1y7w461.aspx
401 result = [] 401 result = []
402 402
403 DEFAULT = 0 403 DEFAULT = 0
404 ARG = 1 404 ARG = 1
405 IN_DOUBLE_QUOTE = 2 405 IN_DOUBLE_QUOTE = 2
407 state = DEFAULT 407 state = DEFAULT
408 backslashes = 0 408 backslashes = 0
409 buf = '' 409 buf = ''
410 410
411 argsLen = len(args) 411 argsLen = len(args)
412 for i in range(argsLen): 412 i=0
413 while i < argsLen:
413 ch = args[i] 414 ch = args[i]
414 if ch == '\\': 415 if ch == '\\':
415 backslashes += 1 416 backslashes += 1
417 i += 1
416 continue 418 continue
417 elif backslashes != 0: 419 elif backslashes != 0:
418 if ch == '"': 420 if ch == '"':
419 while backslashes >= 2: 421 while backslashes >= 2:
420 backslashes -= 2 422 backslashes -= 2
423 if state == DEFAULT: 425 if state == DEFAULT:
424 state = ARG 426 state = ARG
425 427
426 buf += '"' 428 buf += '"'
427 backslashes = 0 429 backslashes = 0
430 i += 1
428 continue 431 continue
429 else: 432 else:
430 # false alarm, treat passed backslashes literally... 433 # false alarm, treat passed backslashes literally...
431 if state == DEFAULT: 434 if state == DEFAULT:
432 state = ARG 435 state = ARG
436 buf += '\\' 439 buf += '\\'
437 440
438 if ch in (' ', '\t'): 441 if ch in (' ', '\t'):
439 if state == DEFAULT: 442 if state == DEFAULT:
440 # skip 443 # skip
444 i += 1
441 continue 445 continue
442 elif state == ARG: 446 elif state == ARG:
443 state = DEFAULT 447 state = DEFAULT
444 result.append(buf) 448 result.append(buf)
445 buf = '' 449 buf = ''
450 i += 1
446 continue 451 continue
447 452
448 if state not in (DEFAULT, ARG, IN_DOUBLE_QUOTE): 453 if state not in (DEFAULT, ARG, IN_DOUBLE_QUOTE):
449 raise RuntimeError('Illegal condition') 454 raise RuntimeError('Illegal condition')
450 455
468 if ch == '"': 473 if ch == '"':
469 state = IN_DOUBLE_QUOTE 474 state = IN_DOUBLE_QUOTE
470 else: 475 else:
471 state = ARG 476 state = ARG
472 buf += ch 477 buf += ch
478
479 i += 1
473 480
474 if len(buf) > 0 or state != DEFAULT: 481 if len(buf) > 0 or state != DEFAULT:
475 result.append(buf) 482 result.append(buf)
476 483
477 return result 484 return result

eric ide

mercurial