Line data Source code
1 : //////////////////////////////////////////////////////////////////////
2 : //
3 : // FILE: dstring.h
4 : // Dynamic String class
5 : //
6 : // Part of: Scid (Shane's Chess Information Database)
7 : // Version: 2.2
8 : //
9 : // Notice: Copyright (c) 2000 Shane Hudson. All rights reserved.
10 : //
11 : // Author: Shane Hudson (sgh@users.sourceforge.net)
12 : //
13 : //////////////////////////////////////////////////////////////////////
14 :
15 : #ifndef SCID_DSTRING_H
16 : #define SCID_DSTRING_H
17 :
18 : #include "common.h"
19 : #include <stdio.h>
20 : #include <string>
21 :
22 0 : class DString { // DEPRECATED
23 : std::string s_;
24 :
25 : public:
26 : void Clear() { s_.clear(); }
27 :
28 0 : const char* Data() { return s_.c_str(); }
29 :
30 : size_t Length(void) { return s_.size(); }
31 :
32 0 : void AddChar(char ch) { s_.append(1, ch); }
33 :
34 : void AppendUint(uint i) {
35 : char s[16];
36 : sprintf(s, "%u", i);
37 : s_.append(s);
38 : }
39 :
40 : void AppendInt(int i) {
41 : char s[16];
42 : sprintf(s, "%d", i);
43 : s_.append(s);
44 : }
45 :
46 : void Append(uint i) { AppendUint(i); }
47 :
48 0 : void Append(const char* str) { s_.append(str); }
49 :
50 : // To allow convenient appending of multiple strings without resorting
51 : // to messy variable-length argument lists, we define DString::Append()
52 : // for up to five string arguments, and for up to four arguments where
53 : // one is an unsigned integer and the rest are strings.
54 : void Append(const char* s1, const char* s2) {
55 : Append(s1);
56 : Append(s2);
57 : }
58 : void Append(const char* s1, uint i2) {
59 : Append(s1);
60 : Append(i2);
61 : }
62 : void Append(uint i1, const char* s2) {
63 : Append(i1);
64 : Append(s2);
65 : }
66 : void Append(const char* s1, const char* s2, const char* s3) {
67 : Append(s1);
68 : Append(s2);
69 : Append(s3);
70 : }
71 : void Append(const char* s1, const char* s2, uint i3) {
72 : Append(s1);
73 : Append(s2);
74 : Append(i3);
75 : }
76 : void Append(const char* s1, uint i2, const char* s3) {
77 : Append(s1);
78 : Append(i2);
79 : Append(s3);
80 : }
81 : void Append(uint i1, const char* s2, const char* s3) {
82 : Append(i1);
83 : Append(s2);
84 : Append(s3);
85 : }
86 : void Append(const char* s1, const char* s2, const char* s3,
87 : const char* s4) {
88 : Append(s1);
89 : Append(s2);
90 : Append(s3);
91 : Append(s4);
92 : }
93 : void Append(const char* s1, const char* s2, const char* s3, uint i4) {
94 : Append(s1);
95 : Append(s2);
96 : Append(s3);
97 : Append(i4);
98 : }
99 : void Append(const char* s1, const char* s2, uint i3, const char* s4) {
100 : Append(s1);
101 : Append(s2);
102 : Append(i3);
103 : Append(s4);
104 : }
105 : void Append(const char* s1, uint i2, const char* s3, const char* s4) {
106 : Append(s1);
107 : Append(i2);
108 : Append(s3);
109 : Append(s4);
110 : }
111 : void Append(uint i1, const char* s2, const char* s3, const char* s4) {
112 : Append(i1);
113 : Append(s2);
114 : Append(s3);
115 : Append(s4);
116 : }
117 : void Append(const char* s1, const char* s2, const char* s3, const char* s4,
118 : const char* s5) {
119 : Append(s1);
120 : Append(s2);
121 : Append(s3);
122 : Append(s4);
123 : Append(s5);
124 : }
125 : };
126 :
127 : #endif // SCID_DSTRING_H
|