OpenDNSSEC-enforcer  1.4.6
string_util.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2009 Nominet UK. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
17  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
19  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
21  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
23  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  */
26 
27 #ifndef KSM_STRING_UTIL_H
28 #define KSM_STRING_UTIL_H
29 
30 /*+
31  * Filename: string_util.h
32  *
33  * Description:
34  * Definitions of the string utilities used by all the whois programs.
35 -*/
36 
37 #include <ksm/system_includes.h>
38 #include <ksm/memory.h>
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 #define COMMENT_CHAR ("#")
45 
46 void StrUncomment(char* line);
47 void StrWhitespace(char* line);
48 char* StrStrdup(const char* string);
49 void StrStrncpy(char* dest, const char* src, size_t destlen);
50 void StrStrncat(char* dest, const char* src, size_t destlen);
51 void StrTrimR(char* text);
52 char* StrTrimL(char* text);
53 char* StrTrim(char* text);
54 size_t StrToLower(char* text);
55 size_t StrToUpper(char* text);
56 size_t StrReplaceCharN(char* string, size_t len, char search, char replace);
57 size_t StrReplaceChar(char* string, char search, char replace);
58 size_t StrTrimmedLength(const char* string);
59 
60 /*
61  * The next definition allows for possible alternative memory strategies to
62  * be used for string routines. At any rate, StrFree() should be used to free
63  * a string allocated by StrStrdup().
64  */
65 
66 #define StrFree(x) MemFree(x)
67 
68 /*
69  * A simple macro (the idea comes from the memcached code) that allows the
70  * compile-time determination of the length of a literal string. Note that
71  * the string must be declared by:
72  *
73  * char string[] = "this is a literal string"
74  *
75  * rather than
76  *
77  * char* string = "this is a literal string"
78  *
79  * Use of the macro on the former gives the correct string length. On the
80  * latter it gives "sizeof(char*) - 1".
81  */
82 
83 #define STR_LENGTH(x) (sizeof(x) - 1)
84 
85 #ifdef __cplusplus
86 }
87 #endif
88 
89 #endif /* KSM_STRING_UTIL_H */
void StrWhitespace(char *line)
Definition: string_util.c:94
char * StrStrdup(const char *string)
Definition: string_util.c:124
void StrStrncpy(char *dest, const char *src, size_t destlen)
Definition: string_util.c:176
void StrStrncat(char *dest, const char *src, size_t destlen)
Definition: string_util.c:191
void StrTrimR(char *text)
Definition: string_util.c:228
size_t StrToLower(char *text)
Definition: string_util.c:323
size_t StrReplaceChar(char *string, char search, char replace)
Definition: string_util.c:413
void StrUncomment(char *line)
Definition: string_util.c:65
char * StrTrimL(char *text)
Definition: string_util.c:269
size_t StrReplaceCharN(char *string, size_t len, char search, char replace)
Definition: string_util.c:397
size_t StrTrimmedLength(const char *string)
Definition: string_util.c:442
char * StrTrim(char *text)
Definition: string_util.c:300
size_t StrToUpper(char *text)
Definition: string_util.c:353