Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

ntostr.h File Reference

#include <string>
#include <stdexcept>

Include dependency graph for ntostr.h:

Include dependency graph

Go to the source code of this file.

Namespaces

namespace  Dv
namespace  Dv::Util

Classes

class  Dv::Util::Int
 Class wrapper for int. More...
class  Dv::Util::Long
 Class wrapper for long. More...
class  Dv::Util::Double
 Class wrapper for double. More...

Functions

std::string ntostr (int i, const char *fmt=0)
 Produces a string representation of its int argument.
std::string ntostr (unsigned int u, const char *fmt=0)
 Produces a string representation of its unsigned int argument.
std::string ntostr (long l, const char *fmt=0)
 Produces a string representation of its long argument.
std::string ntostr (unsigned long ul, const char *fmt=0)
 Produces a string representation of its unsigned long argument.
std::string ntostr (double d, unsigned int precision=7, const char *fmt=0)
 Produces a string representation of its double argument.
bool cstr2long (const char *p, long &l, int base=0)
 Try to convert the initial part of a C string to a long.
bool cstr2ulong (const char *p, unsigned long &ul, int base=0)
 Try to convert the initial part of a C string to an unsigned long.
bool cstr2double (const char *p, double &d)
 Try to convert the initial part of a C string to a double.
std::string & s2lower (std::string &s)
 Change (in-place) all chars in string to lower case.
std::string & s2upper (std::string &s)
 Change (in-place) all chars in string to upper case.
std::string & strim (std::string &s)
 Remove leading and trailing white noise (' ', '\n', '\t') from string.
char * strim (char *pc)
 Remove leading and trailing white noise (' ','\n','\t') from C string.


Function Documentation

std::string ntostr int  i,
const char *  fmt = 0
 

Produces a string representation of its int argument.

The representation is determined by a sprintf format string.

Parameters:
i integer to represent
fmt format C-string, the default (if 0) is "%d".
Returns:
string representation of i, according to fmt.
Warning:
The buffer size is 20.

std::string ntostr unsigned int  u,
const char *  fmt = 0
 

Produces a string representation of its unsigned int argument.

The representation is determined by a sprintf format string.

Parameters:
u unsigned integer to represent
fmt format string, the default (if 0) is "%u".
Returns:
string representation of u, according to fmt.
Warning:
The buffer size is 20.

std::string ntostr long  l,
const char *  fmt = 0
 

Produces a string representation of its long argument.

The representation is determined by a sprintf format string.

Parameters:
l long integer to represent
fmt format string, the default (if 0) is "%ld".
Returns:
string representation of l, according to fmt.
Warning:
The buffer size is 20.

std::string ntostr unsigned long  ul,
const char *  fmt = 0
 

Produces a string representation of its unsigned long argument.

The representation is determined by a sprintf format string.

Parameters:
ul unsigned long integer to represent
fmt format string, the default (if 0) is "%lu".
Returns:
string representation of ul, according to fmt.
Warning:
The buffer size is 20.

std::string ntostr double  d,
unsigned int  precision = 7,
const char *  fmt = 0
 

Produces a string representation of its double argument.

The representation is determined by a sprintf format string.

Parameters:
d unsigned long integer to represent
precision number of digits after decimal point in representation
fmt format string, the default (if 0) is "%.Pf".
Returns:
string representation of d, according to fmt and precision.
Warning:
The buffer size is 20.

bool cstr2long const char *  p,
long &  l,
int  base = 0
 

Try to convert the initial part of a C string to a long.

Parameters:
p C-string to convert
l long receiving the value
base to be used in the conversion. The default base (0) reads decimal or octal (if the string starts with 0) numbers.
Returns:
true iff an initial part of the C string p can be converted to a long value.
Warning:
If decimal is necessary, specify base 10 explicitely!

bool cstr2ulong const char *  p,
unsigned long &  ul,
int  base = 0
 

Try to convert the initial part of a C string to an unsigned long.

Parameters:
p C-string to convert
ul unsigned long receiving the value
base to be used in the conversion. The default base (0) reads decimal or octal (if the string starts with 0) numbers.
Returns:
true iff an initial part of the C string p can be converted to an unsigned long value.
Warning:
If decimal is necessary, specify base 10 explicitely!

bool cstr2double const char *  p,
double &  d
 

Try to convert the initial part of a C string to a double.

Parameters:
p C-string to convert
d double receiving the value
Returns:
true iff an initial part of the C string p can be converted to a double value.

std::string& s2lower std::string &  s  ) 
 

Change (in-place) all chars in string to lower case.

Parameters:
s string to convert.
Returns:
reference to first argument.

std::string& s2upper std::string &  s  ) 
 

Change (in-place) all chars in string to upper case.

Parameters:
s string to convert.
Returns:
reference to first argument.

std::string& strim std::string &  s  ) 
 

Remove leading and trailing white noise (' ', '\n', '\t') from string.

The argument is changed and returned

Parameters:
s string to trim
Returns:
reference to the argument

char* strim char *  pc  ) 
 

Remove leading and trailing white noise (' ','\n','\t') from C string.

Parameters:
pc C-string to trim.
Returns:
pointer to first non-white-space character in the argument.
Warning:
The argument is changed. Since the return value points to the first non-white-space char in the argument, the following is a recepy for disaster:
  char* pc = new char[10];
  ..
  pc = strim(pc);
  delete[] pc;


dvutil-0.13.15 [30 December, 2004]