2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-19 16:32:16 +00:00
Files
python/test/str.cpp
Dave Abrahams d4e06ac436 Preparation for delivering nicely-formatted error messages in
Boost.Python.  The major change is that, instead of being
boost::function2<PyObject*,PyObject*,PyObject*>, py_function is now a
runtime-polymorphic wrapper for compile-time polymorphic
behavior (just like function) of our own which carries more
information/behaviors.  In particular, you can retrieve an array of
c-strings describing the types in the function signature.
Additionally, the minimum and maximum arity are stored in the
py_function object instead of in the 'function' object which wraps it.

* data_members.hpp -

     Adjustments for the new py_function.  Workarounds for CodeWarrior
     Pro 8.3 bugs in function template argument deduction with
     pointers-to-members.

* has_back_reference.hpp, test/back_reference.cpp,
  test/select_holder.cpp -

     Updated to follow the metafunction protocol

* init.hpp, detail/defaults_gen.hpp -

     Make Keywords a more-specific type in function signatures to
     prevent string literals that show up as char[N] from binding to
     the wrong argument (at least Intel 7.1 for Windows does this).

* make_function.hpp -

     Adjustments for the new py_function.  Arities are now computed
     by caller<>.

* opaque_pointer_converter.hpp, type_id.hpp -

     Use BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS facilities;
     generate specializations that all compilers can handle.

* raw_function.hpp -

     Adjustments for the new py_function.

* caller.hpp -

     Added arity and signature type name reporting.

* detail/config.hpp

     Enable __declspec(dllexport) for Cygwin, thereby fixing the
     recent horrible Cygwin linking problems.


* detail/msvc_typeinfo.hpp -

     Always pass boost::type<T>* explicitly, thereby working around
     incompatible notions of how to specialize function templates with
     default arguments on various compilers.

*   object/function.hpp
  , object/function_handle.hpp
  , object/function_object.hpp
  , object/function_object.cpp

     Adjustments for the new py_function.  Arities are carried by
     py_function.

* object/iterator.hpp, object/iterator.cpp

     Adjustments for the new py_function; we have to compute a
     signature of types to construct it with.

* object/py_function.hpp

     Removed dependency on boost::function; see the comment at the
     top of this entry for more details.

* object/select_holder.hpp

     Clean up to more closely follow MPL idioms.

* test/Jamfile -

     Adjust the embedding test for the new Cygwin use of declspec.
     Update bases and pointee tests with missing properties.

* test/input_iterator.cpp -

     Updates for the new iterator adaptors.

* test/opaque.py -

     Add Python encoding comment to suppress PendinDeprecationWarning
     with recent Python builds.

* test/str.cpp

     Pass a Python long instead of a float to string.expandtabs,
     suppressing a PendinDeprecationWarning with recent Python builds.

* libs/utility/counting_iterator_example.cpp

     Borland workaround

* libs/utility/indirect_iterator_example.cpp

     const-correctness fix.

*


[SVN r19247]
2003-07-22 00:06:41 +00:00

68 lines
1.7 KiB
C++

#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <boost/python/class.hpp>
#include <boost/python/str.hpp>
using namespace boost::python;
object convert_to_string(object data)
{
return str(data);
}
void work_with_string(object print)
{
str data("this is a demo string");
print(data.split(" "));
print(data.split(" ",3));
print(str("<->").join(data.split(" ")));
print(data.capitalize());
print('[' + data.center(30) + ']');
print(data.count("t"));
print(data.encode("utf-8"));
print(data.decode("utf-8"));
print(data.endswith("xx"));
print(data.startswith("test"));
print(data.splitlines());
print(data.strip());
print(data.swapcase());
print(data.title());
print("find");
print(data.find("demo"));
print(data.find("demo"),3,5);
print(data.find(std::string("demo")));
print(data.find(std::string("demo"),9));
print("expandtabs");
str tabstr("\t\ttab\tdemo\t!");
print(tabstr.expandtabs());
print(tabstr.expandtabs(4));
print(tabstr.expandtabs(7L));
print("operators");
print( str("part1") + str("part2") );
// print( str("a test string").slice(3,_) );
// print( str("another test")[5] );
print(data.replace("demo",std::string("blabla")));
print(data.rfind("i",5));
print(data.rindex("i",5));
print(data.startswith("asdf"));
print(data.endswith("asdf"));
print(data.translate(str('a')*256));
bool tmp = data.isalnum() || data.isalpha() || data.isdigit() || data.islower() ||
data.isspace() || data.istitle() || data.isupper();
(void)tmp; // ignored.
}
BOOST_PYTHON_MODULE(str_ext)
{
def("convert_to_string",convert_to_string);
def("work_with_string",work_with_string);
}