str.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright David Abrahams 2004. Distributed under the Boost
  2. # Software License, Version 1.0. (See accompanying
  3. # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. from __future__ import print_function
  5. """
  6. >>> from str_ext import *
  7. >>> def printer(*args):
  8. ... for x in args: print(x, end='')
  9. ... print('')
  10. ...
  11. >>> work_with_string(printer) #doctest: +NORMALIZE_WHITESPACE
  12. ['this', 'is', 'a', 'demo', 'string']
  13. ['this', 'is', 'a', 'demo string']
  14. this<->is<->a<->demo<->string
  15. This is a demo string
  16. [ this is a demo string ]
  17. 2
  18. this is a demo string
  19. this is a demo string
  20. ['this is a demo string']
  21. this is a demo string
  22. THIS IS A DEMO STRING
  23. This Is A Demo String
  24. find
  25. 10
  26. 10 3 5
  27. 10
  28. 10
  29. expandtabs
  30. tab demo !
  31. tab demo !
  32. tab demo !
  33. operators
  34. part1part2
  35. this is a blabla string
  36. 18
  37. 18
  38. aaaaaaaaaaaaaaaaaaaaa
  39. """
  40. def run(args = None):
  41. import sys
  42. import doctest
  43. if args is not None:
  44. sys.argv = args
  45. return doctest.testmod(sys.modules.get(__name__))
  46. if __name__ == '__main__':
  47. print("running...")
  48. import sys
  49. status = run()[0]
  50. if (status == 0): print("Done.")
  51. sys.exit(status)