Next: Smart Pointers, Previous: Source Code Layout, Up: Top

## 7 Strings

### 7.1 String

The `String` class provided the same functionality of the C++ string except for fewer constructors. It also inherits `OStream` so that you can write to it with the `<<` operator. It is defined in `string.hpp`.

### 7.2 ParmString

ParmString is a special string class that is designed to be used as a parameter for a function that is expecting a string. It is defined in `parm_string.hpp`. It will allow either a `const char *` or `String` class to be passed in. It will automatically convert to a `const char *`. The string can also be accessed via the `str` method. Usage example:

    void foo(ParmString s1, ParmString s2) {
       const char * str0 = s1;
       unsigned int size0 = s2.size()
       if (s1 == s2 || s2 == "bar") {
         ...
       }
    }
    ...
    String s1 = "...";
    foo(s1);
    const char * s2 = "...";
    foo(s2);

This class should be used when a string is being passed in as a parameter. It is faster than using `const String &` (as that will create an unnecessary temporary when a `const char *` is passed in), and is less annoying than using `const char *` (as it doesn't require the `c_str()` method to be used when a `String` is passed in).

### 7.3 CharVector

A character vector is basically a `Vector<char>` but it has a few additional methods for dealing with strings which `Vector` does not provide. It, like `String`, is also inherits `OStream` so that you can write to it with the `<<` operator. It is defined in `char_vector.hpp`. Use it when ever you need a string which is guaranteed to be in a continuous block of memory which you can write to.