1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-string-private.h String utility class (internal to D-Bus implementation)
4 * Copyright (C) 2002, 2003 Red Hat, Inc.
6 * Licensed under the Academic Free License version 2.1
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
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.
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
24 #ifndef DBUS_STRING_PRIVATE_H
25 #define DBUS_STRING_PRIVATE_H
27 #include <dbus/dbus-memory.h>
28 #include <dbus/dbus-types.h>
30 #ifndef DBUS_CAN_USE_DBUS_STRING_PRIVATE
31 #error "Don't go including dbus-string-private.h for no good reason"
37 * @brief Internals of DBusString.
39 * DBusString internals. DBusString is an opaque objects, it must be
40 * used via accessor functions.
44 unsigned char *str; /**< String data, plus nul termination */
45 int len; /**< Length without nul */
46 int allocated; /**< Allocated size of data */
47 unsigned int constant : 1; /**< String data is not owned by DBusString */
48 unsigned int locked : 1; /**< DBusString has been locked and can't be changed */
49 unsigned int invalid : 1; /**< DBusString is invalid (e.g. already freed) */
50 unsigned int align_offset : 3; /**< str - align_offset is the actual malloc block */
55 * @defgroup DBusStringInternals DBusString implementation details
56 * @ingroup DBusInternals
57 * @brief DBusString implementation details
59 * The guts of DBusString.
65 * The maximum length of a DBusString
67 #define _DBUS_STRING_MAX_LENGTH (_DBUS_INT32_MAX - _DBUS_STRING_ALLOCATION_PADDING)
70 * Checks a bunch of assertions about a string object
72 * @param real the DBusRealString
74 #define DBUS_GENERIC_STRING_PREAMBLE(real) \
76 _dbus_assert ((real) != NULL); \
77 _dbus_assert (!(real)->invalid); \
78 _dbus_assert ((real)->len >= 0); \
79 _dbus_assert ((real)->allocated >= 0); \
80 _dbus_assert ((real)->len <= ((real)->allocated - _DBUS_STRING_ALLOCATION_PADDING)); \
81 _dbus_assert ((real)->len <= _DBUS_STRING_MAX_LENGTH); \
85 * Checks assertions about a string object that needs to be
86 * modifiable - may not be locked or const. Also declares
87 * the "real" variable pointing to DBusRealString.
88 * @param str the string
90 #define DBUS_STRING_PREAMBLE(str) DBusRealString *real = (DBusRealString*) str; \
91 DBUS_GENERIC_STRING_PREAMBLE (real); \
92 _dbus_assert (!(real)->constant); \
93 _dbus_assert (!(real)->locked)
96 * Checks assertions about a string object that may be locked but
97 * can't be const. i.e. a string object that we can free. Also
98 * declares the "real" variable pointing to DBusRealString.
100 * @param str the string
102 #define DBUS_LOCKED_STRING_PREAMBLE(str) DBusRealString *real = (DBusRealString*) str; \
103 DBUS_GENERIC_STRING_PREAMBLE (real); \
104 _dbus_assert (!(real)->constant)
107 * Checks assertions about a string that may be const or locked. Also
108 * declares the "real" variable pointing to DBusRealString.
109 * @param str the string.
111 #define DBUS_CONST_STRING_PREAMBLE(str) const DBusRealString *real = (DBusRealString*) str; \
112 DBUS_GENERIC_STRING_PREAMBLE (real)
115 * Checks for ASCII blank byte
118 #define DBUS_IS_ASCII_BLANK(c) ((c) == ' ' || (c) == '\t')
121 * Checks for ASCII whitespace byte
124 #define DBUS_IS_ASCII_WHITE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r')
130 #endif /* DBUS_STRING_PRIVATE_H */