NCBI C++ ToolKit
string.h
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Brian Bruns
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 
20 #ifndef _tdsstring_h_
21 #define _tdsstring_h_
22 
23 #include <freetds/pushvis.h>
24 
25 /** \addtogroup dstring
26  * @{
27  */
28 
29 /** Internal representation for an empty string */
30 extern const struct tds_dstr tds_str_empty;
31 
32 /** Initializer, used to initialize string like in the following example
33  * @code
34  * DSTR s = DSTR_INITIALIZER;
35  * @endcode
36  */
37 #define DSTR_INITIALIZER ((struct tds_dstr*) &tds_str_empty)
38 
39 /** init a string with empty */
40 static inline void
42 {
43  *(s) = DSTR_INITIALIZER;
44 }
45 
46 /** test if string is empty */
47 static inline int
49 {
50  return (*s)->dstr_size == 0;
51 }
52 
53 /**
54  * Returns a buffer to edit the string.
55  * Be careful to avoid buffer overflows and remember to
56  * set the correct length at the end of the editing if changed.
57  */
58 static inline char *
60 {
61  return (*s)->dstr_s;
62 }
63 
64 /** Returns a C version (NUL terminated string) of dstr */
65 static inline const char *
67 {
68  return (*s)->dstr_s;
69 }
70 
71 /** Returns the length of the string in bytes */
72 static inline size_t
74 {
75  return (*s)->dstr_size;
76 }
77 
78 /** Make a string empty */
79 #define tds_dstr_empty(s) \
80  tds_dstr_free(s)
81 
82 void tds_dstr_zero(DSTR * s);
83 void tds_dstr_free(DSTR * s);
84 
85 DSTR* tds_dstr_dup(DSTR * s, const DSTR * src) TDS_WUR;
86 DSTR* tds_dstr_copy(DSTR * s, const char *src) TDS_WUR;
87 DSTR* tds_dstr_copyn(DSTR * s, const char *src, size_t length) TDS_WUR;
88 DSTR* tds_dstr_set(DSTR * s, char *src) TDS_WUR;
89 
90 DSTR* tds_dstr_setlen(DSTR *s, size_t length);
91 DSTR* tds_dstr_alloc(DSTR *s, size_t length) TDS_WUR;
92 
93 /** @} */
94 
95 #include <freetds/popvis.h>
96 
97 #endif /* _tdsstring_h_ */
DSTR * tds_dstr_setlen(DSTR *s, size_t length)
limit length of string, MUST be <= current length
Definition: tdsstring.c:146
static const char * tds_dstr_cstr(DSTR *s)
Returns a C version (NUL terminated string) of dstr.
Definition: string.h:66
void tds_dstr_zero(DSTR *s)
clear all string filling with zeroes (mainly for security reason)
Definition: tdsstring.c:56
DSTR * tds_dstr_dup(DSTR *s, const DSTR *src) TDS_WUR
Duplicate a string from another dynamic string.
Definition: tdsstring.c:135
#define DSTR_INITIALIZER
Initializer, used to initialize string like in the following example.
Definition: string.h:37
DSTR * tds_dstr_copyn(DSTR *s, const char *src, size_t length) TDS_WUR
Set string to a given buffer of characters.
Definition: tdsstring.c:78
const struct tds_dstr tds_str_empty
Internal representation for an empty string.
Definition: tdsstring.c:46
DSTR * tds_dstr_alloc(DSTR *s, size_t length) TDS_WUR
allocate space for length char
Definition: tdsstring.c:166
static void tds_dstr_init(DSTR *s)
init a string with empty
Definition: string.h:41
static char * tds_dstr_buf(DSTR *s)
Returns a buffer to edit the string.
Definition: string.h:59
DSTR * tds_dstr_set(DSTR *s, char *src) TDS_WUR
set a string from another buffer.
Definition: tdsstring.c:108
void tds_dstr_free(DSTR *s)
free string
Definition: tdsstring.c:63
DSTR * tds_dstr_copy(DSTR *s, const char *src) TDS_WUR
copy a string from another
Definition: tdsstring.c:123
static int tds_dstr_isempty(DSTR *s)
test if string is empty
Definition: string.h:48
static size_t tds_dstr_len(DSTR *s)
Returns the length of the string in bytes.
Definition: string.h:73
Structure to hold a string.
Definition: tds.h:116
#define TDS_WUR
Definition: tds.h:398
Modified on Fri Dec 08 08:21:03 2023 by modify_doxy.py rev. 669887