D-Bus 1.14.10
dbus-string-util.c
1/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2/* dbus-string-util.c Would be in dbus-string.c, but not used in libdbus
3 *
4 * Copyright 2002-2008 Red Hat, Inc.
5 * Copyright 2003 CodeFactory AB
6 * Copyright 2003 Mark McLoughlin
7 * Copyright 2004 Michael Meeks
8 * Copyright 2006-2015 Ralf Habacker <ralf.habacker@freenet.de>
9 * Copyright 2007 Allison Lortie
10 * Copyright 2011 Roberto Guido
11 * Copyright 2016-2018 Collabora Ltd.
12 *
13 * Licensed under the Academic Free License version 2.1
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 *
29 */
30
31#include <config.h>
32#include "dbus-internals.h"
33#include "dbus-string.h"
34#define DBUS_CAN_USE_DBUS_STRING_PRIVATE 1
35#include "dbus-string-private.h"
36
53 const char *c_str)
54{
55 const unsigned char *ap;
56 const unsigned char *bp;
57 const unsigned char *a_end;
58 unsigned long c_str_len;
59 const DBusRealString *real_a = (const DBusRealString*) a;
61 _dbus_assert (c_str != NULL);
62
63 c_str_len = strlen (c_str);
64 if (((unsigned long)real_a->len) < c_str_len)
65 return FALSE;
66
67 ap = real_a->str + (real_a->len - c_str_len);
68 bp = (const unsigned char*) c_str;
69 a_end = real_a->str + real_a->len;
70 while (ap != a_end)
71 {
72 if (*ap != *bp)
73 return FALSE;
74
75 ++ap;
76 ++bp;
77 }
78
79 _dbus_assert (*ap == '\0');
80 _dbus_assert (*bp == '\0');
81
82 return TRUE;
83}
84
97 int start,
98 unsigned char byte,
99 int *found)
100{
101 int i;
103 _dbus_assert (start <= real->len);
104 _dbus_assert (start >= 0);
105 _dbus_assert (found != NULL);
106
107 i = start - 1;
108 while (i >= 0)
109 {
110 if (real->str[i] == byte)
111 break;
112
113 --i;
114 }
115
116 if (found)
117 *found = i;
118
119 return i >= 0;
120}
121
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
#define NULL
A null pointer, defined appropriately for C or C++.
#define TRUE
Expands to "1".
#define FALSE
Expands to "0".
#define DBUS_CONST_STRING_PREAMBLE(str)
Checks assertions about a string that may be const or locked.
#define DBUS_GENERIC_STRING_PREAMBLE(real)
Checks a bunch of assertions about a string object.
dbus_bool_t _dbus_string_ends_with_c_str(const DBusString *a, const char *c_str)
Returns whether a string ends with the given suffix.
dbus_bool_t _dbus_string_find_byte_backward(const DBusString *str, int start, unsigned char byte, int *found)
Find the given byte scanning backward from the given start.
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition: dbus-types.h:35
Internals of DBusString.
unsigned char * str
String data, plus nul termination.
int len
Length without nul.