OpenDNSSEC-enforcer
1.3.4
|
00001 /* 00002 * $Id: string_util.h 875 2009-06-02 15:28:33Z sion $ 00003 * 00004 * Copyright (c) 2008-2009 Nominet UK. All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 1. Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 2. Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * 00015 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00016 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00017 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00018 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 00019 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00020 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00021 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00022 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00023 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 00024 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 00025 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 * 00027 */ 00028 00029 #ifndef KSM_STRING_UTIL_H 00030 #define KSM_STRING_UTIL_H 00031 00032 /*+ 00033 * Filename: string_util.h 00034 * 00035 * Description: 00036 * Definitions of the string utilities used by all the whois programs. 00037 -*/ 00038 00039 #include <ksm/system_includes.h> 00040 #include <ksm/memory.h> 00041 00042 #ifdef __cplusplus 00043 extern "C" { 00044 #endif 00045 00046 #define COMMENT_CHAR ("#") 00047 00048 void StrUncomment(char* line); 00049 void StrWhitespace(char* line); 00050 char* StrStrdup(const char* string); 00051 void StrStrncpy(char* dest, const char* src, size_t destlen); 00052 void StrStrncat(char* dest, const char* src, size_t destlen); 00053 void StrTrimR(char* text); 00054 char* StrTrimL(char* text); 00055 char* StrTrim(char* text); 00056 size_t StrToLower(char* text); 00057 size_t StrToUpper(char* text); 00058 size_t StrReplaceCharN(char* string, size_t len, char search, char replace); 00059 size_t StrReplaceChar(char* string, char search, char replace); 00060 size_t StrTrimmedLength(const char* string); 00061 00062 /* 00063 * The next definition allows for possible alternative memory strategies to 00064 * be used for string routines. At any rate, StrFree() should be used to free 00065 * a string allocated by StrStrdup(). 00066 */ 00067 00068 #define StrFree(x) MemFree(x) 00069 00070 /* 00071 * A simple macro (the idea comes from the memcached code) that allows the 00072 * compile-time determination of the length of a literal string. Note that 00073 * the string must be declared by: 00074 * 00075 * char string[] = "this is a literal string" 00076 * 00077 * rather than 00078 * 00079 * char* string = "this is a literal string" 00080 * 00081 * Use of the macro on the former gives the correct string length. On the 00082 * latter it gives "sizeof(char*) - 1". 00083 */ 00084 00085 #define STR_LENGTH(x) (sizeof(x) - 1) 00086 00087 #ifdef __cplusplus 00088 } 00089 #endif 00090 00091 #endif /* KSM_STRING_UTIL_H */