diff options
author | Norbert Preining <norbert@preining.info> | 2020-10-12 03:04:00 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2020-10-12 03:04:00 +0000 |
commit | 0ce40abb18ec02ec6fd6bcc5f21612c88daa7578 (patch) | |
tree | 416289fe1448873fd8ca33051f50ad85bffa8aaa /support/dktools/dk4strd.ctr | |
parent | fdb18507cd80dc17f5a5256153d34668b4f4e61c (diff) |
CTAN sync 202010120303
Diffstat (limited to 'support/dktools/dk4strd.ctr')
-rw-r--r-- | support/dktools/dk4strd.ctr | 755 |
1 files changed, 0 insertions, 755 deletions
diff --git a/support/dktools/dk4strd.ctr b/support/dktools/dk4strd.ctr deleted file mode 100644 index 113c429f2f..0000000000 --- a/support/dktools/dk4strd.ctr +++ /dev/null @@ -1,755 +0,0 @@ -%% options - -copyright owner = Dirk Krause -copyright year = 2015-xxxx -SPDX-License-Identifier: BSD-3-Clause - - - -%% header - -/** @file - String functions for dkChar characters. -*/ - -#ifndef DK4CONF_H_INCLUDED -#if DK4_BUILDING_DKTOOLS4 -#include "dk4conf.h" -#else -#include <dktools-4/dk4conf.h> -#endif -#endif - -#ifndef DK4TYPES_H_INCLUDED -#if DK4_BUILDING_DKTOOLS4 -#include "dk4types.h" -#else -#include <dktools-4/dk4types.h> -#endif -#endif - -#ifndef DK4ERROR_H_INCLUDED -#if DK4_BUILDING_DKTOOLS4 -#include "dk4error.h" -#else -#include <dktools-4/dk4error.h> -#endif -#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<br> - if dst or src is NULL or sz is 0, - - DK4_E_BUFFER_TOO_SMALL<br> - if the dst buffer is too small. -*/ -int -dk4str_cpy_s(dkChar *dst, size_t sz, const dkChar *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<br> - if dst or src is NULL or sz is 0, - - DK4_E_MATH_OVERFLOW<br> - if a mathematical overflow occured in size calculation, - - DK4_E_BUFFER_TOO_SMALL<br> - if the concatenated string doest not fit into the buffer. -*/ -int -dk4str_cat_s(dkChar *dst, size_t sz, const dkChar *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 dk4str_cpy_s() - function instead. - - CRT on Windows: Not used. - @param dst Destination buffer address. - @param src Source string. -*/ -void -dk4str_cpy_to_left(dkChar *dst, const dkChar *src); - -/** Find string length. - - CRT on Windows: Optional, disabling CRT reduces functionality - to strings with length fitting to int. - @param src Source string. - @return String length. -*/ -size_t -dk4str_len(const dkChar *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 s1<s2. -*/ -int -dk4str_cmp(const dkChar *s1, const dkChar *s2); - -/** Compare two strings. - - CRT on Windows: Optional. - @param s1 Left string, may be NULL. - @param s2 Right string, may be NULL. - @param n Maximum number of characters to compare. - @return 1 if s1>s2, 0 if s1==s2, -1 if s1<s2. -*/ -int -dk4str_ncmp(const dkChar *s1, const dkChar *s2, size_t n); - -/** Compare two strings, case-insensitive comparison. - - 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 s1<s2. -*/ -int -dk4str_casecmp(const dkChar *s1, const dkChar *s2); - -/** Compare two file path names. - - 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 s1<s2. -*/ -int -dk4str_pathcmp(const dkChar *s1, const dkChar *s2); - -/** Find first occurance of character c in string s. - - CRT on Windows: Optional, disabling CRT degrades performance. - @param s String to search for c. - @param c Character to find. - @return Pointer to first occurance if found, NULL otherwise. -*/ -dkChar * -dk4str_chr(const dkChar *s, dkChar c); - -/** Find last occurance of character c in string s. - - CRT on Windows: Optional, disabling CRT degrades performance. - @param s String to search for c. - @param c Character to find. - @return Pointer to last occurance if found, NULL otherwise. -*/ -dkChar * -dk4str_rchr(const dkChar *s, dkChar c); - -/** Retrieve first token from *stringp. - - CRT on Windows: Optional, disabling CRT degrades performance. - @param stringp Adress of string pointer. - @param delim String containing the delimiter set, - my be NULL to use the default delimiter - set (space, tabulator, carriage return and newline). - @return Pointer to first token on success, NULL if no (further) - token found. -*/ -dkChar * -dk4str_sep(dkChar **stringp, const dkChar *delim); - -/** Find first token in string. - - CRT on Windows: Optional, disabling CRT degrades performance. - @param src String to search for tokens. - @param delim String containing the delimiter characters, - may be NULL to use the default delimiter set. - @return Pointer to first token if found, NULL otherwise. -*/ -dkChar * -dk4str_start(const dkChar *src, const dkChar *delim); - -/** Cut string after first token, find start of second token in string. - - CRT on Windows: Optional, disabling CRT degrades performance. - @param src String to search for tokens, - normally the result of dk4str_start() or a - previous dk4str_next() call. - @param delim String containing the delimiter characters, - may be NULL to use the default delimiter set. - @return Pointer to second token if found, NULL otherwise. -*/ -dkChar * -dk4str_next(dkChar *src, const dkChar *delim); - -/** Split a string into tokens. - - CRT on Windows: Optional, disabling CRT degrades performance. - @param dpp Pointer to string pointer array. - @param szdpp Size of destination string pointer array. - @param src Source string to process. - @param delim String containing delimiter characters, - may be NULL to use the default delimiter set. - @param erp Error report, may be NULL. - @return Number of tokens found on success, 0 if no token - found or on error. - - Error codes: - - DK4_E_INVALID_ARGUMENTS<br> - for invalid function arguments, - - DK4_E_BUFFER_TOO_SMALL<br> - with dt.mem.nelem set to the number of tokens in string if the dpp - array is too short. -*/ -size_t -dk4str_tokenize( - dkChar **dpp, size_t szdpp, dkChar *src, const dkChar *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 -dk4str_normalize(dkChar *src, const dkChar *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 -dk4str_array_index(const dkChar * const *arr, const dkChar *str, int cs); - -/** Find index of a string in an array of strings. - - CRT on Windows: Optional, disabling CRT degrades performance - for case-insensitive comparisons. - @param arr Array of strings allowing abbreviation. - @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 -dk4str_abbr_index( - const dkChar * const *arr, - dkChar spec, - const dkChar *str, - int cs -); - -/** Check whether a text matches a pattern, the text may be abbreviated. - - CRT on windows: Optional, disabling CRT degrades performance - for 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 -dk4str_is_abbr(const dkChar *str, const dkChar *pattern, dkChar spec, int cs); - -/** Check whether a string represents a boolean value. - @param str String to check. - @return 1 if str represents a boolean value, 0 otherwise. -*/ -int -dk4str_is_bool(const dkChar *str); - -/** Check whether a string represents the boolean value TRUE. - - CRT on Windows: Optional, disabling CRT degrades performance. - @param str String to check. - @return 1 if str represents the boolean value TRUE, 0 otherwise. -*/ -int -dk4str_is_on(const dkChar *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 - @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<br> - if src is a NULL pointer, - - DK4_E_MATH_OVERFLOW<br> - on mathematical overflow in size calculation, - - DK4_E_MEMORY_ALLOCATION_FAILED<br> - with mem.elsize and mem.nelem set if no memory is available. -*/ -dkChar * -dk4str_dup(const dkChar *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 -dk4str_rtwh(dkChar *str, const dkChar *whsp); - -/** Remove trailing newline from line. - - CRT on Windows: Optional, disabling CRT degrades performance. - @param lptr Line pointer. -*/ -void -dk4str_delnl(dkChar *lptr); - -/** Skip the first text words in a line, return pointer to start - of next word. - - CRT on Windows: Optional, disabling CRT degrades performance. - @param line Line to process. - @param skip Number of words to skip. - @return Pointer to next word on success, NULL on error. -*/ -const dkChar * -dk4str_skip(const dkChar *line, size_t skip); - - -/** Sanitize string (overwrite using 0 bytes). - - CRT on Windows: Optional. - @param str Address of string to sanitize. - @return 1 on success, 0 on error. -*/ -int -dk4str_sanitize(dkChar *str); - -/** Sanitize string buffer (overwrite using 0 bytes). - - CRT on Windows: Optional. - @param str Address of string buffer. - @param sz Size of string buffer (number of dkChar). - @return 1 on success, 0 on error. -*/ -int -dk4str_buffer_sanitize(dkChar *str, size_t sz); - -/** Sanitize dynamically allocated memory and release it. - - CRT on Windows: Optional. - @param str Address of string to sanitize and release. - @return 1 on success, 0 on error. -*/ -int -dk4str_free_sanitized(dkChar *str); - -#ifdef __cplusplus -} -#endif - - -#if DK4_CHAR_SIZE > 1 -/** Sanitize string and release it, set pointer to NULL. - - CRT on Windows: Optional. - @param p Pointer to string to release. -*/ -#define dk4str_release_sanitized(p) \ -do { if (NULL != p) { (void)dk4strw_free_sanitized(p); } p = NULL; } while (0) -#else -/** Sanitize string and release it, set pointer to NULL. - - CRT on Windows: Optional. - @param p Pointer to string to release. -*/ -#define dk4str_release_sanitized(p) \ -do { if (NULL != p) { (void)dk4str8_free_sanitized(p); } p = NULL; } while (0) -#endif - -%% module - - -#include "dk4conf.h" -#include "dk4strd.h" - -#if DK4_CHAR_SIZE > 1 -#ifndef DK4STRW_H_INCLUDED -#include "dk4strw.h" -#endif -#else -#ifndef DK4STR8_H_INCLUDED -#include "dk4str8.h" -#endif -#endif - - -int -dk4str_cpy_s(dkChar *dst, size_t sz, const dkChar *src, dk4_er_t *erp) -{ -#if DK4_CHAR_SIZE > 1 - return (dk4strw_cpy_s(dst, sz, src, erp)); -#else - return (dk4str8_cpy_s(dst, sz, src, erp)); -#endif -} - - - -int -dk4str_cat_s(dkChar *dst, size_t sz, const dkChar *src, dk4_er_t *erp) -{ -#if DK4_CHAR_SIZE > 1 - return (dk4strw_cat_s(dst, sz, src, erp)); -#else - return (dk4str8_cat_s(dst, sz, src, erp)); -#endif -} - - - -void -dk4str_cpy_to_left(dkChar *dst, const dkChar *src) -{ -#if DK4_CHAR_SIZE > 1 - dk4strw_cpy_to_left(dst, src); -#else - dk4str8_cpy_to_left(dst, src); -#endif -} - - - -size_t -dk4str_len(const dkChar *src) -{ -#if DK4_CHAR_SIZE > 1 - return (dk4strw_len(src)); -#else - return (dk4str8_len(src)); -#endif -} - - - -int -dk4str_cmp(const dkChar *s1, const dkChar *s2) -{ -#if DK4_CHAR_SIZE > 1 - return (dk4strw_cmp(s1, s2)); -#else - return (dk4str8_cmp(s1, s2)); -#endif -} - - - -int -dk4str_ncmp(const dkChar *s1, const dkChar *s2, size_t n) -{ -#if DK4_CHAR_SIZE > 1 - return (dk4strw_ncmp(s1, s2, n)); -#else - return (dk4str8_ncmp(s1, s2, n)); -#endif -} - - -int -dk4str_casecmp(const dkChar *s1, const dkChar *s2) -{ -#if DK4_CHAR_SIZE > 1 - return (dk4strw_casecmp(s1, s2)); -#else - return (dk4str8_casecmp(s1, s2)); -#endif -} - - - -dkChar * -dk4str_sep(dkChar **stringp, const dkChar *delim) -{ -#if DK4_CHAR_SIZE > 1 - return (dk4strw_sep(stringp, delim)); -#else - return (dk4str8_sep(stringp, delim)); -#endif -} - - - -dkChar * -dk4str_start(const dkChar *src, const dkChar *delim) -{ -#if DK4_CHAR_SIZE > 1 - return (dk4strw_start(src, delim)); -#else - return (dk4str8_start(src, delim)); -#endif -} - - - -dkChar * -dk4str_next(dkChar *src, const dkChar *delim) -{ -#if DK4_CHAR_SIZE > 1 - return (dk4strw_next(src, delim)); -#else - return (dk4str8_next(src, delim)); -#endif -} - - - -size_t -dk4str_tokenize( - dkChar **dpp, size_t szdpp, dkChar *src, const dkChar *delim, dk4_er_t *erp -) -{ -#if DK4_CHAR_SIZE > 1 - return (dk4strw_tokenize(dpp, szdpp, src, delim, erp)); -#else - return (dk4str8_tokenize(dpp, szdpp, src, delim, erp)); -#endif -} - - - -void -dk4str_normalize(dkChar *src, const dkChar *delim) -{ -#if DK4_CHAR_SIZE > 1 - dk4strw_normalize(src, delim); -#else - dk4str8_normalize(src, delim); -#endif -} - - - -#if (defined(_WIN32) && DK4_USE_WINDOWS_LOCAL_ALLOC) \ - || (DK4_HAVE_MALLOC && DK4_HAVE_FREE) - -dkChar * -dk4str_dup(const dkChar *src, dk4_er_t *erp) -{ -#if DK4_CHAR_SIZE > 1 - return (dk4strw_dup(src, erp)); -#else - return (dk4str8_dup(src, erp)); -#endif -} - -#endif -/* if (defined(_WIN32) ... */ - - - -int -dk4str_array_index(const dkChar * const *arr, const dkChar *str, int cs) -{ -#if DK4_CHAR_SIZE > 1 - return (dk4strw_array_index(arr, str, cs)); -#else - return (dk4str8_array_index(arr, str, cs)); -#endif -} - - - -int -dk4str_is_abbr(const dkChar *str, const dkChar *pattern, dkChar spec, int cs) -{ -#if DK4_CHAR_SIZE > 1 - return (dk4strw_is_abbr(str, pattern, spec, cs)); -#else - return (dk4str8_is_abbr(str, pattern, spec, cs)); -#endif -} - - - -int -dk4str_abbr_index( - const dkChar * const *arr, - dkChar spec, - const dkChar *str, - int cs -) -{ -#if DK4_CHAR_SIZE > 1 - return (dk4strw_abbr_index(arr, spec, str, cs)); -#else - return (dk4str8_abbr_index(arr, spec, str, cs)); -#endif -} - - - -int -dk4str_is_bool(const dkChar *str) -{ -#if DK4_CHAR_SIZE > 1 - return (dk4strw_is_bool(str)); -#else - return (dk4str8_is_bool(str)); -#endif -} - - - -int -dk4str_is_on(const dkChar *str) -{ -#if DK4_CHAR_SIZE > 1 - return (dk4strw_is_on(str)); -#else - return (dk4str8_is_on(str)); -#endif -} - - - -dkChar * -dk4str_chr(const dkChar *s, dkChar c) -{ -#if DK4_CHAR_SIZE > 1 - return (dk4strw_chr(s, c)); -#else - return (dk4str8_chr(s, c)); -#endif -} - - - -dkChar * -dk4str_rchr(const dkChar *s, dkChar c) -{ -#if DK4_CHAR_SIZE > 1 - return (dk4strw_rchr(s, c)); -#else - return (dk4str8_rchr(s, c)); -#endif -} - - - -int -dk4str_pathcmp(const dkChar *s1, const dkChar *s2) -{ -#if DK4_HAVE_CASE_INSENSITIVE_PATHNAMES - return (dk4str_casecmp(s1, s2)); -#else - return (dk4str_cmp(s1, s2)); -#endif -} - - - -void -dk4str_rtwh(dkChar *str, const dkChar *whsp) -{ -#if DK4_CHAR_SIZE > 1 - dk4strw_rtwh(str, whsp); -#else - dk4str8_rtwh(str, whsp); -#endif -} - - - -void -dk4str_delnl(dkChar *lptr) -{ -#if DK4_CHAR_SIZE > 1 - dk4strw_delnl(lptr); -#else - dk4str8_delnl(lptr); -#endif -} - - - -const dkChar * -dk4str_skip(const dkChar *line, size_t skip) -{ -#if DK4_CHAR_SIZE > 1 - return (dk4strw_skip(line, skip)); -#else - return (dk4str8_skip(line, skip)); -#endif -} - - - - -int -dk4str_sanitize(dkChar *str) -{ -#if DK4_CHAR_SIZE > 1 - return (dk4strw_sanitize(str)); -#else - return (dk4str8_sanitize(str)); -#endif -} - - - -int -dk4str_buffer_sanitize(dkChar *str, size_t sz) -{ -#if DK4_CHAR_SIZE > 1 - return (dk4strw_buffer_sanitize(str, sz)); -#else - return (dk4str8_buffer_sanitize(str, sz)); -#endif -} - - - -int -dk4str_free_sanitized(dkChar *str) -{ -#if DK4_CHAR_SIZE > 1 - return (dk4strw_free_sanitized(str)); -#else - return (dk4str8_free_sanitized(str)); -#endif -} - |