summaryrefslogtreecommitdiff
path: root/zwgc/new_string.h
blob: ea1010559706a0168c37b4007973e3733f96e959 (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
126
127
128
129
130
131
132
133
134
/* This file is part of the Project Athena Zephyr Notification System.
 * It is one of the source files comprising zwgc, the Zephyr WindowGram
 * client.
 *
 *      Created by:     Marc Horowitz <marc@athena.mit.edu>
 *
 *      $Id$
 *
 *      Copyright (c) 1989 by the Massachusetts Institute of Technology.
 *      For copying and distribution information, see the file
 *      "mit-copyright.h".
 */

#ifndef string_TYPE
#define string_TYPE

#include <string.h>
#include "new_memory.h"

typedef char *string;

/*
 *    int string_Length(string s):
 *        Effects: Returns the number of non-null characters in s.
 */

#define string_Length(s) strlen(s)

/*
 *    int string_Eq(string a, b):
 *        Effects: Returns true iff strings a & b are equal.  I.e., have the
 *                 same character contents.
 */

#define string_Eq(a,b) (!strcmp(a,b))

/*
 *    int string_Neq(string a, b):
 *        Effects: Returns true iff strings a & b are not equal.
 */

#define string_Neq(a,b) (strcmp(a,b))

/*
 *    string string_CreateFromData(char *data, int length):
 *        Requires: data[0], data[1], ..., data[length-1] != 0
 *        Effects: Takes the first length characters at data and
 *                 creates a string containing them.  The returned string
 *                 is on the heap & must be freed eventually.
 *                 I.e., if passed "foobar" and 3, it would return
 *                 string_Copy("foo").
 */

extern string string__CreateFromData(char *, int);
#ifdef DEBUG_MEMORY
#define string_CreateFromData(data,length) (set_module(__FILE__,__LINE__),\
				    string__CreateFromData(data,length))
#else
#define string_CreateFromData(data,length)  string__CreateFromData(data,length)
#endif

/*
 *    string string_Copy(string s):
 *        Effects: Returns a copy of s on the heap.  The copy must be
 *                 freed eventually.
 */

extern string string__Copy(string);
#ifdef DEBUG_MEMORY
#define string_Copy(data)  (set_module(__FILE__,__LINE__),\
			    string__Copy(data))
#else
#define string_Copy(data)  string__Copy(data)
#endif

/*
 *    string string_Concat(string a, b):
 *        Effects: Returns a string equal to a concatenated to b.
 *                 The returned string is on the heap and must be
 *                 freed eventually.  I.e., given "abc" and "def",
 *                 returns string_Copy("abcdef").
 */

extern string string__Concat(string, string);
#ifdef DEBUG_MEMORY
#define string_Concat(a,b)  (set_module(__FILE__,__LINE__),\
			     string__Concat(a,b))
#else
#define string_Concat(a,b)  string__Concat(a,b)
#endif
    
/*
 *    string string_Concat2(string a, b):
 *        Modifies: a
 *        Requires: a is on the heap, b does not point into a.
 *        Effects: Equivalent to:
 *                     string temp;
 *                     temp = string_Concat(a,b);
 *                     free(a);
 *                     return(temp);
 *                 only faster.  I.e., uses realloc instead of malloc+bcopy.
 */

extern string string__Concat2(string, string);
#ifdef DEBUG_MEMORY
#define string_Concat2(a,b)  (set_module(__FILE__,__LINE__),\
			      string__Concat2(a,b))
#else
#define string_Concat2(a,b)  string__Concat2(a,b)
#endif

/*
 *    string string_Downcase(string s):
 *        Modifies: s
 *        Effects: Modifies s by changing every uppercase character in s
 *                 to the corresponding lowercase character.  Nothing else
 *                 is changed.  I.e., "FoObAr19." is changed to "foobar19.".
 *                 S is returned as a convenience.
 */

extern string string_Downcase(string);

/*
 *    string string_Upcase(string s):
 *        Modifies: s
 *        Effects: Modifies s by changing every lowercase character in s
 *                 to the corresponding uppercase character.  Nothing else
 *                 is changed.  I.e., "FoObAr19." is changed to "FOOBAR19.".
 *                 S is returned as a convenience.
 */

extern string string_Upcase(string);

#endif