Public Types | |
enum | E_MarkupMode { MM_HTML, MM_HTML32, MM_XHTML, MM_XML } |
Markup language mode. More... | |
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 const char * | strerror (const int errnum, char *buf, const size_t buflen) |
convert a given error code to a string. | |
static OFString & | toUpper (OFString &result, const OFString &value) |
returns the upper-case version of a given string | |
static OFString & | toUpper (OFString &value) |
returns the upper-case version of a given string. | |
static OFString & | toLower (OFString &result, const OFString &value) |
returns the lower-case version of a given string | |
static OFString & | toLower (OFString &value) |
returns the lower-case version of a given string. | |
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 OFString & | getDirNameFromPath (OFString &result, const OFString &pathName, const OFBool assumeDirName=OFTrue) |
get directory name component from given path name. | |
static OFString & | getFilenameFromPath (OFString &result, const OFString &pathName, const OFBool assumeFilename=OFTrue) |
get file name component from given path name. | |
static OFString & | normalizeDirName (OFString &result, const OFString &dirName, const OFBool allowEmptyDirName=OFFalse) |
normalize the given directory name. | |
static OFString & | combineDirAndFilename (OFString &result, const OFString &dirName, const OFString &fileName, const OFBool allowEmptyDirName=OFFalse) |
combine the given directory and file name. | |
static OFCondition | removeRootDirFromPathname (OFString &result, const OFString &rootDir, const OFString &pathName, const OFBool allowLeadingPathSeparator=OFTrue) |
remove root directory prefix from given path name. | |
static size_t | searchDirectoryRecursively (const OFString &directory, OFList< OFString > &fileList, const OFString &pattern, const OFString &dirPrefix, const OFBool recurse=OFTrue) |
scan a given directory (recursively) and add all filenames found to a list | |
static OFBool | deleteFile (const OFString &filename) |
delete given file from filesystem | |
static size_t | getFileSize (const OFString &filename) |
determine size of given file (in bytes) | |
static OFBool | checkForMarkupConversion (const OFString &sourceString, const OFBool convertNonASCII=OFFalse) |
check whether conversion to HTML/XML mnenonic string is required. | |
static OFCondition | convertToMarkupStream (STD_NAMESPACE ostream &out, const OFString &sourceString, const OFBool convertNonASCII=OFFalse, const E_MarkupMode markupMode=MM_XML, const OFBool newlineAllowed=OFFalse) |
convert character string to HTML/XHTML/XML mnenonic stream. | |
static const OFString & | convertToMarkupString (const OFString &sourceString, OFString &markupString, const OFBool convertNonASCII=OFFalse, const E_MarkupMode markupMode=MM_XML, const OFBool newlineAllowed=OFFalse) |
convert character string to HTML/XHTML/XML mnenonic string. | |
static OFCondition | encodeBase64 (STD_NAMESPACE ostream &out, const unsigned char *data, const size_t length, const size_t width=0) |
encode binary data according to "Base64" as described in RFC 2045 (MIME). | |
static const OFString & | encodeBase64 (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 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 long | getProcessID () |
Determines the identification of the running process. | |
static OFBool | check32BitAddOverflow (const Uint32 summand1, const Uint32 summand2) |
check whether the addition of two 32-bit integers yields in an overflow | |
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 |
This class is used to comprise a number of "global" helper functions.
Definition at line 59 of file ofstd.h.
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.
dst | destination buffer of size siz, must not be NULL | |
src | source string, must not be NULL | |
siz | size of destination buffer |
Definition at line 97 of file ofstd.h.
References my_strlcpy().
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.
dst | destination buffer of size siz, must not be NULL | |
src | source string, must not be NULL | |
siz | size of destination buffer |
Definition at line 123 of file ofstd.h.
References my_strlcat().
static const char* OFStandard::strerror | ( | const int | errnum, | |
char * | buf, | |||
const size_t | buflen | |||
) | [static] |
convert a given error code to a string.
This function wraps the various approaches found on different systems. Internally, the standard function strerror() or strerror_r() is used.
errnum | error code to be converted | |
buf | buffer which is used to store the result string (if supported) | |
buflen | size if the buffer in bytes |
Referenced by OFFile::getLastErrorString().
returns the upper-case version of a given string
result | string variable in which the result is stored | |
value | string value to be converted to upper case |
returns the upper-case version of a given string.
NB: This function changes the parameter 'value'.
value | string value to be converted to upper case |
returns the lower-case version of a given string
result | string variable in which the result is stored | |
value | string value to be converted to lower case |
returns the lower-case version of a given string.
NB: This function changes the parameter 'value'.
value | string value to be converted to lower case |
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).
pathName | name of the path to be checked |
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).
fileName | name of the file to be checked |
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).
dirName | name of the directory to be checked |
static OFBool OFStandard::isReadable | ( | const OFString & | pathName | ) | [static] |
check whether the given path is readable.
This function works for both files and directories.
pathName | name of the path to be checked |
static OFBool OFStandard::isWriteable | ( | const OFString & | pathName | ) | [static] |
check whether the given path is writeable.
This function works for both files and directories.
pathName | name of the path to be checked |
static OFString& OFStandard::getDirNameFromPath | ( | OFString & | result, | |
const OFString & | pathName, | |||
const OFBool | assumeDirName = OFTrue | |||
) | [static] |
get directory name component from given path name.
Extracts the substring before the last path separator. If there is no path separator in the given path name, the value of 'pathName' is returned by default; if 'assumeDirName' is OFFalse, an empty string is returned. NB: This function neither checks whether the given 'pathName' exists nor whether the resulting name points to a valid or existing directory.
result | string variable in which the resulting directory name is stored | |
pathName | path name from which the directory name should be extracted | |
assumeDirName | assume that there always is a directory name in 'pathName' |
static OFString& OFStandard::getFilenameFromPath | ( | OFString & | result, | |
const OFString & | pathName, | |||
const OFBool | assumeFilename = OFTrue | |||
) | [static] |
get file name component from given path name.
Extracts the substring after the last path separator. If there is no path separator in the given path name, the value of 'pathName' is returned by default; if 'assumeFilename' is OFFalse, an empty string is returned. NB: This function neither checks whether the given 'pathName' exists nor whether the resulting name points to a valid or existing file.
result | string variable in which the resulting file name is stored | |
pathName | path name from which the file name should be extracted | |
assumeFilename | assume that there always is a file name in 'pathName' |
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.
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 |
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. Furthermore, the value of 'dirName' is ignored if 'fileName' starts with a path separator.
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 |
static OFCondition OFStandard::removeRootDirFromPathname | ( | OFString & | result, | |
const OFString & | rootDir, | |||
const OFString & | pathName, | |||
const OFBool | allowLeadingPathSeparator = OFTrue | |||
) | [static] |
remove root directory prefix from given path name.
In case 'pathName' starts with 'rootDir', the common prefix is removed. Otherwise, an empty string is returned.
result | string variable in which the resulting path name is stored | |
rootDir | name of the root directory to be removed | |
pathName | path name from which the root directory (prefix) is removed | |
allowLeadingPathSeparator | flag indicating whether a leading path separator is allowed for the resulting path name (automatically removed otherwise) |
static size_t OFStandard::searchDirectoryRecursively | ( | const OFString & | directory, | |
OFList< OFString > & | fileList, | |||
const OFString & | pattern, | |||
const OFString & | dirPrefix, | |||
const OFBool | recurse = OFTrue | |||
) | [static] |
scan a given directory (recursively) and add all filenames found to a list
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. | |
recurse | flag indicating whether to search recursively (default) or not |
static OFBool OFStandard::deleteFile | ( | const OFString & | filename | ) | [static] |
delete given file from filesystem
filename | name of the file (including directory) to delete |
static size_t OFStandard::getFileSize | ( | const OFString & | filename | ) | [static] |
determine size of given file (in bytes)
filename | name of the file to be checked |
static OFBool OFStandard::checkForMarkupConversion | ( | const OFString & | sourceString, | |
const OFBool | convertNonASCII = OFFalse | |||
) | [static] |
check whether conversion to HTML/XML mnenonic string is required.
This check can be performed before convertToMarkupStream() or convertToMarkupString() is called in order to speed up the process in case the conversion is not required.
sourceString | source string to be checked | |
convertNonASCII | convert non-ASCII characters (< #32 and >= #127) to numeric value (&#nnn;) if OFTrue |
static OFCondition OFStandard::convertToMarkupStream | ( | STD_NAMESPACE ostream & | out, | |
const OFString & | sourceString, | |||
const OFBool | convertNonASCII = OFFalse , |
|||
const E_MarkupMode | markupMode = MM_XML , |
|||
const OFBool | newlineAllowed = OFFalse | |||
) | [static] |
convert character string to HTML/XHTML/XML mnenonic stream.
Characters with special meaning for HTML/XHTML/XML (e.g. '<' and '&') are replaced by the corresponding mnenonics (e.g. "<" and "&"). If flag 'convertNonASCII' is OFTrue, all characters < #32 and >= #127 are also converted (useful if only HTML 3.2 is supported which does not allow to specify the character set). In HTML 3.2 mode, the quotation mark (") is converted to """ instead of """ because the latter entity is not defined. In HTML mode, the apostrophe sign (') is converted to "'" instead of "'" for the same reason.
out | stream used for the HTML/XHTML/XML mnenonic output | |
sourceString | source string to be converted | |
convertNonASCII | convert non-ASCII characters (< # 32 and >= #127) to numeric value (&#nnn;) if OFTrue | |
markupMode | convert to HTML, HTML 3.2, XHTML or XML markup. LF and CR are encoded as " " and " " 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>" (HTML) or "<br />" (XHTML) is used, "¶" otherwise. The following combinations are accepted: LF, CR, LF CR, CF LF. |
static const OFString& OFStandard::convertToMarkupString | ( | const OFString & | sourceString, | |
OFString & | markupString, | |||
const OFBool | convertNonASCII = OFFalse , |
|||
const E_MarkupMode | markupMode = MM_XML , |
|||
const OFBool | newlineAllowed = OFFalse | |||
) | [static] |
convert character string to HTML/XHTML/XML mnenonic string.
Characters with special meaning for HTML/XHTML/XML (e.g. '<' and '&') are replaced by the corresponding mnenonics (e.g. "<" and "&"). If flag 'convertNonASCII' is OFTrue, all characters < #32 and >= #127 are also converted (useful if only HTML 3.2 is supported which does not allow to specify the character set). In HTML 3.2 mode, the quotation mark (") is converted to """ instead of """ because the latter entity is not defined. In HTML mode, the apostrophe sign (') is converted to "'" instead of "'" for the same reason.
sourceString | source string to be converted | |
markupString | reference to character string where the result should be stored | |
convertNonASCII | convert non-ASCII characters (< # 32 and >= #127) to numeric value (&#nnn;) if OFTrue | |
markupMode | convert to HTML, HTML 3.2, XHTML or XML markup string. 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>" (HTML) or "<br />" (XHTML) is used, "¶" otherwise. The following combinations are accepted: LF, CR, LF CR, CF LF. |
static OFCondition OFStandard::encodeBase64 | ( | STD_NAMESPACE ostream & | out, | |
const unsigned char * | data, | |||
const size_t | length, | |||
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 error code (EC_IllegalParameter) is returned.
out | output stream used for the base64 encoded data | |
data | buffer with binary data to be encoded (big endian required!) | |
length | length of the input data buffer (in bytes) | |
width | maximum number of characters per line in the output stream (default: 0 = no line breaks, typical for MIME = 72) |
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.
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) |
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.
data | Base64 encoded input data (possibly padded with '=' at the end) | |
result | receives pointer to resulting buffer with binary data (big endian encoded) |
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.
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. |
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.
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 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
seconds | number of seconds to sleep |
Definition at line 543 of file ofstd.h.
References my_sleep().
static long OFStandard::getProcessID | ( | ) | [static] |
Determines the identification of the running process.
static OFBool OFStandard::check32BitAddOverflow | ( | const Uint32 | summand1, | |
const Uint32 | summand2 | |||
) | [inline, static] |
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.
dst | destination buffer of size siz, must not be NULL | |
src | source string, must not be NULL | |
siz | size of destination buffer |
Referenced by strlcpy().
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.
dst | destination buffer of size siz, must not be NULL | |
src | source string, must not be NULL | |
siz | size of destination buffer |
Referenced by strlcat().
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
seconds | number of seconds to sleep |
Referenced by sleep().
const unsigned int OFStandard::ftoa_alternate [static] |