VR-Vantage 3.1 API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
stringEx.h
Go to the documentation of this file.
1 
2 // stringEx.h
3 //
4 // Copyright JRM Enterprises, Inc. 2004
5 // All rights reserved.
6 //
7 // This code is the intellectual property of JRM Enterprises, Inc.
8 // It may not be used or released as source or compiled binary form
9 // without the prior written consent of JRM Enterprises, Inc.
10 //
11 // Description: declaration of stringEx
12 //
13 // Author: Jerry Evans' submission jerry@chordia.co.uk found on
14 // CodeProject http://www.codeproject.com/string/stringex.asp
15 // Ported by Jeff Biggs (jbigz@hiwaay.net)
16 //
17 // $Header: /cvsroot/SigSim/SigSimRT/include/stringEx.h,v 1.1 2009-07-27 12:46:47 cvsuser Exp $
18 //
19 // $Log: not supported by cvs2svn $
20 // Revision 1.3 2006/12/19 05:36:33 cvsuser
21 // Fix varags for linux.
22 // TR
23 //
24 // Revision 1.2 2006/03/22 21:43:23 cvsuser
25 // (Tim) Added doxygen comments to allow for documentation
26 //
27 // Revision 1.1 2005/02/16 14:46:53 cvsuser
28 // New Asgard SDK. Uses updated OSG version 0.9.8
29 //
30 // Revision 1.3 2004/07/09 21:30:57 cvsuser
31 // attempt to make stringEx cross platform (NOT tested on linux yet, let me know)
32 // - biggs
33 //
34 //
36 
37 #ifndef __stringEx_h__
38 #define __stringEx_h__
39 
40 #include <string>
41 #include <algorithm>
42 #include <vector>
43 #include <stdio.h>
44 #ifdef LINUX
45 #include <stdarg.h>
46 #endif
47 
49 // class stringEx
50 //
51 // description: std::string extension class. Provides MFC-like Format() and
52 // others.
53 //
54 
55 class stringEx : public std::string
56 {
57  // size of Format() buffer.
58  enum { _MAX_CHARS = 8096 };
59 
60 public:
61 
62 
64 //stringEx
68  stringEx() {}
69 
71 //~stringEx
75  ~stringEx() {}
76 
77 
79 // stringEx
84  stringEx(const stringEx &arg) { assign(arg.c_str()); }
86 // stringEx
91  stringEx(const std::string &arg) { assign(arg); }
93 // stringEx
98  stringEx(const char *pArg) { assign(pArg); }
99 
100 
102 //&operator=
108  stringEx &operator=(const char *pArg) { assign(pArg); return (*this); }
110 //&operator=
116  stringEx &operator=(const std::string &arg) { assign(arg); return (*this); }
118 //&operator=
124  stringEx &operator=(const stringEx &arg) { assign(arg.c_str()); return (*this); }
125 
126 
128 //Format
135  int Format(const char *szFormat, ...)
136  {
137  std::vector<char> buffer(_MAX_CHARS);
138  va_list argList;
139  va_start(argList, szFormat);
140 # ifdef WIN32
141  int ret = _vsnprintf(&buffer[0], _MAX_CHARS, szFormat, argList);
142 # else
143  int ret = vsnprintf(&buffer[0], _MAX_CHARS, szFormat, argList);
144 # endif
145  va_end(argList);
146  assign(&buffer[0], ret);
147  return ret;
148  }
149 
151 //&FormatEx
161  stringEx &FormatEx(const char *szFormat, ...)
162  {
163  std::vector<char> buffer(_MAX_CHARS);
164  va_list argList;
165  va_start(argList, szFormat);
166 # ifdef WIN32
167  int ret = _vsnprintf(&buffer[0], _MAX_CHARS, szFormat, argList);
168 # else
169  int ret = vsnprintf(&buffer[0], _MAX_CHARS, szFormat, argList);
170 # endif
171  va_end(argList);
172  assign(&buffer[0], ret);
173  return (*this);
174  }
175 
176 
178 //&MakeUpper
184  {
185  std::transform(begin(), end(), begin(), toupper); return (*this);
186  }
188 //&MakeLower
194  {
195  std::transform(begin(), end(), begin(), tolower); return (*this);
196  }
197 };
198 
199 #endif //__stringEx_h__
200 


Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)