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 pos, xbUInt32 n );
99 xbString &Assign(const xbString &s, xbUInt32 n );
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(const char *src, char delim, xbUInt32 iCnt, xbInt16 iOpt = 0 );
116 char GetCharacter( xbUInt32 lPos ) const;
117 xbUInt32 GetLastPos(char c) const;
118 xbUInt32 GetLastPos(const char *s) const;
119 char GetPathSeparator() const;
120 xbUInt32 GetSize() const;
121
122 xbBool HasAlphaChars() const;
123 xbBool IsEmpty() const;
124 xbBool IsNull() const;
125
126 xbString &Left( xbUInt32 ulLen );
127 xbUInt32 Len() const; // returns the length of the string
128 xbString &Ltrim();
129 xbString &Ltrunc( xbUInt32 ulCnt );
130
131 xbString &Mid(xbUInt32 ulPos, xbUInt32 lLen );
132 xbString &PadLeft( char c, xbUInt32 ulLen );
133 xbString &PadRight( char c, xbUInt32 ulLen );
134 xbUInt32 Pos(char c) const;
135 xbUInt32 Pos(const char *s) const;
136 xbString &PutAt(xbUInt32 ulPos, char c);
137
138 xbString &Remove( xbUInt32 ulPos, xbUInt32 ulN );
139 xbString &Resize( xbUInt32 lSize );
140 xbString &Rtrim();
141
142 xbString &Set( const char *s );
143 xbString &Set( const xbString &s );
144 xbString &Set( const char *s, xbUInt32 ulSize );
145 xbString &SetNum( xbInt32 lNum );
146 xbString &Sprintf(const char *format, ...);
147
148 const char *Str() const;
149 char *strncpy( char * cDest, xbUInt32 n ) const;
150 xbString &SwapChars( char from, char to );
151
152 xbString &ToLowerCase();
153 xbString &ToUpperCase();
154 xbString &Trim();
155
156 xbBool ValidLogicalValue() const;
157 xbBool ValidNumericValue() const;
158 xbString &ZapChar( char c );
159 xbString &ZapLeadingChar( char c );
160 xbString &ZapTrailingChar( char c );
161
162 friend std::ostream& operator<< ( std::ostream& os, const xbString& s );
163
164 private:
165
166 static const char * NullString;
167 static char cJunkBuf;
168
169 char *data; // pointer to actual string data
170 xbUInt32 size; // size of string plus null terminating byte
171
172 void ctor(const char *s);
173// xbUInt32 CalcSprintfBufSize(const char *format, ...);
174
175// char * xb_realloc( char *pIn, xbUInt32 iLen );
176
177 // next routine could result in buffer over runs if used with improperly sized buffers
178 char * xb_strcpy ( char *target, const char *source);
179
180};
181
182} /* namespace */
183#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