aboutsummaryrefslogtreecommitdiff
path: root/src/SString.h
blob: 1ff544558c3b5305b05abb30b4bc4a43e76846db (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
 /*@@
  @file      SString.h
  @date      02.04.2004
  @author    Steve White
  @desc      Module for generic operations on strings
  @enddesc
  @version $Header$
  @@*/
#ifndef _SSTRING_H
#define _SSTRING_H

#include <stddef.h>

typedef enum { FALSE, TRUE } SSBOOL;
typedef char SSCHAR;

typedef struct String_tag String;
				/* String creation and deletion */
String		*String_New();
String		*String_Copy( const String *other );
String		*String_Make( const SSCHAR *other );
void		String_Delete( String * );
				/* Copying */
String *	StringSet( String *dest, const String *source );
String *	StringSetSubString( String *dest, const String *source,
			size_t first, size_t last );
				/* Number of characters in string */
size_t		StringLength( const String * );
				/* Accessors */
SSCHAR		StringNthChar( const String *, size_t n );
String *	StringSetNthChar( String *, size_t n, SSCHAR c );
String *	StringTruncate( String *, size_t n );
				/* Conversion to and from C string */
String *	StringSetToCString( String *s, const SSCHAR *c_str );
String *	StringConcatCString( String *s, const SSCHAR *c_str );
String *	StringInsertCString( String * s, const char * c_str,
						size_t position );
String *	StringSetToBuffer( String *s, const SSCHAR *buf,
						size_t len );
const SSCHAR *	StringGetBuffer( const String * s );
				/* Searching */
SSBOOL		StringFindSubString( const String *s, const String *substr,
				size_t *position );
SSBOOL		StringFindChar( const String *s, SSCHAR theChar,
				size_t *position );
				/* Comparison */
SSBOOL		StringEquals( const String *a, const String *b );
int		StringCompare( const String *a, const String *b );
				/* Insertion and Concatenation */
String *	StringInsert( String * s, const String * other, size_t pos );
String *	StringInsertChar( String * s, SSCHAR c, size_t pos );
String *	StringDeleteChar( String * s, size_t pos );
String *	StringDeleteRange( String * s, size_t begin, size_t end );
String *	StringConcat( String * s, const String * other);
				/* Trim */
String *	StringTrimHead( const String *s, size_t pos );
String *	StringTrimTail( const String *s, size_t pos );
				/* Printing to stdout */
void		StringPrint( const String *str );
void		StringFormatPrint( const String *str, const SSCHAR *format );
				/* For line reading and writing */
void		String_SetLineEndCharacter( SSCHAR c );
				/* String conversions */
String *	StringConcatDecimal( String *str, long int d );
String *	StringConcatHex( String *str, long int d );
String *	StringConcatOctal( String *str, long int d );
String *	StringConcatDouble( String *str, double d );
String *	StringConcatFormattedDouble( String *str, int ndigits,
				int ndecimals, double d );

/* A poor man's namespace for the String module */
#ifdef STRING_NAMESPACE

#define Set( a, b ) \
		StringSet( a, b )
#define SetToCString( a, b ) \
		StringSetToCString( a, b )
#define InsertCString( a, b, c ) \
		StringInsertCString( a, b, c )
#define ConcatCString( a, b ) \
		StringConcatCString( a, b )
#define SetToBuffer( a, b ) \
		StringSetToBuffer( a, b )
#define GetBuffer( a ) \
		StringGetBuffer( a )
#define Length( p ) \
		StringLength( p )
#define	NthChar( s, n ) \
		StringNthChar( s, n )
#define SetNthChar( s, n, c ) \
		StringSetNthChar( s, n, c )
#define Truncate( s, n ) \
		StringTruncate( s, n )
#define	FindSubString( s, c, p ) \
		StringFindSubString( s, c, p )
#define	FindChar( s, c, p ) \
		StringFindChar( s, c, p )
#define Compare( a, b ) \
		StringCompare( a, b )
#define AreEqual( a, b ) \
		StringsAreEqual( a, b )
#define Insert( a, b, p ) \
		StringInsert( a, b, p )
#define InsertChar( a, b, p ) \
		StringInsertChar( a, b, p )
#define Concat( a, b ) \
		StringConcat( a, b )
#define Print( a ) \
		StringPrint( a )
#define FormatPrint( a, s ) \
		StringFormatPrint( a, s )
#define ConcatDecimal( a, s ) \
		StringConcatDecimal( a, s )
#define ConcatHex( a, s ) \
		StringConcatHex( a, s )
#define ConcatOctal( a, s ) \
		StringConcatOctal( a, s )
#define ConcatDouble( a, s ) \
		StringConcatDouble( a, s )
#define ConcatFormattedDouble( a, f, f2, s ) \
		StringConcatFormattedDouble( a, f, f2, s )

#endif

#endif