os/ossrv/ossrv_pub/boost_apis/boost/python/str.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright David Abrahams 2002.
sl@0
     2
// Distributed under the Boost Software License, Version 1.0. (See
sl@0
     3
// accompanying file LICENSE_1_0.txt or copy at
sl@0
     4
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
     5
#ifndef STR_20020703_HPP
sl@0
     6
#define STR_20020703_HPP
sl@0
     7
sl@0
     8
# include <boost/python/detail/prefix.hpp>
sl@0
     9
sl@0
    10
#include <boost/python/object.hpp>
sl@0
    11
#include <boost/python/list.hpp>
sl@0
    12
#include <boost/python/converter/pytype_object_mgr_traits.hpp>
sl@0
    13
sl@0
    14
// disable defines in <cctype> provided by some system libraries
sl@0
    15
#undef isspace
sl@0
    16
#undef islower
sl@0
    17
#undef isalpha
sl@0
    18
#undef isdigit
sl@0
    19
#undef isalnum
sl@0
    20
#undef isupper
sl@0
    21
sl@0
    22
namespace boost { namespace python {
sl@0
    23
sl@0
    24
class str;
sl@0
    25
sl@0
    26
namespace detail
sl@0
    27
{
sl@0
    28
  struct BOOST_PYTHON_DECL str_base : object
sl@0
    29
  {
sl@0
    30
      str capitalize() const;
sl@0
    31
sl@0
    32
      str center(object_cref width) const;
sl@0
    33
sl@0
    34
      long count(object_cref sub) const;
sl@0
    35
sl@0
    36
      long count(object_cref sub, object_cref start) const;
sl@0
    37
    
sl@0
    38
      long count(object_cref sub, object_cref start, object_cref end) const;
sl@0
    39
sl@0
    40
      object decode() const;
sl@0
    41
      object decode(object_cref encoding) const;
sl@0
    42
sl@0
    43
      object decode(object_cref encoding, object_cref errors) const;
sl@0
    44
sl@0
    45
      object encode() const;
sl@0
    46
      object encode(object_cref encoding) const;
sl@0
    47
      object encode(object_cref encoding, object_cref errors) const;
sl@0
    48
sl@0
    49
      bool endswith(object_cref suffix) const;
sl@0
    50
    
sl@0
    51
      bool endswith(object_cref suffix, object_cref start) const;
sl@0
    52
      bool endswith(object_cref suffix, object_cref start, object_cref end) const;
sl@0
    53
    
sl@0
    54
      str expandtabs() const;
sl@0
    55
      str expandtabs(object_cref tabsize) const;
sl@0
    56
sl@0
    57
      long find(object_cref sub) const;
sl@0
    58
      long find(object_cref sub, object_cref start) const;
sl@0
    59
sl@0
    60
      long find(object_cref sub, object_cref start, object_cref end) const;
sl@0
    61
sl@0
    62
      long index(object_cref sub) const;
sl@0
    63
sl@0
    64
      long index(object_cref sub, object_cref start) const;
sl@0
    65
      long index(object_cref sub, object_cref start, object_cref end) const;
sl@0
    66
sl@0
    67
      bool isalnum() const;
sl@0
    68
      bool isalpha() const;
sl@0
    69
      bool isdigit() const;
sl@0
    70
      bool islower() const;
sl@0
    71
      bool isspace() const;
sl@0
    72
      bool istitle() const;
sl@0
    73
      bool isupper() const;
sl@0
    74
    
sl@0
    75
      str join(object_cref sequence) const;
sl@0
    76
sl@0
    77
      str ljust(object_cref width) const;
sl@0
    78
      str lower() const;
sl@0
    79
      str lstrip() const;
sl@0
    80
sl@0
    81
      str replace(object_cref old, object_cref new_) const;
sl@0
    82
      str replace(object_cref old, object_cref new_, object_cref maxsplit) const;
sl@0
    83
      long rfind(object_cref sub) const;
sl@0
    84
sl@0
    85
      long rfind(object_cref sub, object_cref start) const;
sl@0
    86
sl@0
    87
      long rfind(object_cref sub, object_cref start, object_cref end) const;
sl@0
    88
      long rindex(object_cref sub) const;
sl@0
    89
      long rindex(object_cref sub, object_cref start) const;
sl@0
    90
sl@0
    91
sl@0
    92
      long rindex(object_cref sub, object_cref start, object_cref end) const;
sl@0
    93
sl@0
    94
      str rjust(object_cref width) const;
sl@0
    95
    
sl@0
    96
      str rstrip() const;
sl@0
    97
    
sl@0
    98
      list split() const; 
sl@0
    99
      list split(object_cref sep) const;
sl@0
   100
   
sl@0
   101
      list split(object_cref sep, object_cref maxsplit) const; 
sl@0
   102
    
sl@0
   103
sl@0
   104
      list splitlines() const;
sl@0
   105
      list splitlines(object_cref keepends) const;
sl@0
   106
sl@0
   107
      bool startswith(object_cref prefix) const;
sl@0
   108
sl@0
   109
sl@0
   110
      bool startswith(object_cref prefix, object_cref start) const;
sl@0
   111
      bool startswith(object_cref prefix, object_cref start, object_cref end) const;
sl@0
   112
sl@0
   113
      str strip() const;
sl@0
   114
      str swapcase() const;
sl@0
   115
      str title() const;
sl@0
   116
    
sl@0
   117
      str translate(object_cref table) const;
sl@0
   118
sl@0
   119
      str translate(object_cref table, object_cref deletechars) const;
sl@0
   120
sl@0
   121
    
sl@0
   122
      str upper() const;
sl@0
   123
sl@0
   124
   protected:
sl@0
   125
      str_base(); // new str
sl@0
   126
    
sl@0
   127
      str_base(const char* s); // new str
sl@0
   128
sl@0
   129
      str_base(char const* start, char const* finish);
sl@0
   130
      
sl@0
   131
      str_base(char const* start, std::size_t length);
sl@0
   132
      
sl@0
   133
      explicit str_base(object_cref other);
sl@0
   134
sl@0
   135
      BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(str_base, object)
sl@0
   136
   private:
sl@0
   137
      static new_reference call(object const&);
sl@0
   138
  };
sl@0
   139
}
sl@0
   140
sl@0
   141
sl@0
   142
class str : public detail::str_base
sl@0
   143
{
sl@0
   144
    typedef detail::str_base base;
sl@0
   145
 public:
sl@0
   146
    str() {} // new str
sl@0
   147
    
sl@0
   148
    str(const char* s) : base(s) {} // new str
sl@0
   149
    
sl@0
   150
    str(char const* start, char const* finish) // new str
sl@0
   151
      : base(start, finish)
sl@0
   152
    {}
sl@0
   153
    
sl@0
   154
    str(char const* start, std::size_t length) // new str
sl@0
   155
      : base(start, length)
sl@0
   156
    {}
sl@0
   157
    
sl@0
   158
    template <class T>
sl@0
   159
    explicit str(T const& other)
sl@0
   160
        : base(object(other))
sl@0
   161
    {
sl@0
   162
    }
sl@0
   163
sl@0
   164
    template <class T>
sl@0
   165
    str center(T const& width) const
sl@0
   166
    {
sl@0
   167
        return base::center(object(width));
sl@0
   168
    }
sl@0
   169
sl@0
   170
    template<class T>
sl@0
   171
    long count(T const& sub) const
sl@0
   172
    {
sl@0
   173
        return base::count(object(sub));
sl@0
   174
    }
sl@0
   175
sl@0
   176
    template<class T1, class T2>
sl@0
   177
    long count(T1 const& sub,T2 const& start) const
sl@0
   178
    {
sl@0
   179
        return base::count(object(sub), object(start));
sl@0
   180
    }
sl@0
   181
sl@0
   182
    template<class T1, class T2, class T3>
sl@0
   183
    long count(T1 const& sub,T2 const& start, T3 const& end) const
sl@0
   184
    {
sl@0
   185
        return base::count(object(sub), object(start));
sl@0
   186
    }
sl@0
   187
sl@0
   188
    object decode() const { return base::decode(); }
sl@0
   189
    
sl@0
   190
    template<class T>
sl@0
   191
    object decode(T const& encoding) const
sl@0
   192
    {
sl@0
   193
        return base::decode(object(encoding));
sl@0
   194
    }
sl@0
   195
sl@0
   196
    template<class T1, class T2>
sl@0
   197
    object decode(T1 const& encoding, T2 const& errors) const
sl@0
   198
    {
sl@0
   199
        return base::decode(object(encoding),object(errors));
sl@0
   200
    }
sl@0
   201
sl@0
   202
    object encode() const { return base::encode(); }
sl@0
   203
sl@0
   204
    template <class T>
sl@0
   205
    object encode(T const& encoding) const
sl@0
   206
    {
sl@0
   207
        return base::encode(object(encoding));
sl@0
   208
    }
sl@0
   209
sl@0
   210
    template <class T1, class T2>
sl@0
   211
    object encode(T1 const& encoding, T2 const& errors) const
sl@0
   212
    {
sl@0
   213
        return base::encode(object(encoding),object(errors));
sl@0
   214
    }
sl@0
   215
sl@0
   216
    template <class T>
sl@0
   217
    bool endswith(T const& suffix) const
sl@0
   218
    {
sl@0
   219
        return base::endswith(object(suffix));
sl@0
   220
    }
sl@0
   221
sl@0
   222
    template <class T1, class T2>
sl@0
   223
    bool endswith(T1 const& suffix, T2 const& start) const
sl@0
   224
    {
sl@0
   225
        return base::endswith(object(suffix), object(start));
sl@0
   226
    }
sl@0
   227
sl@0
   228
    template <class T1, class T2, class T3>
sl@0
   229
    bool endswith(T1 const& suffix, T2 const& start, T3 const& end) const
sl@0
   230
    {
sl@0
   231
        return base::endswith(object(suffix), object(start), object(end));
sl@0
   232
    }
sl@0
   233
    
sl@0
   234
    str expandtabs() const { return base::expandtabs(); }
sl@0
   235
sl@0
   236
    template <class T>
sl@0
   237
    str expandtabs(T const& tabsize) const
sl@0
   238
    {
sl@0
   239
        return base::expandtabs(object(tabsize));
sl@0
   240
    }
sl@0
   241
    
sl@0
   242
    template <class T>
sl@0
   243
    long find(T const& sub) const
sl@0
   244
    {
sl@0
   245
        return base::find(object(sub));
sl@0
   246
    }
sl@0
   247
sl@0
   248
    template <class T1, class T2>
sl@0
   249
    long find(T1 const& sub, T2 const& start) const
sl@0
   250
    {
sl@0
   251
        return base::find(object(sub), object(start));
sl@0
   252
    }
sl@0
   253
sl@0
   254
    template <class T1, class T2, class T3>
sl@0
   255
    long find(T1 const& sub, T2 const& start, T3 const& end) const
sl@0
   256
    {
sl@0
   257
        return base::find(object(sub), object(start), object(end));
sl@0
   258
    }
sl@0
   259
    
sl@0
   260
    template <class T>
sl@0
   261
    long index(T const& sub) const
sl@0
   262
    {
sl@0
   263
        return base::index(object(sub));
sl@0
   264
    }
sl@0
   265
    
sl@0
   266
    template <class T1, class T2>
sl@0
   267
    long index(T1 const& sub, T2 const& start) const
sl@0
   268
    {
sl@0
   269
        return base::index(object(sub), object(start));
sl@0
   270
    }
sl@0
   271
sl@0
   272
    template <class T1, class T2, class T3>
sl@0
   273
    long index(T1 const& sub, T2 const& start, T3 const& end) const
sl@0
   274
    {
sl@0
   275
        return base::index(object(sub), object(start), object(end));
sl@0
   276
    }
sl@0
   277
sl@0
   278
    template <class T>
sl@0
   279
    str join(T const& sequence) const
sl@0
   280
    {
sl@0
   281
        return base::join(object(sequence));
sl@0
   282
    }
sl@0
   283
    
sl@0
   284
    template <class T>
sl@0
   285
    str ljust(T const& width) const
sl@0
   286
    {
sl@0
   287
        return base::ljust(object(width));
sl@0
   288
    }
sl@0
   289
sl@0
   290
    template <class T1, class T2>
sl@0
   291
    str replace(T1 const& old, T2 const& new_) const 
sl@0
   292
    {
sl@0
   293
        return base::replace(object(old),object(new_));
sl@0
   294
    }
sl@0
   295
sl@0
   296
    template <class T1, class T2, class T3>
sl@0
   297
    str replace(T1 const& old, T2 const& new_, T3 const& maxsplit) const 
sl@0
   298
    {
sl@0
   299
        return base::replace(object(old),object(new_), object(maxsplit));
sl@0
   300
    }
sl@0
   301
    
sl@0
   302
    template <class T>
sl@0
   303
    long rfind(T const& sub) const
sl@0
   304
    {
sl@0
   305
        return base::rfind(object(sub));
sl@0
   306
    }
sl@0
   307
sl@0
   308
    template <class T1, class T2>
sl@0
   309
    long rfind(T1 const& sub, T2 const& start) const
sl@0
   310
    {
sl@0
   311
        return base::rfind(object(sub), object(start));
sl@0
   312
    }
sl@0
   313
    
sl@0
   314
    template <class T1, class T2, class T3>
sl@0
   315
    long rfind(T1 const& sub, T2 const& start, T3 const& end) const
sl@0
   316
    {
sl@0
   317
        return base::rfind(object(sub), object(start), object(end));
sl@0
   318
    }
sl@0
   319
    
sl@0
   320
    template <class T>
sl@0
   321
    long rindex(T const& sub) const
sl@0
   322
    {
sl@0
   323
        return base::rindex(object(sub));
sl@0
   324
    }
sl@0
   325
sl@0
   326
    template <class T1, class T2>
sl@0
   327
    long rindex(T1 const& sub, T2 const& start) const
sl@0
   328
    {
sl@0
   329
        return base::rindex(object(sub), object(start));
sl@0
   330
    }
sl@0
   331
sl@0
   332
    template <class T1, class T2, class T3>
sl@0
   333
    long rindex(T1 const& sub, T2 const& start, T3 const& end) const
sl@0
   334
    {
sl@0
   335
        return base::rindex(object(sub), object(start), object(end));
sl@0
   336
    }
sl@0
   337
sl@0
   338
    template <class T>
sl@0
   339
    str rjust(T const& width) const
sl@0
   340
    {
sl@0
   341
        return base::rjust(object(width));
sl@0
   342
    }
sl@0
   343
    
sl@0
   344
    list split() const { return base::split(); }
sl@0
   345
   
sl@0
   346
    template <class T>
sl@0
   347
    list split(T const& sep) const
sl@0
   348
    {
sl@0
   349
        return base::split(object(sep));
sl@0
   350
    }
sl@0
   351
sl@0
   352
    template <class T1, class T2>
sl@0
   353
    list split(T1 const& sep, T2 const& maxsplit) const
sl@0
   354
    {
sl@0
   355
        return base::split(object(sep), object(maxsplit));
sl@0
   356
    }
sl@0
   357
sl@0
   358
    list splitlines() const { return base::splitlines(); }
sl@0
   359
sl@0
   360
    template <class T>
sl@0
   361
    list splitlines(T const& keepends) const
sl@0
   362
    {
sl@0
   363
        return base::splitlines(object(keepends));
sl@0
   364
    }
sl@0
   365
sl@0
   366
    template <class T>
sl@0
   367
    bool startswith(T const& prefix) const
sl@0
   368
    {
sl@0
   369
        return base::startswith(object(prefix));
sl@0
   370
    }
sl@0
   371
sl@0
   372
    template <class T1, class T2>
sl@0
   373
    bool startswith(T1 const& prefix, T2 const& start) const
sl@0
   374
    {
sl@0
   375
        return base::startswith(object(prefix), object(start));
sl@0
   376
    }
sl@0
   377
     
sl@0
   378
    template <class T1, class T2, class T3>
sl@0
   379
    bool startswith(T1 const& prefix, T2 const& start, T3 const& end) const
sl@0
   380
    {
sl@0
   381
        return base::startswith(object(prefix), object(start), object(end));
sl@0
   382
    }
sl@0
   383
sl@0
   384
    template <class T>
sl@0
   385
    str translate(T const& table) const
sl@0
   386
    {
sl@0
   387
        return base::translate(object(table));
sl@0
   388
    }
sl@0
   389
sl@0
   390
    template <class T1, class T2>
sl@0
   391
    str translate(T1 const& table, T2 const& deletechars) const
sl@0
   392
    {
sl@0
   393
        return base::translate(object(table), object(deletechars));
sl@0
   394
    }
sl@0
   395
    
sl@0
   396
 public: // implementation detail -- for internal use only
sl@0
   397
    BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(str, base)
sl@0
   398
};
sl@0
   399
sl@0
   400
//
sl@0
   401
// Converter Specializations
sl@0
   402
//
sl@0
   403
namespace converter
sl@0
   404
{
sl@0
   405
  template <>
sl@0
   406
  struct object_manager_traits<str>
sl@0
   407
      : pytype_object_manager_traits<&PyString_Type,str>
sl@0
   408
  {
sl@0
   409
  };
sl@0
   410
}
sl@0
   411
sl@0
   412
}}  // namespace boost::python
sl@0
   413
sl@0
   414
#endif // STR_20020703_HPP