Put the data (print job contents) in LPD requests under the LPD protocol
[obnox/wireshark/wip.git] / epan / strutil.h
1 /* strutil.h
2  * String utility definitions
3  *
4  * $Id$
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifndef __STRUTIL_H__
26 #define __STRUTIL_H__
27
28 /* ... thus, config.h needs to be #included */
29
30 /** @file
31  * String handling and conversion utilities.
32  */
33
34 /** Given a pointer into a data buffer, and to the end of the buffer,
35  *  find the end of the (putative) line at that position in the data
36  *  buffer.
37  *
38  * @param data A pointer to the beginning of the data
39  * @param dataend A pointer to the end of the data
40  * @param eol A pointer that will receive the EOL location
41  * @return A pointer to the EOL character(s) in "*eol".
42  */
43 const guchar *find_line_end(const guchar *data, const guchar *dataend,
44     const guchar **eol);
45
46 /** Get the length of the next token in a line, and the beginning of the
47  *  next token after that (if any).
48  * @param linep A pointer to the beginning of the line
49  * @param lineend A pointer to the end of the line
50  * @param next_token Receives the location of the next token
51  * @return 0 if there is no next token.
52  */
53 int        get_token_len(const guchar *linep, const guchar *lineend,
54     const guchar **next_token);
55
56 /** Given a string, generate a string from it that shows non-printable
57  *  characters as C-style escapes, and return a pointer to it.
58  *
59  * @param line A pointer to the input string
60  * @param len The length of the input string
61  * @return A pointer to the formatted string
62  *
63  * @see tvb_format_text()
64  */
65 gchar*     format_text(const guchar *line, int len);
66
67 /** Turn an array of bytes into a string showing the bytes in hex.
68  *
69  * @param bd A pointer to the byte array
70  * @param bd_len The length of the byte array
71  * @return A pointer to the formatted string
72  *
73  * @see bytes_to_str_punct()
74  */
75 gchar*     bytes_to_str(const guint8 *bd, int bd_len);
76
77 /** Turn an array of bytes into a string showing the bytes in hex,
78  *  separated by a punctuation character.
79  *
80  * @param bd A pointer to the byte array
81  * @param bd_len The length of the byte array
82  * @param punct The punctuation character
83  * @return A pointer to the formatted string
84  *
85  * @see bytes_to_str()
86  */
87 gchar*     bytes_to_str_punct(const guint8 *bd, int bd_len, gchar punct);
88
89 /** Turn a string of hex digits with optional separators (defined by
90  *  is_byte_sep() into a byte array.
91  *
92  * @param hex_str The string of hex digits.
93  * @param bytes The GByteArray that will receive the bytes.  This
94  *        must be initialized by the caller.
95  * @param force_separators If set to TRUE, separators MUST exist between 
96  *        bytes.
97  * @return True if the string was converted successfully
98  */
99 gboolean   hex_str_to_bytes(const char *hex_str, GByteArray *bytes,
100     gboolean force_separators);
101
102 /** Return a XML escaped representation of the unescaped string.
103  *  The returned string must be freed when no longer in use. 
104  *
105  * @param unescaped The unescaped string
106  * @return An XML-escaped representation of the input string
107  */
108 gchar*     xml_escape(const gchar *unescaped);
109
110 /* Return the first occurrence of needle in haystack.
111  * Algorithm copied from GNU's glibc 2.3.2 memcmp()
112  *
113  * @param haystack The data to search
114  * @param haystack_len The length of the search data
115  * @param needle The string to look for
116  * @param needle_len The length of the search string
117  * @return A pointer to the first occurrence of "needle" in
118  *         "haystack".  If "needle" isn't found or is NULL, or if
119  *         "needle_len" is 0, NULL is returned.
120  */
121 const guint8 * epan_memmem(const guint8 *haystack, guint haystack_len,
122                 const guint8 *needle, guint needle_len);
123
124 /* Surround a string or a macro, resolved to a string, with double quotes */
125 #define _STRINGIFY(a)           # a
126 #define STRINGIFY(a)            _STRINGIFY(a)
127
128 /** Scan a string to make sure it's valid hex.
129  *
130  * @param string The string to validate
131  * @param nbytes The length of the return buffer
132  * @return A pointer to a buffer containing the converted raw bytes.  This
133  *         buffer must be g_free()d by the caller.
134  */
135 guint8 * convert_string_to_hex(const char *string, size_t *nbytes);
136
137 /** Prep a string for case-sensitive vs case-insensitive searching.
138  *
139  * @param string The search string
140  * @param case_insensitive TRUE if case-insensitive, FALSE if not
141  * @return A direct copy of the string if it's a case-sensitive search and
142  * an uppercased version if not.  In either case the string must be g_free()d
143  * by the caller.
144  */
145 char * convert_string_case(const char *string, gboolean case_insensitive);
146
147 #endif /* __STRUTIL_H__ */