xref: /haiku/src/add-ons/input_server/methods/pen/compat/StringIO.cpp (revision 21258e2674226d6aa732321b6f8494841895af5f)
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 
17 BStringIO::BStringIO()
18 {
19 	fString = new BString;
20 }
21 
22 BStringIO::~BStringIO()
23 {
24 	delete fString;
25 }
26 
27 ssize_t
28 BStringIO::ReadAt(off_t pos, void *buffer, size_t size)
29 {
30 	return EIO;
31 }
32 
33 ssize_t
34 BStringIO::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 
45 off_t
46 BStringIO::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 
65 off_t
66 BStringIO::Position() const
67 {
68 	return fPosition;
69 }
70 
71 status_t
72 BStringIO::SetSize(off_t size)
73 {
74 	return EINVAL;
75 }
76 
77 const char *
78 BStringIO::String() const
79 {
80 	return fString->String();
81 }
82 
83 
84 // ops
85 BStringIO & BStringIO::operator<<(const BString & s) {this->BPositionIO::Write(s.String(), s.Length()); return *this;};
86 BStringIO & 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