475 if text.startswith(patn): |
475 if text.startswith(patn): |
476 return text |
476 return text |
477 return '' |
477 return '' |
478 |
478 |
479 |
479 |
|
480 def word(context, mapping, args): |
|
481 """return nth word from a string""" |
|
482 if not (2 <= len(args) <= 3): |
|
483 raise error.ParseError(_("word expects two or three arguments, got %d") |
|
484 % len(args)) |
|
485 |
|
486 num = int(stringify(args[0][0](context, mapping, args[0][1]))) |
|
487 text = stringify(args[1][0](context, mapping, args[1][1])) |
|
488 if len(args) == 3: |
|
489 splitter = stringify(args[2][0](context, mapping, args[2][1])) |
|
490 else: |
|
491 splitter = None |
|
492 |
|
493 tokens = text.split(splitter) |
|
494 if num >= len(tokens): |
|
495 return '' |
|
496 else: |
|
497 return tokens[num] |
|
498 |
480 methods = { |
499 methods = { |
481 "string": lambda e, c: (runstring, e[1]), |
500 "string": lambda e, c: (runstring, e[1]), |
482 "rawstring": lambda e, c: (runrawstring, e[1]), |
501 "rawstring": lambda e, c: (runrawstring, e[1]), |
483 "symbol": lambda e, c: (runsymbol, e[1]), |
502 "symbol": lambda e, c: (runsymbol, e[1]), |
484 "group": lambda e, c: compileexp(e[1], c), |
503 "group": lambda e, c: compileexp(e[1], c), |