str.qbk 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. [section boost/python/str.hpp]
  2. [section Introduction]
  3. Exposes a [link concepts.objectwrapper.typewrapper_concept_requirements TypeWrapper] for the Python [@http://www.python.org/dev/doc/devel/lib/string-methods.html `str`] type.
  4. [endsect]
  5. [section Class `str`]
  6. Exposes the [@http://www.python.org/dev/doc/devel/lib/string-methods.html string methods] of Python's built-in `str` type. The semantics of the constructors and member functions defined below, except for the two-argument constructors which construct str objects from a range of characters, can be fully understood by reading the [link concepts.objectwrapper.typewrapper_concept_requirements TypeWrapper] concept definition. Since str is publicly derived from [link object_wrappers.boost_python_object_hpp.class_object `object`], the public `object` interface applies to `str` instances as well.
  7. ``
  8. namespace boost { namespace python
  9. {
  10. class str : public object
  11. {
  12. public:
  13. str(); // new str
  14. str(char const* s); // new str
  15. str(char const* start, char const* finish); // new str
  16. str(char const* start, std::size_t length); // new str
  17. template <class T>
  18. explicit str(T const& other);
  19. str capitalize() const;
  20. template <class T>
  21. str center(T const& width) const;
  22. template<class T>
  23. long count(T const& sub) const;
  24. template<class T1, class T2>
  25. long count(T1 const& sub,T2 const& start) const;
  26. template<class T1, class T2, class T3>
  27. long count(T1 const& sub,T2 const& start, T3 const& end) const;
  28. object decode() const;
  29. template<class T>
  30. object decode(T const& encoding) const;
  31. template<class T1, class T2>
  32. object decode(T1 const& encoding, T2 const& errors) const;
  33. object encode() const;
  34. template <class T>
  35. object encode(T const& encoding) const;
  36. template <class T1, class T2>
  37. object encode(T1 const& encoding, T2 const& errors) const;
  38. template <class T>
  39. bool endswith(T const& suffix) const;
  40. template <class T1, class T2>
  41. bool endswith(T1 const& suffix, T2 const& start) const;
  42. template <class T1, class T2, class T3>
  43. bool endswith(T1 const& suffix, T2 const& start, T3 const& end) const;
  44. str expandtabs() const;
  45. template <class T>
  46. str expandtabs(T const& tabsize) const;
  47. template <class T>
  48. long find(T const& sub) const;
  49. template <class T1, class T2>
  50. long find(T1 const& sub, T2 const& start) const;
  51. template <class T1, class T2, class T3>
  52. long find(T1 const& sub, T2 const& start, T3 const& end) const;
  53. template <class T>
  54. long index(T const& sub) const;
  55. template <class T1, class T2>
  56. long index(T1 const& sub, T2 const& start) const;
  57. template <class T1, class T2, class T3>
  58. long index(T1 const& sub, T2 const& start, T3 const& end) const;
  59. bool isalnum() const;
  60. bool isalpha() const;
  61. bool isdigit() const;
  62. bool islower() const;
  63. bool isspace() const;
  64. bool istitle() const;
  65. bool isupper() const;
  66. template <class T>
  67. str join(T const& sequence) const;
  68. template <class T>
  69. str ljust(T const& width) const;
  70. str lower() const;
  71. str lstrip() const;
  72. template <class T1, class T2>
  73. str replace(T1 const& old, T2 const& new_) const;
  74. template <class T1, class T2, class T3>
  75. str replace(T1 const& old, T2 const& new_, T3 const& maxsplit) const;
  76. template <class T>
  77. long rfind(T const& sub) const;
  78. template <class T1, class T2>
  79. long rfind(T1 const& sub, T2 const& start) const;
  80. template <class T1, class T2, class T3>
  81. long rfind(T1 const& sub, T2 const& start, T3 const& end) const;
  82. template <class T>
  83. long rindex(T const& sub) const;
  84. template <class T1, class T2>
  85. long rindex(T1 const& sub, T2 const& start) const;
  86. template <class T1, class T2, class T3>
  87. long rindex(T1 const& sub, T2 const& start, T3 const& end) const;
  88. template <class T>
  89. str rjust(T const& width) const;
  90. str rstrip() const;
  91. list split() const;
  92. template <class T>
  93. list split(T const& sep) const;
  94. template <class T1, class T2>
  95. list split(T1 const& sep, T2 const& maxsplit) const;
  96. list splitlines() const;
  97. template <class T>
  98. list splitlines(T const& keepends) const;
  99. template <class T>
  100. bool startswith(T const& prefix) const;
  101. template <class T1, class T2>
  102. bool startswidth(T1 const& prefix, T2 const& start) const;
  103. template <class T1, class T2, class T3>
  104. bool startswidth(T1 const& prefix, T2 const& start, T3 const& end) const;
  105. str strip() const;
  106. str swapcase() const;
  107. str title() const;
  108. template <class T>
  109. str translate(T const& table) const;
  110. template <class T1, class T2>
  111. str translate(T1 const& table, T2 const& deletechars) const;
  112. str upper() const;
  113. };
  114. }}
  115. ``
  116. [endsect]
  117. [section Example]
  118. ``
  119. using namespace boost::python;
  120. str remove_angle_brackets(str x)
  121. {
  122. return x.strip('<').strip('>');
  123. }
  124. ``
  125. [endsect]
  126. [endsect]