SE250:lab-9:rwan064:string.h
Jump to navigation
Jump to search
<html> <head>
<title>string.h</title>
</head> <body bgcolor="#ffffff" text="#000000">
<a name="line1"> 1</a> <font color="#444444">/* <a name="line2"> 2</a> File: string.h <a name="line3"> 3</a> Author: Rajitha Wannigama <a name="line4"> 4</a> Purpose: Header file for String type implementation in C. <a name="line5"> 5</a> */</font> <a name="line6"> 6</a> <a name="line7"> 7</a> <strong>typedef</strong> <a name="line8"> 8</a> <strong>struct</strong> <font color="#2040a0">String</font> <font color="4444FF"><strong>{</strong></font> <a name="line9"> 9</a> <strong>char</strong> <font color="4444FF">*</font><font color="#2040a0">str</font><font color="4444FF">;</font> <a name="line10">10</a> // <font color="#2040a0">Length</font> <font color="#2040a0">and</font> <font color="#2040a0">capacity</font> <font color="#2040a0">doesn</font>'<font color="#2040a0">t</font> <font color="#2040a0">include</font> <font color="#2040a0">NULL</font> <font color="#2040a0">terminator</font>. <a name="line11">11</a> <strong>unsigned</strong> <strong>int</strong> <font color="#2040a0">length</font><font color="4444FF">;</font> <a name="line12">12</a> <strong>unsigned</strong> <strong>int</strong> <font color="#2040a0">capacity</font><font color="4444FF">;</font> <a name="line13">13</a> <font color="4444FF"><strong>}</strong></font> <font color="#2040a0">String</font><font color="4444FF">;</font> <a name="line14">14</a> <a name="line15">15</a> <strong>extern</strong> <font color="#2040a0">String</font> <font color="4444FF">*</font><font color="#2040a0">null_s</font><font color="4444FF">;</font> <a name="line16">16</a> //<strong>extern</strong> <font color="#2040a0">String</font> <font color="#2040a0">empty_s</font><font color="4444FF">;</font> <a name="line17">17</a> <a name="line18">18</a> <font color="#2040a0">String</font><font color="4444FF">*</font> <font color="#2040a0">create_empty_string</font><font color="4444FF">(</font> <strong>void</strong> <font color="4444FF">)</font><font color="4444FF">;</font> <a name="line19">19</a> <font color="#2040a0">String</font><font color="4444FF">*</font> <font color="#2040a0">create_string</font><font color="4444FF">(</font> <strong>const</strong> <strong>char</strong> <font color="4444FF">*</font><font color="#2040a0">source</font> <font color="4444FF">)</font><font color="4444FF">;</font> <a name="line20">20</a> <strong>void</strong> <font color="#2040a0">print_string</font><font color="4444FF">(</font> <font color="#2040a0">String</font> <font color="4444FF">*</font><font color="#2040a0">str</font> <font color="4444FF">)</font><font color="4444FF">;</font> <a name="line21">21</a> <a name="line22">22</a> <strong>void</strong> <font color="#2040a0">change_string</font><font color="4444FF">(</font> <font color="#2040a0">String</font> <font color="4444FF">*</font><font color="#2040a0">destination</font>, <strong>const</strong> <font color="#2040a0">String</font> <font color="4444FF">*</font><font color="#2040a0">source</font> <font color="4444FF">)</font><font color="4444FF">;</font> <a name="line23">23</a> <a name="line24">24</a> <font color="#444444">/* <a name="line25">25</a> Get a C-Style string of the string represented by this String object <a name="line26">26</a> This function allocates a new area of memory for the C-style string. <a name="line27">27</a> */</font> <a name="line28">28</a> <strong>char</strong><font color="4444FF">*</font> <font color="#2040a0">get_cstring</font><font color="4444FF">(</font> <font color="#2040a0">String</font> <font color="4444FF">*</font><font color="#2040a0">str</font> <font color="4444FF">)</font><font color="4444FF">;</font> <a name="line29">29</a> <a name="line30">30</a> <font color="#444444">/* Resize a String object */</font> <a name="line31">31</a> <strong>void</strong> <font color="#2040a0">ensure_capacity</font><font color="4444FF">(</font> <font color="#2040a0">String</font> <font color="4444FF">*</font><font color="#2040a0">s</font>, <strong>unsigned</strong> <strong>int</strong> <font color="#2040a0">cap</font> <font color="4444FF">)</font><font color="4444FF">;</font> <a name="line32">32</a> <a name="line33">33</a> <strong>void</strong> <font color="#2040a0">append_string</font><font color="4444FF">(</font> <font color="#2040a0">String</font> <font color="4444FF">*</font><font color="#2040a0">destination</font>, <strong>const</strong> <font color="#2040a0">String</font> <font color="4444FF">*</font><font color="#2040a0">source</font> <font color="4444FF">)</font><font color="4444FF">;</font> <a name="line34">34</a> <strong>void</strong> <font color="#2040a0">append_cstring</font><font color="4444FF">(</font> <font color="#2040a0">String</font> <font color="4444FF">*</font><font color="#2040a0">destination</font>, <strong>const</strong> <strong>char</strong> <font color="4444FF">*</font><font color="#2040a0">source</font> <font color="4444FF">)</font><font color="4444FF">;</font> <a name="line35">35</a> <a name="line36">36</a> <font color="#444444">/* TO BE IMPLEMENTED */</font> <a name="line37">37</a> <font color="#444444">/* Compare two strings and see if they are equal. If they are equal, return TRUE(non-zero). Otherwise FALSE(zero) value is returned. */</font> <a name="line38">38</a> <strong>int</strong> <font color="#2040a0">compare_strings</font><font color="4444FF">(</font> <strong>const</strong> <font color="#2040a0">String</font> <font color="4444FF">*</font><font color="#2040a0">s1</font>, <strong>const</strong> <font color="#2040a0">String</font> <font color="4444FF">*</font><font color="#2040a0">s2</font> <font color="4444FF">)</font><font color="4444FF">;</font>
syntax highlighted by <a href="http://www.palfrader.org/code2html">Code2HTML</a>, v. 0.9.1 </body> </html>