OFStandard Class Reference

A class for various helper functions. More...

List of all members.

Static Public Member Functions

static size_t strlcpy (char *dst, const char *src, size_t siz)
 This function copies up to size - 1 characters from the NUL- terminated string src to dst, NUL-terminating the result.
static size_t strlcat (char *dst, const char *src, size_t siz)
 This function appends the NUL-terminated string src to the end of dst.
static OFBool pathExists (const OFString &pathName)
 check whether the given path exists.
static OFBool fileExists (const OFString &fileName)
 check whether the given file exists.
static OFBool dirExists (const OFString &dirName)
 check whether the given directory exists.
static OFBool isReadable (const OFString &pathName)
 check whether the given path is readable.
static OFBool isWriteable (const OFString &pathName)
 check whether the given path is writeable.
static OFStringnormalizeDirName (OFString &result, const OFString &dirName, const OFBool allowEmptyDirName=OFFalse)
 normalize the given directory name.
static OFStringcombineDirAndFilename (OFString &result, const OFString &dirName, const OFString &fileName, const OFBool allowEmptyDirName=OFFalse)
 combine the given directory and file name.
static size_t searchDirectoryRecursively (const OFString &directory, OFList< OFString > &fileList, const OFString &pattern, const OFString &dirPrefix)
 scan a given directory recursively and add all filenames found to a list
static const OFStringconvertToMarkupString (const OFString &sourceString, OFString &markupString, const OFBool convertNonASCII=OFFalse, const OFBool xmlMode=OFTrue, const OFBool newlineAllowed=OFFalse)
 convert character string to HTML/XML mnenonic string.
static const OFStringencodeBase64 (const unsigned char *data, const size_t length, OFString &result, const size_t width=0)
 encode binary data according to "Base64" as described in RFC 2045 (MIME).
static size_t decodeBase64 (const OFString &data, unsigned char *&result)
 decode "Base64" encoded string.
static double atof (const char *s, OFBool *success=NULL)
 converts a floating-point number from an ASCII decimal representation to internal double-precision format.
static void ftoa (char *target, size_t targetSize, double value, unsigned int flags=0, int width=0, int precision=-1)
 formats a floating-point number into an ASCII string.
static OFBool stringMatchesCharacterSet (const char *str, const char *charset)
 Checks if a given string consists only of characters which are specified in a given charset.
static unsigned int sleep (unsigned int seconds)
 makes the current process sleep until seconds seconds have elapsed or a signal arrives which is not ignored.

Static Public Attributes

ftoa() processing flags.
These flags can be combined by bit-wise or.

static const unsigned int ftoa_format_e
 Use e or E conversion format instead of g or G.
static const unsigned int ftoa_format_f
 Use f or F conversion format instead of g or G.
static const unsigned int ftoa_uppercase
 Use E, F or G conversion format instead of e, f or g.
static const unsigned int ftoa_alternate
 convert value to alternate form.
static const unsigned int ftoa_leftadj
 left-justify number be within the field
static const unsigned int ftoa_zeropad
 pad with zeroes instead of blanks

Static Private Member Functions

static size_t my_strlcpy (char *dst, const char *src, size_t siz)
 private implementation of strlcpy.
static size_t my_strlcat (char *dst, const char *src, size_t siz)
 private implementation of strlcat.
static unsigned int my_sleep (unsigned int seconds)
 makes the current process sleep until seconds seconds have elapsed or a signal arrives which is not ignored.


Detailed Description

A class for various helper functions.

This class is used to comprise a number of "global" helper functions.

Definition at line 62 of file ofstd.h.


Member Function Documentation

static double OFStandard::atof const char *  s,
OFBool *  success = NULL
[static]
 

converts a floating-point number from an ASCII decimal representation to internal double-precision format.

Unlike the atof() function defined in Posix, this implementation is not affected by a locale setting, the radix character is always assumed to be '.' This implementation does not set errno if the input cannot be parsed and it does not implement special handling for overflow/underflow or NaN values. However, a return code indicates whether or not a successful conversion could be performed. The precision of this implementation is limited to approx. 9 decimal digits. The use of this implementation can be disabled by defining the macro DISABLE_OFSTD_ATOF at compile time; in this case, the locale dependent Posix implementation of sscanf is used and the application is responsible for making sure that the Posix locale is activated at all times.

Parameters:
s A decimal ASCII floating-point number, optionally preceded by white space. Must have form "-I.FE-X", where I is the integer part of the mantissa, F is the fractional part of the mantissa, and X is the exponent. Either of the signs may be "+", "-", or omitted. Either I or F may be omitted, or both. The decimal point isn't necessary unless F is present. The "E" may actually be an "e". E and X may both be omitted (but not just one).
success pointer to return status code, may be NULL. if present, a status code is stored in the variable pointed to by this parameter. The status is OFTrue if a conversion could be performed and OFFalse if the string does not have the expected format.
Returns:
floating-point equivalent of string. If a terminating character is found before any floating-point digits, then zero is returned.

static OFString& OFStandard::combineDirAndFilename OFString result,
const OFString dirName,
const OFString fileName,
const OFBool  allowEmptyDirName = OFFalse
[static]
 

combine the given directory and file name.

Normalizes the directory name and appends the file name (with a path separator) if not empty. If both 'dirName' and 'fileName' are empty strings and the flag 'allowEmptyDirName' is OFFalse the resulting path name is set to "." (current directory). If 'dirName' is "." and the flag 'allowEmptyDirName' is OFTrue an empty directory name is used. NB: This function neither checks whether the given 'dirName' exists nor whether the resulting path name points to a valid or existing file name.

Parameters:
result string variable in which the resulting path name is stored
dirName directory name to be combined with the file name
fileName file name to be combined with the directory name
allowEmptyDirName flag indicating whether an empty directory name is allowed
Returns:
reference to the resulting path name (same as 'result')

static const OFString& OFStandard::convertToMarkupString const OFString sourceString,
OFString markupString,
const OFBool  convertNonASCII = OFFalse,
const OFBool  xmlMode = OFTrue,
const OFBool  newlineAllowed = OFFalse
[static]
 

convert character string to HTML/XML mnenonic string.

Characters with special meaning for HTML/XML (e.g. '<' and '&') are replaced by the corresponding mnenonics (e.g. "&lt;" and "&amp;"). If flag 'convertNonASCII' is OFTrue all characters > #127 are also converted (useful if only HTML 3.2 is supported which does not allow to specify the character set).

Parameters:
sourceString source string to be converted
markupString reference to character string where the result should be stored
convertNonASCII convert non-ASCII characters (> #127) to numeric value (&nnn;) if OFTrue
xmlMode convert to XML markup string if OFTrue, HTML string otherwise. LF and CR are encoded as "&#10;" and "&#13;" in XML mode, the flag 'newlineAllowed' has no meaning in this case.
newlineAllowed optional flag indicating whether newlines are allowed or not. If they are allowed the text "<br>" is used, "&para;" otherwise. The following combinations are accepted: LF, CR, LF CR, CF LF.
Returns:
reference to resulting 'markupString' (might be empty if 'sourceString' was empty)

static size_t OFStandard::decodeBase64 const OFString data,
unsigned char *&  result
[static]
 

decode "Base64" encoded string.

Any character that does not belong to the Base64 alphabet (0..9, A..Z, a..z, + and /) is ignored when decoding the input string. This is especially true for line breaks which are usually contained in MIME (RFC 2045) encoded streams (see above). The first occurence of a '=' character is taken as evidence that the end of the data has been reached. NB: The memory buffer in which the binary output is stored is allocated inside this function and has to to be freed (using "delete[]") by the caller! Do not pass a pointer to an already allocated buffer to this function, the caller does not know the exact size anyway.

Parameters:
data Base64 encoded input data (possibly padded with '=' at the end)
result receives pointer to resulting buffer with binary data (big endian encoded)
Returns:
length of the resulting binary data (0 if an error occurred, in this case the buffer is deleted internally)

static OFBool OFStandard::dirExists const OFString dirName  )  [static]
 

check whether the given directory exists.

This function also checks that the specified path points to directory and not to a file (or the like).

Parameters:
dirName name of the directory to be checked
Returns:
OFTrue if directory exists, OFFalse otherwise

static const OFString& OFStandard::encodeBase64 const unsigned char *  data,
const size_t  length,
OFString result,
const size_t  width = 0
[static]
 

encode binary data according to "Base64" as described in RFC 2045 (MIME).

Basic algorithm: groups of 3 bytes from the binary input are coded as groups of 4 bytes in the textual output. The input data is 'padded' with zeros to create a length that is an even multiple of 3. A special character ('=') is used to denote padding so that the output can be decoded back to its exact size. If the input data is NULL an empty string is returned.

Parameters:
data buffer with binary data to be encoded (big endian required!)
length length of the input data buffer (in bytes)
result reference to resulting string variable (Base64 encoded)
width maximum number of characters per line in the output string (default: 0 = no line breaks, typical for MIME = 72)
Returns:
reference to the resulting string

static OFBool OFStandard::fileExists const OFString fileName  )  [static]
 

check whether the given file exists.

This function also checks that the specified path points to file and not to a directory (or the like).

Parameters:
fileName name of the file to be checked
Returns:
OFTrue if file exists, OFFalse otherwise

static void OFStandard::ftoa char *  target,
size_t  targetSize,
double  value,
unsigned int  flags = 0,
int  width = 0,
int  precision = -1
[static]
 

formats a floating-point number into an ASCII string.

This function works similar to sprintf(), except that this implementation is not affected by a locale setting. The radix character is always '.'.

This implementation guarantees that the given string size is always respected by using strlcpy to copy the formatted string into the target buffer.

The use of this implementation can be disabled by defining the macro DISABLE_OFSTD_FTOA at compile time; in this case, the locale dependent Posix implementation of sprintf is used and the application is responsible for making sure that the Posix locale is activated at all times.

Parameters:
target pointer to target string buffer
targetSize size of target string buffer
value double value to be formatted
flags processing flags. Any of the flags defined below can be combined by bit-wise or.
width width from format (8d), or 0
precision precision from format (%.3d), or -1

static OFBool OFStandard::isReadable const OFString pathName  )  [static]
 

check whether the given path is readable.

This function works for both files and directories.

Parameters:
pathName name of the path to be checked
Returns:
OFTrue if path is readable, OFFalse otherwise

static OFBool OFStandard::isWriteable const OFString pathName  )  [static]
 

check whether the given path is writeable.

This function works for both files and directories.

Parameters:
pathName name of the path to be checked
Returns:
OFTrue if path is writeable, OFFalse otherwise

static unsigned int OFStandard::my_sleep unsigned int  seconds  )  [static, private]
 

makes the current process sleep until seconds seconds have elapsed or a signal arrives which is not ignored.

Parameters:
seconds number of seconds to sleep
Returns:
Zero if the requested time has elapsed, or the number of seconds left to sleep.

Referenced by sleep().

static size_t OFStandard::my_strlcat char *  dst,
const char *  src,
size_t  siz
[static, private]
 

private implementation of strlcat.

Called when strlcat is not available in the standard library.

Parameters:
dst destination buffer of size siz, must not be NULL
src source string, must not be NULL
siz size of destination buffer
Returns:
the total length of the string the function tried to create, i.e. the initial length of dst plus the length of src.

Referenced by strlcat().

static size_t OFStandard::my_strlcpy char *  dst,
const char *  src,
size_t  siz
[static, private]
 

private implementation of strlcpy.

Called when strlcpy is not available in the standard library.

Parameters:
dst destination buffer of size siz, must not be NULL
src source string, must not be NULL
siz size of destination buffer
Returns:
the total length of the string the function tried to create, i.e. strlen(src).

Referenced by strlcpy().

static OFString& OFStandard::normalizeDirName OFString result,
const OFString dirName,
const OFBool  allowEmptyDirName = OFFalse
[static]
 

normalize the given directory name.

Removes trailing path separators from the directory name. If the resulting directory name is an empty string and the flag 'allowEmptyDirName' is OFFalse the directory name is set to "." (current directory). If the resulting directory name is "." and the flag 'allowEmptyDirName' is OFTrue the directory name is set to an empty string.

Parameters:
result string variable in which the resulting directory name is stored
dirName directory name to be normalized
allowEmptyDirName flag indicating whether an empty directory name is allowed
Returns:
reference to the resulting directory name (same as 'result')

static OFBool OFStandard::pathExists const OFString pathName  )  [static]
 

check whether the given path exists.

This function does not distinguish files from directories (use 'fileExists()' or 'directoryExists()' if required).

Parameters:
pathName name of the path to be checked
Returns:
OFTrue if path exists, OFFalse otherwise

static size_t OFStandard::searchDirectoryRecursively const OFString directory,
OFList< OFString > &  fileList,
const OFString pattern,
const OFString dirPrefix
[static]
 

scan a given directory recursively and add all filenames found to a list

Parameters:
directory name of the directory to be scanned
fileList list to which the filenames are added. Please note that the list is not not cleared automatically.
pattern optional wildcard pattern used to match the filenames against. By default all files match. In order to work under Unix the system function fnmatch() is required.
dirPrefix optional prefix added to the directory name. This prefix will, however, not be part of the filenames added to the list.
Returns:
number of new files added to the list

static unsigned int OFStandard::sleep unsigned int  seconds  )  [inline, static]
 

makes the current process sleep until seconds seconds have elapsed or a signal arrives which is not ignored.

Parameters:
seconds number of seconds to sleep
Returns:
Zero if the requested time has elapsed, or the number of seconds left to sleep.

Definition at line 378 of file ofstd.h.

References my_sleep().

static OFBool OFStandard::stringMatchesCharacterSet const char *  str,
const char *  charset
[static]
 

Checks if a given string consists only of characters which are specified in a given charset.

Note that in case one of the parameters equals NULL, OFTrue will be returned.

Parameters:
str String which shall be checked.
charset Possible character set for s.
Returns:
OFTrue if the given string consists only of characters which are specified in the given charset; OFFalse otherwise.

static size_t OFStandard::strlcat char *  dst,
const char *  src,
size_t  siz
[inline, static]
 

This function appends the NUL-terminated string src to the end of dst.

It will append at most size - strlen(dst) - 1 bytes, NUL- terminating the result. It is designed to be a safer, more consistent, and less error-prone replacement for strncat(3). strlcat takes the full size of the buffer (not just the length) and guarantees to NUL-terminate the result (as long as size is larger than 0). Note that you should include a byte for the NUL in size. Also note that strlcat only operates on true C strings, i. e. dst and src must be NUL-terminated.

Parameters:
dst destination buffer of size siz, must not be NULL
src source string, must not be NULL
siz size of destination buffer
Returns:
the total length of the string the function tried to create, i.e. the initial length of dst plus the length of src. While this may seem somewhat confusing it was done to make truncation detection simple.

Definition at line 110 of file ofstd.h.

References my_strlcat().

static size_t OFStandard::strlcpy char *  dst,
const char *  src,
size_t  siz
[inline, static]
 

This function copies up to size - 1 characters from the NUL- terminated string src to dst, NUL-terminating the result.

It is designed to be a safer, more consistent, and less error-prone replacement for strncpy(3). strlcpy takes the full size of the buffer (not just the length) and guarantees to NUL-terminate the result (as long as size is larger than 0). Note that you should include a byte for the NUL in size. Also note that strlcpy only operates on true C strings, i. e. src must be NUL-terminated.

Parameters:
dst destination buffer of size siz, must not be NULL
src source string, must not be NULL
siz size of destination buffer
Returns:
the total length of the string the function tried to create, i.e. strlen(src). While this may seem somewhat confusing it was done to make truncation detection simple.

Definition at line 84 of file ofstd.h.

References my_strlcpy().


Member Data Documentation

const unsigned int OFStandard::ftoa_alternate [static]
 

convert value to alternate form.

The result will always contain a decimal point, even if no digits follow the point. For g and G conversions, trailing zeroes will not be removed from the result.

Definition at line 353 of file ofstd.h.


The documentation for this class was generated from the following file:


Generated on 20 Dec 2005 for OFFIS DCMTK Version 3.5.4 by Doxygen 1.4.5