nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /* str_util.h
2 * String utility definitions
3 *
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22  
23 #ifndef __STR_UTIL_H__
24 #define __STR_UTIL_H__
25  
26 #include <glib.h>
27 #include "ws_symbol_export.h"
28  
29 #ifdef __cplusplus
30 extern "C" {
31 #endif /* __cplusplus */
32  
33 /** Convert all upper-case ASCII letters to their ASCII lower-case
34 * equivalents, in place, with a simple non-locale-dependent
35 * ASCII mapping (A-Z -> a-z).
36 * All other characters are left unchanged, as the mapping to
37 * lower case may be locale-dependent.
38 *
39 * The string is assumed to be in a character encoding, such as
40 * an ISO 8859 or other EUC encoding, or UTF-8, in which all
41 * bytes in the range 0x00 through 0x7F are ASCII characters and
42 * non-ASCII characters are constructed from one or more bytes in
43 * the range 0x80 through 0xFF.
44 *
45 * @param str The string to be lower-cased.
46 * @return ptr to the string
47 */
48 WS_DLL_PUBLIC
49 gchar *ascii_strdown_inplace(gchar *str);
50  
51 /** Convert all lower-case ASCII letters to their ASCII upper-case
52 * equivalents, in place, with a simple non-locale-dependent
53 * ASCII mapping (a-z -> A-Z).
54 * All other characters are left unchanged, as the mapping to
55 * lower case may be locale-dependent.
56 *
57 * The string is assumed to be in a character encoding, such as
58 * an ISO 8859 or other EUC encoding, or UTF-8, in which all
59 * bytes in the range 0x00 through 0x7F are ASCII characters and
60 * non-ASCII characters are constructed from one or more bytes in
61 * the range 0x80 through 0xFF.
62 *
63 * @param str The string to be upper-cased.
64 * @return ptr to the string
65 */
66 WS_DLL_PUBLIC
67 gchar *ascii_strup_inplace(gchar *str);
68  
69 /** Check if an entire string consists of printable characters
70 *
71 * @param string The string to be checked
72 * @return TRUE if the entire string is printable, otherwise FALSE
73 */
74 WS_DLL_PUBLIC
75 gboolean isprint_string(const gchar *string);
76  
77 /** Check if an entire string consists of digits
78 *
79 * @param string The string to be checked
80 * @return TRUE if the entire string is digits, otherwise FALSE
81 */
82 WS_DLL_PUBLIC
83 gboolean isdigit_string(guchar *string);
84  
85 WS_DLL_PUBLIC
86 int ws_xton(char ch);
87  
88 typedef enum {
89 format_size_unit_none = 0, /**< No unit will be appended. You must supply your own. */
90 format_size_unit_bytes = 1, /**< "bytes" for un-prefixed sizes, "B" otherwise. */
91 format_size_unit_bits = 2, /**< "bits" for un-prefixed sizes, "b" otherwise. */
92 format_size_unit_bits_s = 3, /**< "bits/s" for un-prefixed sizes, "bps" otherwise. */
93 format_size_unit_bytes_s = 4, /**< "bytes/s" for un-prefixed sizes, "Bps" otherwise. */
94 format_size_unit_packets = 5, /**< "packets" */
95 format_size_unit_packets_s = 6, /**< "packets/s" */
96 format_size_prefix_si = 0 << 8, /**< SI (power of 1000) prefixes will be used. */
97 format_size_prefix_iec = 1 << 8 /**< IEC (power of 1024) prefixes will be used. */
98 /* XXX format_size_prefix_default_for_this_particular_os ? */
99 } format_size_flags_e;
100  
101 /** Given a size, return its value in a human-readable format
102 *
103 * Prefixes up to "T/Ti" (tera, tebi) are currently supported.
104 *
105 * @param size The size value
106 * @param flags Flags to control the output (unit of measurement,
107 * SI vs IEC, etc). Unit and prefix flags may be ORed together.
108 * @return A newly-allocated string representing the value.
109 */
110 WS_DLL_PUBLIC
111 gchar *format_size(gint64 size, format_size_flags_e flags);
112  
113 WS_DLL_PUBLIC
114 gchar printable_char_or_period(gchar c);
115  
116 /* To pass one of two strings, singular or plural */
117 #define plurality(d,s,p) ((d) == 1 ? (s) : (p))
118  
119 #ifdef __cplusplus
120 }
121  
122 /* Should we just have separate unit and prefix enums instead? */
123 extern format_size_flags_e operator|(format_size_flags_e lhs, format_size_flags_e rhs);
124 #endif /* __cplusplus */
125  
126 #endif /* __STR_UTIL_H__ */