Rice  3.0.0
String.hpp
1 #ifndef Rice__String__hpp_
2 #define Rice__String__hpp_
3 
4 #include "Identifier.hpp"
5 #include "Builtin_Object_defn.hpp"
6 #include "to_from_ruby_defn.hpp"
7 #include "detail/ruby.hpp"
8 #include <string>
9 
10 namespace Rice
11 {
12 
14 
23 class String
24  : public Builtin_Object<T_STRING>
25 {
26 public:
28  String();
29 
31  String(VALUE v);
32 
35 
38 
40  String(char const * s);
41 
43  String(std::string const & s);
44 
46  static String format(char const * s, ...);
47 
49 
51  size_t length() const;
52 
54 
57  char operator[](ptrdiff_t index) const;
58 
60  char const * c_str() const;
61 
63  std::string str() const;
64 
66 
69  Identifier intern() const;
70 };
71 
72 } // namespace Rice
73 
74 template<>
75 inline
76 Rice::String from_ruby<Rice::String>(Rice::Object x)
77 {
78  return Rice::String(x);
79 }
80 
81 template<>
82 inline
83 Rice::Object to_ruby<Rice::String>(Rice::String const & x)
84 {
85  return x;
86 }
87 
88 #include "Builtin_Object.ipp"
89 
90 #endif // Rice__String__hpp_
91 
A smartpointer-like wrapper for Ruby builtin objects.
Definition: Builtin_Object_defn.hpp:20
A wrapper for the ID type.
Definition: Identifier.hpp:16
The base class for all Objects.
Definition: Object_defn.hpp:25
A Wraper for the ruby String class.
Definition: String.hpp:25
String(Object v)
Wrap an existing string.
Identifier intern() const
Create an Identifier from the String.
std::string str() const
Return a copy of the string as an std::string.
char operator[](ptrdiff_t index) const
Get the character at the given index.
static String format(char const *s,...)
Format a string using printf-style formatting.
String(char const *s)
Construct a String from a null-terminated C string.
char const * c_str() const
Return a pointer to the beginning of the underlying C string.
String(std::string const &s)
Construct a String from an std::string.
String(Identifier id)
Construct a String from an Identifier.
size_t length() const
Get the length of the String.
String()
Construct a new string.
String(VALUE v)
Wrap an existing string.