Xbase64 4.0.1
C++ Library for handling Xbase (DBF) format type files
xbstring.h
Go to the documentation of this file.
1/* xbstring.h
2
3XBase64 Software Library
4
5Copyright (c) 1997,2003,2014,2022 Gary A Kunkel
6
7The xb64 software library is covered under the terms of the GPL Version 3, 2007 license.
8
9Email Contact:
10
11 XDB-devel@lists.sourceforge.net
12 XDB-users@lists.sourceforge.net
13
14*/
15
16#ifndef __XBSTRING_H__
17#define __XBSTRING_H__
18
19#ifdef CMAKE_COMPILER_IS_GNUCC
20#pragma interface
21#endif
22
23#include <stdlib.h>
24#include <iostream>
25
26namespace xb{
27
28
30
50class XBDLLEXPORT xbString {
51
52 public:
53 //Various constructors
54 xbString(xbUInt32 size);
55 xbString(char c);
56 xbString(const char *s, xbUInt32 lMaxLen);
57 xbString(const xbString &s);
58 xbString(const char * = "");
59 xbString( xbDouble d );
60 ~xbString();
61
62 //operators
63 xbString &operator= (const xbString &s);
64 xbString &operator= (const char *s);
65 operator const char *() const;
66 char &operator[](xbUInt32 n) const;
67 char &operator[](xbInt32 n) const;
68
69 xbString &operator+=(const xbString &s);
70 xbString &operator+=(const char *s);
71 xbString &operator+=(char c);
72 xbString &operator-=(const xbString &s);
73 xbString &operator-=(const char *s);
74 xbString &operator-=(char c);
75
76 xbBool operator == ( const xbString& ) const;
77 xbBool operator == ( const char * ) const;
78 xbBool operator != ( const xbString& ) const;
79 xbBool operator != ( const char * ) const;
80
81 xbBool operator < ( const xbString& ) const;
82 xbBool operator > ( const xbString& ) const;
83 xbBool operator <= ( const xbString& ) const;
84 xbBool operator >= ( const xbString& ) const;
85
86 xbString operator-( const xbString &s );
87 xbString operator+( const char *s );
88 xbString operator+( const xbString &s );
89 xbString operator+( const char c );
90
91 xbString &AddBackSlash( char c );
92 xbString &Append(const xbString &s);
93 xbString &Append(const char *s);
94 xbString &Append(const char *s, xbUInt32 iByteCount );
95 xbString &Append(char c);
96 xbString &Assign(const char *srcStr, xbUInt32 lStartPos, xbUInt32 lCopyLen );
97 xbString &Assign(const char *srcStr, xbUInt32 lStartPos );
98 xbString &Assign(const xbString &s, xbUInt32 ulStartPos, xbUInt32 lCopyLen );
99 xbString &Assign(const xbString &s, xbUInt32 ulStartPos );
100
101 xbString Copy() const;
102 xbUInt32 CountChar( char c ) const;
103 xbUInt32 CountChar( char c, xbInt16 iOpt ) const;
104 xbInt16 CvtHexChar( char &cOut );
105 xbInt16 CvtHexString( xbString &sOut );
106 xbInt16 CvtULongLong( xbUInt64 &ullOut );
107 xbInt16 CvtLongLong( xbInt64 &llOut );
108
109 #ifdef XB_DEBUG_SUPPORT
110 void Dump( const char *title ) const;
111 void Dump( const char *title, xbInt16 iOption ) const;
112 void DumpHex( const char *title ) const;
113 #endif
114
115 xbString &ExtractElement(xbString &s, char delim, xbUInt32 iCnt, xbInt16 iOpt = 0 );
116 xbString &ExtractElement(const char *src, char delim, xbUInt32 iCnt, xbInt16 iOpt = 0 );
117
118 char GetCharacter( xbUInt32 lPos ) const;
119 xbUInt32 GetLastPos(char c) const;
120 xbUInt32 GetLastPos(const char *s) const;
121 char GetPathSeparator() const;
122 xbUInt32 GetSize() const;
123
124 xbBool HasAlphaChars() const;
125 xbBool IsEmpty() const;
126 xbBool IsNull() const;
127
128 xbString &Left( xbUInt32 ulLen );
129 xbUInt32 Len() const; // returns the length of the string
130 xbString &Ltrim();
131 xbString &Ltrunc( xbUInt32 ulCnt );
132
133 xbString &Mid(xbUInt32 ulPos, xbUInt32 lLen );
134 xbString &PadLeft( char c, xbUInt32 ulLen );
135 xbString &PadRight( char c, xbUInt32 ulLen );
136
137 xbUInt32 Pos(char c, xbUInt32 ulStartPos ) const;
138 xbUInt32 Pos(char c) const;
139 xbUInt32 Pos(const char *s) const;
140 xbString &PutAt(xbUInt32 ulPos, char c);
141
142 xbString &Remove( xbUInt32 ulPos, xbUInt32 ulN );
143 xbString &Replace( const char *sReplace, const char *sReplaceWith, xbInt16 iOpt = 0 );
144 xbString &Resize( xbUInt32 lSize );
145 xbString &Rtrim();
146
147 xbString &Set( const char *s );
148 xbString &Set( const xbString &s );
149 xbString &Set( const char *s, xbUInt32 ulSize );
150 xbString &SetNum( xbInt32 lNum );
151 xbString &Sprintf(const char *format, ...);
152
153 const char *Str() const;
154 char *strncpy( char * cDest, xbUInt32 n ) const;
155 xbString &SwapChars( char from, char to );
156
157 xbString &ToLowerCase();
158 xbString &ToUpperCase();
159 xbString &Trim();
160
161 xbBool ValidLogicalValue() const;
162 xbBool ValidNumericValue() const;
163 xbString &ZapChar( char c );
164 xbString &ZapLeadingChar( char c );
165 xbString &ZapTrailingChar( char c );
166
167 friend std::ostream& operator<< ( std::ostream& os, const xbString& s );
168
169 private:
170
171 static const char * NullString;
172 static char cJunkBuf;
173
174 char *data; // pointer to actual string data
175 xbUInt32 size; // size of string plus null terminating byte
176
177 void ctor(const char *s);
178// xbUInt32 CalcSprintfBufSize(const char *format, ...);
179
180// char * xb_realloc( char *pIn, xbUInt32 iLen );
181
182 // next routine could result in buffer over runs if used with improperly sized buffers
183 char * xb_strcpy ( char *target, const char *source);
184
185};
186
187} /* namespace */
188#endif /* __XBSTRING_H__ */
Class for handling string data.
Definition: xbstring.h:50
Definition: xbdate.cpp:19
double xbDouble
Definition: xbtypes.h:23
short int xbBool
Definition: xbtypes.h:24
std::ostream & operator<<(std::ostream &os, const xbString &s)
Stream insertion operator <<.
Definition: xbstring.cpp:148