aboutsummaryrefslogtreecommitdiff
path: root/c++-libbu++/src/string.cpp
blob: 32018b8cb9fbf7f053fa5d844e48ba99252ad9da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * Copyright (C) 2007-2013 Xagasoft, All rights reserved.
 *
 * This file is part of the libgats library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include "gats/string.h"

#include "gats/integer.h"

#include <bu/formatter.h>

Gats::String::String()
{
}

Gats::String::String( const char *s ) :
    Bu::String( s )
{
}

Gats::String::String( const char *s, long iLength ) :
    Bu::String( s, iLength )
{
}

Gats::String::String( long iLength ) :
    Bu::String( iLength )
{
}

Gats::String::String( const String &s ) :
    Bu::String( s )
{
}

Gats::String::String( const Bu::String &s ) :
    Bu::String( s )
{
}

Gats::String::~String()
{
}

Gats::Object *Gats::String::clone() const
{
    return new Gats::String( Bu::String::clone() );
}

void Gats::String::write( Bu::Stream &rOut ) const
{
    rOut.write("s", 1 );
    uint32_t iSize = getSize();
    Gats::Integer::writePackedInt( rOut, iSize );
    rOut.write( getStr(), iSize );
}

void Gats::String::read( Bu::Stream &rIn, char cType )
{
    uint32_t iSize;
    Gats::Integer::readPackedInt( rIn, iSize );
    setSize( iSize );
    rIn.read( getStr(), iSize );
}

Gats::String &Gats::String::operator=( const char *s )
{
    Bu::String::operator=( s );
    return *this;
}

Gats::String &Gats::String::operator=( const Gats::String &s )
{
    Bu::String::operator=( s );
    return *this;
}

Gats::String &Gats::String::operator=( const Bu::String &s )
{
    Bu::String::operator=( s );
    return *this;
}

bool Gats::String::operator==( const char *s ) const
{
    return Bu::String::operator==( s );
}

bool Gats::String::operator==( const Gats::String &s ) const
{
    return Bu::String::operator==( s );
}

bool Gats::String::operator==( const Bu::String &s ) const
{
    return Bu::String::operator==( s );
}

Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::String &s )
{
    for( Gats::String::const_iterator i = s.begin(); i; i++ )
    {
        if( *i >= 127 || *i <= 31 )
            return f << "(binary str) " << s.getSize() << " bytes";
    }
    return f << "(str) \"" << dynamic_cast<const Bu::String &>(s) << "\"";
}