FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
string_operations.h
1 /*
2 Author: Daniele Fognini, Andreas Wuerl
3 Copyright (C) 2013-2015, Siemens AG
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 #ifndef MONK_AGENT_STRING_OPERATIONS_H
20 #define MONK_AGENT_STRING_OPERATIONS_H
21 
22 #include <glib.h>
23 #include <string.h>
24 #include <stdint.h>
25 
26 typedef struct {
27  unsigned int length;
28  unsigned int removedBefore;
29  uint32_t hashedContent;
30 } Token;
31 
32 #define token_length(token) (token).length
33 
34 #define tokens_new() g_array_new(FALSE, FALSE, sizeof (Token))
35 #define tokens_free(p) g_array_free((p), TRUE)
36 
37 #define tokens_index(tokens,i) &g_array_index((tokens), Token, (i))
38 
39 GArray* tokenize(const char* inputString, const char* delimiters);
40 
41 int streamTokenize(const char* inputChunk, size_t inputSize, const char* delimiters,
42  GArray** output, Token** remainder);
43 
44 #define tokenEquals(a, b) (((a)->length == (b)->length ) && ((a)->hashedContent == (b)->hashedContent))
45 
46 int tokensEquals(const GArray* a, const GArray* b);
47 
48 size_t token_position_of(size_t index, const GArray* tokens);
49 
50 #endif // MONK_AGENT_STRING_OPERATIONS_H