summaryrefslogtreecommitdiffstats
path: root/parse.h
blob: 6bbc4afda05a9f60dd852b17411dd1912798e8d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* parsing routines for the counted string class. These
 * routines provide generic parsing aid as well some fairly
 * complex routines targeted toward specific needs.
 *
 * General information - read this:
 * All routines work on a single CStr object, which must be supplied
 * during construction. The parse class keeps an internal pointer of
 * where the next parse operation is to start (you could also say
 * this is where the last parse operation stopped).
 *
 * Each parse operation carried out by this package starts from the
 * parse pointer, parses the caller-requested element (e.g. an
 * integer or delemited string) and the update the parse pointer. If
 * the caller tries to parse beyond the end of the original string,
 * an error is returned. In general, all functions return a parsRet
 * error code and all require the parseObj to be the first parameter.
 * The to-be-parsed string provided to the parse object MUST NOT be
 * freed or modified by the caller during the lifetime of the parse
 * object. However, the caller must free it when it is no longer needed.
 * Optinally, the parse object can be instructed to do that. All objects
 * returned by the parse routines must be freed by the caller. For
 * simpler data types (like integers), the caller must provide the
 * necessary buffer space.
 *
 * begun 2005-09-09 rgerhards
 */
#ifndef _PARSE_H_INCLUDED__
#define _PARSE_H_INCLUDED__ 1

#include "stringbuf.h"

/** 
 * The parse object
 */
struct rsParsObject
{	
#ifndef NDEBUG
	rsObjID OID;			/**< object ID */
#endif
	rsCStrObj *pCStr;		/**< pointer to the string object we are parsing */
	int iCurrPos;			/**< current parsing position (char offset) */
};
typedef struct rsParsObject rsParsObj;


/* BEGIN "inline"-like functions */
/* END "inline"-like functions */

int rsParsGetParsePointer(rsParsObj *pThis);

/**
 * Construct a rsPars object.
 */
rsRetVal rsParsConstruct(rsParsObj **ppThis);
rsRetVal rsParsAssignString(rsParsObj *pThis, rsCStrObj *pCStr);

/* parse an integer. The parse pointer is advanced */
rsRetVal parsInt(rsParsObj *pThis, int* pInt);

/* Skip whitespace. Often used to trim parsable entries. */
rsRetVal parsSkipWhitespace(rsParsObj *pThis);

/* Parse string up to a delimiter.
 *
 * Input:
 * cDelim - the delimiter
 *   The following two are for whitespace stripping,
 *   0 means "no", 1 "yes"
 *   - bTrimLeading
 *   - bTrimTrailing
 * 
 * Output:
 * ppCStr Pointer to the parsed string
 */
rsRetVal parsDelimCStr(rsParsObj *pThis, rsCStrObj **ppCStr, char cDelim, int bTrimLeading, int bTrimTrailing);

rsRetVal parsSkipAfterChar(rsParsObj *pThis, char c);
rsRetVal parsQuotedCStr(rsParsObj *pThis, rsCStrObj **ppCStr);
#if 0 /* later! */
/* Parse a property
 * This is a complex parsing routine. It parses an property
 * entry suitable for use in the property replacer. It is currently
 * just an idea if this should be a parser function.
 */
parsRet parsProp(parseObj *pThis, ?? **pPropEtry);
#endif

#endif
/*
 * Local variables:
 *  c-indent-level: 8
 *  c-basic-offset: 8
 *  tab-width: 8
 * End:
 * vi:set ai:
 */