PString

This implements a more or less robust string helper class. 'more or less' means, as much as the limited memory resources on the Pilot allow to. Memory allocation is still kept simple to keep the code small (no string tables, no garbage collection). Strings are expanded according to the needs, but never shrunk, only deleted.
I still lacks a lot of functionality, but I'm expanding it according to the needs.

Synopsis

#include <PLString.h>

Derivation

  • PBaseObj
  • PString
  • Constructors

        PString();
    
    Creates a NULL string. No memory is allocated, a cast to (char*) yields 0.


        PString(const PString& s);
    
    Copy constructor. Allocates memory to hold s.


        PString(const char* p);
        PString(short i);
        PString(int i);
        PString(long i);
        PString(unsigned short i);
        PString(unsigned int i);
        PString(unsigned long i);
        PString(char c);
    
    Conversion constructors. PString(char c) creates a one character string (See PDouble for floating point conversion).


        PString(const void* p, int len);
    
    Constructs a string containing arbitrary data. Even '\0'-characters are allowed.

    Operators

        operator char* () const;
    
    Returns the pointer to the data (modifiable). Use len() to determine the size.


        PString operator= (const PString&);
    
    Copy assignment.


        char& operator[] (int idx);
        const char& operator[] (inst idx) const;
    
    Returns the character at position idx. Indexing starts at 0. For the const version, array bounds are checked, the non-const version will expand the string (not yet implemented).


        PString& operator+= (const PString&);
        PString& operator+= (const char*);
    
    Append.


        PString operator+ (const PString&, const PString&);
        PString operator+ (const PSTring&, const char*);
        PString operator+ (const char*, const PString&);
    
    Concatenate


        Boolean operator== (const PString&);
        Boolean operator== (const char*);
        Boolean operator== (const char*, const PString&);
    
    Contents comparison.

    Public functions

        int len() const;
    
    The length of the contents (may include '\0' characters).


        int           asInt();
        unsigned int  asUInt();
        long          asLong();
        unsigned long asULong();
    
    Conversion functions (See PDouble for floating point conversion).


        PString& resize(int size);
        PString& copy(const char* p, int len = -1, int size = -1);
        PString& concat(const char* p, int len = -1);
        int  concat(const char* p, int len = -1) const;
    
    Not needed, used internally.