+/EE312

software design

git clone https://git.julia.blue/+/EE312

Joseph RyanProject 40c27270

master
1.9 KiB52 linesraw
1// String.h
2#ifndef _String_h
3#define _String_h 1
4
5struct String {
6    int len; // number of chars in the string (does not include the zero)
7    char* ptr; // pointer to an array on the heap (where the chars are stored)
8};
9
10/* two creation functions, the first promotes an ordinary C string to our Strings
11 * the second creates a new duplicate of an existing String */
12String StringCreate(const char* c_string);
13String StringDup(String* s);
14
15/* a more powerful creation function that creates a new string
16 * by concatenating pre and suff
17 * the newly created string will consist of all the characters from pre
18 * followed by all the characters in suff */
19String StringConcat(String* pre, String* suff);
20
21void StringDestroy(String* s); // our cleanup function
22
23/* display the String s on the standard output console */
24void StringPrint(String* s);
25
26/* MUTATOR: change the String dst so that it is an identical copy of src
27 * dst must already exist (i.e., dst must have been previously created/initialized) */
28void StringReAssign(String* dst, String* src);
29
30/* PREDICATE: return true iff s1 represents exactly the same string as s2 */
31bool StringIsEqualTo(String* s1, String* s2);
32
33/* PREDICATE: return true iff s1 comes before s2 in dictionary order
34 * NOTE: the comparison is based on the ordering in the asii table, so it is
35 * case sensitive ('Z' < 'a') and is defined for punctuation, although the behavior
36 * for comparing strings with punctuation is rather arbitrary */
37bool StringIsLessThan(String* s1, String* s2);
38
39
40/* MUTATOR
41 * append suffix to s
42 * the string s is increased in size by appending suffix to the end (suffix is not changed) */
43void StringAppend(String* s, String* suffix);
44
45/* ACCESSOR
46 * return the number of characters in s
47 * Use this macro like a function StringSize that returns the length of a String.
48 */
49#define StringSize(s) ((*s).len)
50
51
52#endif /* _String_h */