]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/zwgc/new_string.h
2ad7851e4d20b6b009f210727c575f39de7afcf9
[1ts-debian.git] / zephyr / zwgc / new_string.h
1 /* This file is part of the Project Athena Zephyr Notification System.
2  * It is one of the source files comprising zwgc, the Zephyr WindowGram
3  * client.
4  *
5  *      Created by:     Marc Horowitz <marc@athena.mit.edu>
6  *
7  *      $Id$
8  *
9  *      Copyright (c) 1989 by the Massachusetts Institute of Technology.
10  *      For copying and distribution information, see the file
11  *      "mit-copyright.h".
12  */
13
14 #ifndef string_TYPE
15 #define string_TYPE
16
17 #include <string.h>
18 #include "new_memory.h"
19
20 typedef char *string;
21
22 /*
23  *    int string_Length(string s):
24  *        Effects: Returns the number of non-null characters in s.
25  */
26
27 #define string_Length(s) strlen(s)
28
29 /*
30  *    int string_Eq(string a, b):
31  *        Effects: Returns true iff strings a & b are equal.  I.e., have the
32  *                 same character contents.
33  */
34
35 #define string_Eq(a,b) (!strcmp(a,b))
36
37 /*
38  *    int string_Neq(string a, b):
39  *        Effects: Returns true iff strings a & b are not equal.
40  */
41
42 #define string_Neq(a,b) (strcmp(a,b))
43
44 /*
45  *    string string_CreateFromData(char *data, int length):
46  *        Requires: data[0], data[1], ..., data[length-1] != 0
47  *        Effects: Takes the first length characters at data and
48  *                 creates a string containing them.  The returned string
49  *                 is on the heap & must be freed eventually.
50  *                 I.e., if passed "foobar" and 3, it would return
51  *                 string_Copy("foo").
52  */
53
54 extern string string__CreateFromData();
55 #ifdef DEBUG_MEMORY
56 #define string_CreateFromData(data,length) (set_module(__FILE__,__LINE__),\
57                                     string__CreateFromData(data,length))
58 #else
59 #define string_CreateFromData(data,length)  string__CreateFromData(data,length)
60 #endif
61
62 /*
63  *    string string_Copy(string s):
64  *        Effects: Returns a copy of s on the heap.  The copy must be
65  *                 freed eventually.
66  */
67
68 extern string string__Copy(/* string s */);
69 #ifdef DEBUG_MEMORY
70 #define string_Copy(data)  (set_module(__FILE__,__LINE__),\
71                             string__Copy(data))
72 #else
73 #define string_Copy(data)  string__Copy(data)
74 #endif
75
76 /*
77  *    string string_Concat(string a, b):
78  *        Effects: Returns a string equal to a concatenated to b.
79  *                 The returned string is on the heap and must be
80  *                 freed eventually.  I.e., given "abc" and "def",
81  *                 returns string_Copy("abcdef").
82  */
83
84 extern string string__Concat(/* string a, b */);
85 #ifdef DEBUG_MEMORY
86 #define string_Concat(a,b)  (set_module(__FILE__,__LINE__),\
87                              string__Concat(a,b))
88 #else
89 #define string_Concat(a,b)  string__Concat(a,b)
90 #endif
91     
92 /*
93  *    string string_Concat2(string a, b):
94  *        Modifies: a
95  *        Requires: a is on the heap, b does not point into a.
96  *        Effects: Equivalent to:
97  *                     string temp;
98  *                     temp = string_Concat(a,b);
99  *                     free(a);
100  *                     return(temp);
101  *                 only faster.  I.e., uses realloc instead of malloc+bcopy.
102  */
103
104 extern string string__Concat2(/* string a, b */);
105 #ifdef DEBUG_MEMORY
106 #define string_Concat2(a,b)  (set_module(__FILE__,__LINE__),\
107                               string__Concat2(a,b))
108 #else
109 #define string_Concat2(a,b)  string__Concat2(a,b)
110 #endif
111
112 /*
113  *    string string_Downcase(string s):
114  *        Modifies: s
115  *        Effects: Modifies s by changing every uppercase character in s
116  *                 to the corresponding lowercase character.  Nothing else
117  *                 is changed.  I.e., "FoObAr19." is changed to "foobar19.".
118  *                 S is returned as a convenience.
119  */
120
121 extern string string_Downcase();
122
123 /*
124  *    string string_Upcase(string s):
125  *        Modifies: s
126  *        Effects: Modifies s by changing every lowercase character in s
127  *                 to the corresponding uppercase character.  Nothing else
128  *                 is changed.  I.e., "FoObAr19." is changed to "FOOBAR19.".
129  *                 S is returned as a convenience.
130  */
131
132 extern string string_Upcase();
133
134 #endif