class CCL::CString

Overview

Immutable C-String class, safe for ASCII-encoded text only! More…

#include <cstring.h>

class CString:
    protected CCL::PlainCString,
    public Core::CStringTraits,
    public Core::CStringClassifier
{
public:
    // fields

    static const CString kEmpty;

    // construction

    CString (CStringPtr text = nullptr);
    CString (CStringRef other);

    // methods

    MutableCString subString (int index, int count = -1) const;
    MutableCString getBetween (CStringPtr prefix, CStringPtr suffix) const;
    bool getBetween (MutableCString& result, CStringPtr prefix, CStringPtr suffix) const;
    void toUnicode (String& string, TextEncoding encoding = Text::kASCII) const;
    CString& operator = (CStringPtr text);
    CString& operator = (CStringRef other);
    static CStringRef getLineEnd (TextLineFormat lineFormat = Text::kSystemLineFormat);
};

Inherited Members

public:
    // fields

    CStringPtr text;
    ICString* theString;

    // methods

    CStringPtr str () const;
    bool isEmpty () const;
    int length () const;
    bool copyTo (char* charBuffer, int bufferSize) const;
    int index (CStringPtr other) const;
    bool contains (CStringPtr other) const;
    bool startsWith (CStringPtr other) const;
    bool endsWith (CStringPtr other) const;
    int index (char c) const;
    int index (uchar c) const;
    int lastIndex (char c) const;
    int lastIndex (uchar c) const;
    bool contains (char c) const;
    int compare (CStringPtr other, bool caseSensitive = true) const;
    bool getIntValue (int32& value) const;
    bool getIntValue (int64& value) const;
    int scanInt (int fallback = 0) const;
    int64 scanLargetInt (int64 fallback = 0) const;
    bool getHexValue (int64& value) const;
    bool getFloatValue (double& value) const;
    bool getFloatValue (float& value) const;
    float scanFloat (float fallback = 0) const;
    double scanDouble (double fallback = 0) const;
    unsigned int getHashCode () const;
    bool operator == (CStringPtr other) const;
    bool operator != (CStringPtr other) const;

    template  <class S>
    bool operator == (const CStringTraits <S>& other) const;

    template  <class S>
    bool operator != (const CStringTraits <S>& other) const;

    bool equalsUnsafe (CStringPtr other) const;
    char at (int index) const;
    char firstChar () const;
    char lastChar () const;
    char operator [] (int index) const;
    operator CStringPtr () const;
    static bool isAlpha (char c);
    static bool isAlphaNumeric (char c);
    static bool isWhitespace (char c);
    static bool isDigit (char c);
    static bool isASCII (char c);
    static bool isLowercase (char c);
    static bool isUppercase (char c);
    static char toLowercase (char c);
    static char toUppercase (char c);

Detailed Documentation

Immutable C-String class, safe for ASCII-encoded text only!

Fields

static const CString kEmpty

Empty C-String.

Construction

CString (CStringPtr text = nullptr)

Construct with plain C-String.

CString (CStringRef other)

Copy constructor.

Methods

MutableCString subString (int index, int count = -1) const

Create substring.

MutableCString getBetween (CStringPtr prefix, CStringPtr suffix) const

Returns substring between prefix and suffix, string must start with prefix.

bool getBetween (MutableCString& result, CStringPtr prefix, CStringPtr suffix) const

Sets result to the substring between prefix and suffix, string must start with prefix.

Returns true if prefix and suffix match, even if the result between is empty.

void toUnicode (String& string, TextEncoding encoding = Text::kASCII) const

Convert to Unicode String.

CString& operator = (CStringPtr text)

Assign plain C-String.

CString& operator = (CStringRef other)

Assign other C-String.

static CStringRef getLineEnd (TextLineFormat lineFormat = Text::kSystemLineFormat)

Get line ending of given format.