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
5 * Created by: Marc Horowitz <marc@athena.mit.edu>
9 * Copyright (c) 1989 by the Massachusetts Institute of Technology.
10 * For copying and distribution information, see the file
18 #include "new_memory.h"
23 * int string_Length(string s):
24 * Effects: Returns the number of non-null characters in s.
27 #define string_Length(s) strlen(s)
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.
35 #define string_Eq(a,b) (!strcmp(a,b))
38 * int string_Neq(string a, b):
39 * Effects: Returns true iff strings a & b are not equal.
42 #define string_Neq(a,b) (strcmp(a,b))
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
54 extern string string__CreateFromData();
56 #define string_CreateFromData(data,length) (set_module(__FILE__,__LINE__),\
57 string__CreateFromData(data,length))
59 #define string_CreateFromData(data,length) string__CreateFromData(data,length)
63 * string string_Copy(string s):
64 * Effects: Returns a copy of s on the heap. The copy must be
68 extern string string__Copy(/* string s */);
70 #define string_Copy(data) (set_module(__FILE__,__LINE__),\
73 #define string_Copy(data) string__Copy(data)
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").
84 extern string string__Concat(/* string a, b */);
86 #define string_Concat(a,b) (set_module(__FILE__,__LINE__),\
89 #define string_Concat(a,b) string__Concat(a,b)
93 * string string_Concat2(string a, b):
95 * Requires: a is on the heap, b does not point into a.
96 * Effects: Equivalent to:
98 * temp = string_Concat(a,b);
101 * only faster. I.e., uses realloc instead of malloc+bcopy.
104 extern string string__Concat2(/* string a, b */);
106 #define string_Concat2(a,b) (set_module(__FILE__,__LINE__),\
107 string__Concat2(a,b))
109 #define string_Concat2(a,b) string__Concat2(a,b)
113 * string string_Downcase(string 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.
121 extern string string_Downcase();
124 * string string_Upcase(string 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.
132 extern string string_Upcase();