/* WARNING: This file was generated by dkct. Changes you make here will be lost if dkct is run again! You should modify the original source and run dkct on it. Original source: dk4str8.ctr */ /* Copyright (C) 2015-2017, Dirk Krause Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above opyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef DK4STR8_H_INCLUDED /** Avoid multiple inclusions. */ #define DK4STR8_H_INCLUDED 1 #line 10 "dk4str8.ctr" /** @file Additional string functions for 8 bit characters. Although some of the functions in this module duplicate functionality from string.h functions, you should use the functions from this module. With DK4DK4_WIN_AVOID_CRT or DK4_WIN_DENY_CRT defined to non-zero these functions call Windows API functions like lstrcmpA() ... instead of CRT functions. */ #ifndef DK4CONF_H_INCLUDED #include "dk4conf.h" #endif #ifndef DK4TYPES_H_INCLUDED #include "dk4types.h" #endif #ifndef DK4ERROR_H_INCLUDED #include "dk4error.h" #endif #ifndef STDLIB_H_INCLUDED #include #define STDLIB_H_INCLUDED 1 #endif #ifdef __cplusplus extern "C" { #endif /** Copy string, check destination buffer size. CRT on Windows: Optional. @param dst Destination buffer address. @param sz Destination buffer size. @param src Source string. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if dst or src is NULL or sz is 0, - DK4_E_BUFFER_TOO_SMALL
if the dst buffer is too small. */ int dk4str8_cpy_s(char *dst, size_t sz, const char *src, dk4_er_t *erp); /** Concatenate strings, check destination buffer size. CRT on Windows: Optional. @param dst Destination buffer address. @param sz Destination buffer size. @param src Source string. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if dst or src is NULL or sz is 0, - DK4_E_MATH_OVERFLOW
if a mathematical overflow occured in size calculation, - DK4_E_BUFFER_TOO_SMALL
if the concatenated string doest not fit into the buffer. */ int dk4str8_cat_s(char *dst, size_t sz, const char *src, dk4_er_t *erp); /** Copy characters within a string from right to left. This copy operation is intended for moving characters within one string from right to left, making the string shorter as is. This function does not check buffer size or report any error. For normal string copy operations, use the dk4str8_cpy_s() function instead. CRT on Windows: Not used. @param dst Destination buffer address. @param src Source string. */ void dk4str8_cpy_to_left(char *dst, const char *src); /** Find string length. CRT on Windows: Optional. @param src Source string. @return String length. */ size_t dk4str8_len(const char *src); /** Compare two strings. CRT on Windows: Optional. @param s1 Left string, may be NULL. @param s2 Right string, may be NULL. @return 1 if s1>s2, 0 if s1==s2, -1 if s1s2, 0 if s1==s2, -1 if s1s2, 0 if s1==s2, -1 if s1s2, 0 if s1==s2, -1 if s1 for invalid function arguments, - DK4_E_BUFFER_TOO_SMALL
with dt.mem.nelem set to the number of tokens in string if the dpp array is too short. */ size_t dk4str8_tokenize( char **dpp, size_t szdpp, char *src, const char *delim, dk4_er_t *erp ); /** Normalize a string (remove leading and trailing delimiters, replace delimiter sequences by just one delimiter). CRT on Windows: Optional, disabling CRT degrades performance. @param src Buffer containing the string to normalize. @param delim String containing delimiter characters, may be NULL to use the default delimiter set. */ void dk4str8_normalize(char *src, const char *delim); /** Find index of a string in an array of strings. CRT on Windows: Optional. @param arr Array of strings. @param str String to find in array. @param cs Flag: Case-sensitive search (0=no, other=yes). @return Non-negative index value on success, -1 on error. */ int dk4str8_array_index(const char * const *arr, const char *str, int cs); /** Find index of a string in an array of strings. CRT on Windows: Optional, disabling CRT degrades performances and reduces to upper-case conversion to characters 'a' to 'z'. @param arr Array of string allowing abbreviations. @param spec Special character indicating start of optional text. @param str String to find in array. @param cs Flag: Case-sensitive search (0=no, other=yes). @return Non-negative index value on success, -1 on error. */ int dk4str8_abbr_index(const char * const *arr, char spec, const char *str, int cs); /** Check whether a text matches a pattern, the text may be abbreviated. CRT on Windows: Optional, disabling CRT degrades performances and reduces to upper-case conversion to characters 'a' to 'z' in case-insensitive comparisons. @param str Text to check. @param pattern Pattern for comparison. @param spec Special character marking the abbreviation in the pattern. @param cs Flag: Case sensitive (1) or not (0). @return 1 for a match, 0 otherwise. */ int dk4str8_is_abbr(const char *str, const char *pattern, char spec, int cs); /** Check whether a string represents a boolean value. CRT on Windows: Optional, disabling CRT degrades performances. @param str String to check. @return 1 if str represents a boolean value, 0 otherwise. */ int dk4str8_is_bool(const char *str); /** Check whether a string represents the boolean value TRUE. CRT on Windows: Optional, disabling CRT degrades performances. @param str String to check. @return 1 if str represents the boolean value TRUE, 0 otherwise. */ int dk4str8_is_on(const char *str); #if (defined(_WIN32) && DK4_USE_WINDOWS_LOCAL_ALLOC) \ || (DK4_HAVE_MALLOC && DK4_HAVE_FREE) /** Duplicate string in dynamically allocated memory. CRT on Windows: Optional, disabling CRT reduces functionality to strings with length fitting to int and overall size in bytes - including finalizer - fitting into a DWORD. @param src String to duplicate. @param erp Error report, may be NULL. @return Pointer to string in new memory on succes, NULL on error. Use dk4mem_free() to release the memory after usage. Error codes: - DK4_E_INVALID_ARGUMENTS
if src is a NULL pointer, - DK4_E_MATH_OVERFLOW
on mathematical overflow in size calculation, - DK4_E_MEMORY
if no memory is available. */ char * dk4str8_dup(const char *src, dk4_er_t *erp); #endif /* if (defined(_WIN32) ... */ /** Remove trailing white spaces. CRT on Windows: Optional, disabling CRT degrades performance. @param str String to remove white spaces from. @param whsp White spaces set. */ void dk4str8_rtwh(char *str, const char *whsp); /** Convert character to uppercase. CRT on Windows: Optional, disabling CRT degrades performances and reduces functionality to characters 'a' to 'z'. @param c Character to convert. @return Conversion result. */ char dk4str8_toupper(char c); /** Convert character to lowercase. CRT on Windows: Optional, disabling CRT degrades performances and reduces functionality to characters 'A' to 'Z'. @param c Character to convert. @return Conversion result. */ char dk4str8_tolower(char c); /** Remove trailing newline from line. @param lptr Line pointer. */ void dk4str8_delnl(char *lptr); /** Skip the first text words in a line, return pointer to start of next word. @param line Line to process. @param skip Number of words to skip. @return Pointer to next word on success, NULL on error. */ const char * dk4str8_skip(const char *line, size_t skip); /** Sanitize string (overwrite using 0 bytes). @param str Address of string to sanitize. @return 1 on success, 0 on error. */ int dk4str8_sanitize(char *str); /** Sanitize string buffer (overwrite using 0 bytes). @param str Address of string buffer. @param sz Size of string buffer (number of elements). @return 1 on success, 0 on error. */ int dk4str8_buffer_sanitize(char *str, size_t sz); /** Sanitize dynamically allocated memory and release it. @param str Address of string to sanitize and release. @return 1 on success, 0 on error. */ int dk4str8_free_sanitized(char *str); #ifdef __cplusplus } #endif /** Sanitize string and release it, set pointer to NULL. @param p Pointer to string to release. */ #define dk4str8_release_sanitized(p) \ do { if (NULL != p) { (void)dk4str8_free_sanitized(p); } p = NULL; } while (0) #endif