1/*
2 * minimalistic Dano-like BStringIO
3 * (c) 2007, François Revol.
4 */
5#include <BeBuild.h>
6#ifndef B_BEOS_VERSION_DANO
7
8#include <StringIO.h>
9#include <Rect.h>
10#include <unistd.h>
11//#include <stdint.h>
12
13// stripped down BStringIO
14
15
16
17BStringIO::BStringIO()
18{
19	fString = new BString;
20}
21
22BStringIO::~BStringIO()
23{
24	delete fString;
25}
26
27ssize_t
28BStringIO::ReadAt(off_t pos, void *buffer, size_t size)
29{
30	return EIO;
31}
32
33ssize_t
34BStringIO::WriteAt(off_t pos, const void *buffer, size_t size)
35{
36	if (pos > (2147483647L)/*INT32_MAX*/)
37		return EINVAL;
38	if (fString->Length() < pos)
39		fString->Insert(' ', (int32)(pos - fString->Length()), fString->Length());
40	fString->Remove((int32)pos, size);
41	fString->Insert((const char *)buffer, size, (int32)pos);
42	return size;
43}
44
45off_t
46BStringIO::Seek(off_t pos, uint32 seek_mode)
47{
48	switch (seek_mode) {
49	case SEEK_CUR:
50		fPosition += pos;
51		return fPosition;
52	case SEEK_SET:
53		fPosition = pos;
54		return fPosition;
55	case SEEK_END:
56		fPosition = fString->Length() - pos;
57		if (fPosition < 0)
58			fPosition = 0;
59		return fPosition;
60	default:
61		return EINVAL;
62	}
63}
64
65off_t
66BStringIO::Position() const
67{
68	return fPosition;
69}
70
71status_t
72BStringIO::SetSize(off_t size)
73{
74	return EINVAL;
75}
76
77const char *
78BStringIO::String() const
79{
80	return fString->String();
81}
82
83
84// ops
85BStringIO & BStringIO::operator<<(const BString & s) {this->BPositionIO::Write(s.String(), s.Length()); return *this;};
86BStringIO & BStringIO::operator<<(const BRect & r) {BString s; s << "Rect{" << r.left << r.top << r.right << r.bottom << "}"; this->BPositionIO::Write(s.String(), s.Length()); return *this;};
87
88#endif /* B_BEOS_VERSION_DANO */
89