str_util.c:format_size() uses 0xff00 for the mask, so left-shift format_size_prefix_...
[metze/wireshark/wip.git] / wsutil / str_util.h
1 /* str_util.h
2  * String utility definitions
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #ifndef __STR_UTIL_H__
26 #define __STR_UTIL_H__
27
28 /** Convert all upper-case ASCII letters to their ASCII lower-case
29  *  equivalents, in place, with a simple non-locale-dependent
30  *  ASCII mapping (A-Z -> a-z).
31  *  All other characters are left unchanged, as the mapping to
32  *  lower case may be locale-dependent.
33  *
34  *  The string is assumed to be in a character encoding, such as
35  *  an ISO 8859 or other EUC encoding, or UTF-8, in which all
36  *  bytes in the range 0x00 through 0x7F are ASCII characters and
37  *  non-ASCII characters are constructed from one or more bytes in
38  *  the range 0x80 through 0xFF.
39  *
40  * @param str The string to be lower-cased.
41  * @return    ptr to the string
42  */
43 gchar *ascii_strdown_inplace(gchar *str);
44
45 /** Convert all lower-case ASCII letters to their ASCII upper-case
46  *  equivalents, in place, with a simple non-locale-dependent
47  *  ASCII mapping (a-z -> A-Z).
48  *  All other characters are left unchanged, as the mapping to
49  *  lower case may be locale-dependent.
50  *
51  *  The string is assumed to be in a character encoding, such as
52  *  an ISO 8859 or other EUC encoding, or UTF-8, in which all
53  *  bytes in the range 0x00 through 0x7F are ASCII characters and
54  *  non-ASCII characters are constructed from one or more bytes in
55  *  the range 0x80 through 0xFF.
56  *
57  * @param str The string to be upper-cased.
58  * @return    ptr to the string
59  */
60 gchar *ascii_strup_inplace(gchar *str);
61
62 /** Check if an entire string consists of printable characters
63  *
64  * @param str The string to be checked
65  * @return    TRUE if the entire string is printable, otherwise FALSE
66  */
67 gboolean isprint_string(guchar *string);
68
69 /** Check if an entire string consists of digits
70  *
71  * @param str The string to be checked
72  * @return    TRUE if the entire string is digits, otherwise FALSE
73  */
74 gboolean isdigit_string(guchar *string);
75
76 typedef enum {
77     format_size_unit_none    = 0,       /**< No unit will be appended. You must supply your own. */
78     format_size_unit_bytes   = 1,       /**< "bytes" for un-prefixed sizes, "B" otherwise. */
79     /* XXX Do we use bytes/s anywhere? */
80     format_size_unit_bits    = 2,       /**< "bits" for un-prefixed sizes, "b" otherwise. */
81     format_size_unit_bits_s  = 3,       /**< "bits/s" for un-prefixed sizes, "bps" otherwise. */
82     format_size_prefix_si    = 0 << 8,  /**< SI (power of 1000) prefixes will be used. */
83     format_size_prefix_iec   = 1 << 8   /**< IEC (power of 1024) prefixes will be used. */
84     /* XXX format_size_prefix_default_for_this_particular_os ? */
85 } format_size_flags_e;
86
87 /** Given a size, return its value in a human-readable format
88  *
89  * Prefixes up to "T/Ti" (tera, tebi) are currently supported.
90  *
91  * @param size The size value
92  * @param flags Flags to control the output (unit of measurement,
93  * SI vs IEC, etc). Unit and prefix flags may be ORed together.
94  * @return A newly-allocated string representing the value.
95  */
96 gchar *format_size(gint64 size, format_size_flags_e flags);
97
98 #endif /* __STR_UTIL_H__ */