Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Boost.Python - <boost/python/str.hpp>

Boost.Python

Header

Contents

Introduction
Classes
Class str
Class str synopsis
Example(s)

Introduction

Exposes a TypeWrapper for the Python str type.

Classes

Class str

Exposes the 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 TypeWrapper concept definition. Since str is publicly derived from object, the public object interface applies to str instances as well.

Class str synopsis

namespace boost { namespace python
{
  class str : public object
  {
   public:
      str(); // new str

      str(char const* s); // new str

      str(char const* start, char const* finish); // new str
      str(char const* start, std::size_t length); // new str

      template 
      explicit str(T const& other);

      str capitalize() const;

      template 
      str center(T const& width) const;

      template
      long count(T const& sub) const;
      template
      long count(T1 const& sub,T2 const& start) const;
      template
      long count(T1 const& sub,T2 const& start, T3 const& end) const;

      object decode() const;
      template
      object decode(T const& encoding) const;
      template
      object decode(T1 const& encoding, T2 const& errors) const;

      object encode() const;
      template 
      object encode(T const& encoding) const;
      template 
      object encode(T1 const& encoding, T2 const& errors) const;

      template 
      bool endswith(T const& suffix) const;
      template 
      bool endswith(T1 const& suffix, T2 const& start) const;
      template 
      bool endswith(T1 const& suffix, T2 const& start, T3 const& end) const;

      str expandtabs() const;
      template 
      str expandtabs(T const& tabsize) const;

      template 
      long find(T const& sub) const;
      template 
      long find(T1 const& sub, T2 const& start) const;
      template 
      long find(T1 const& sub, T2 const& start, T3 const& end) const;

      template 
      long index(T const& sub) const;
      template 
      long index(T1 const& sub, T2 const& start) const;
      template 
      long index(T1 const& sub, T2 const& start, T3 const& end) const;

      bool isalnum() const;
      bool isalpha() const;
      bool isdigit() const;
      bool islower() const;
      bool isspace() const;
      bool istitle() const;
      bool isupper() const;

      template 
      str join(T const& sequence) const;

      template 
      str ljust(T const& width) const;

      str lower() const;
      str lstrip() const;

      template 
      str replace(T1 const& old, T2 const& new_) const;
      template 
      str replace(T1 const& old, T2 const& new_, T3 const& maxsplit) const;

      template 
      long rfind(T const& sub) const;
      template 
      long rfind(T1 const& sub, T2 const& start) const;
      template 
      long rfind(T1 const& sub, T2 const& start, T3 const& end) const;

      template 
      long rindex(T const& sub) const;
      template 
      long rindex(T1 const& sub, T2 const& start) const;
      template 
      long rindex(T1 const& sub, T2 const& start, T3 const& end) const;

      template 
      str rjust(T const& width) const;

      str rstrip() const;

      list split() const; 
      template 
      list split(T const& sep) const;
      template 
      list split(T1 const& sep, T2 const& maxsplit) const;

      list splitlines() const;
      template 
      list splitlines(T const& keepends) const;

      template 
      bool startswith(T const& prefix) const;
      template 
      bool startswidth(T1 const& prefix, T2 const& start) const;
      template 
      bool startswidth(T1 const& prefix, T2 const& start, T3 const& end) const;

      str strip() const;
      str swapcase() const;
      str title() const;

      template 
      str translate(T const& table) const;
      template 
      str translate(T1 const& table, T2 const& deletechars) const;

      str upper() const;
  };
}}

Example

using namespace boost::python;
str remove_angle_brackets(str x)
{
  return x.strip('<').strip('>');
}

Revised 3 October, 2002

© Copyright Dave Abrahams 2002.