src/StringTable.cc

changeset 115
9be16e1c1e44
parent 112
def56932f938
equal deleted inserted replaced
114:6cbeb9f8350f 115:9be16e1c1e44
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 // TODO: Another freeloader...
30
29 #include <stdio.h> 31 #include <stdio.h>
30 #include <stdlib.h> 32 #include <stdlib.h>
31 #include <string.h> 33 #include <string.h>
32 #include "StringTable.h" 34 #include "StringTable.h"
33 35
34 static StringList gStringTable; 36 static StringList g_StringTable;
35 37
36 // ============================================================================ 38 // ============================================================================
37 // 39 //
38 const StringList& GetStringTable() 40 const StringList& getStringTable()
39 { 41 {
40 return gStringTable; 42 return g_StringTable;
41 } 43 }
42 44
43 // ============================================================================ 45 // ============================================================================
44 // 46 //
45 // Potentially adds a string to the table and returns the index of it. 47 // Potentially adds a string to the table and returns the index of it.
46 // 48 //
47 int StringTableIndex (const String& a) 49 int getStringTableIndex (const String& a)
48 { 50 {
49 // Find a free slot in the table. 51 // Find a free slot in the table.
50 int idx; 52 int idx;
51 53
52 for (idx = 0; idx < gStringTable.Size(); idx++) 54 for (idx = 0; idx < g_StringTable.size(); idx++)
53 { 55 {
54 // String is already in the table, thus return it. 56 // String is already in the table, thus return it.
55 if (gStringTable[idx] == a) 57 if (g_StringTable[idx] == a)
56 return idx; 58 return idx;
57 } 59 }
58 60
59 // Must not be too long. 61 // Must not be too long.
60 if (a.Length() >= gMaxStringLength) 62 if (a.length() >= gMaxStringLength)
61 Error ("string `%1` too long (%2 characters, max is %3)\n", 63 error ("string `%1` too long (%2 characters, max is %3)\n",
62 a, a.Length(), gMaxStringLength); 64 a, a.length(), gMaxStringLength);
63 65
64 // Check if the table is already full 66 // Check if the table is already full
65 if (gStringTable.Size() == gMaxStringlistSize - 1) 67 if (g_StringTable.size() == gMaxStringlistSize - 1)
66 Error ("too many strings!\n"); 68 error ("too many strings!\n");
67 69
68 // Now, dump the string into the slot 70 // Now, dump the string into the slot
69 gStringTable.Append (a); 71 g_StringTable.append (a);
70 return (gStringTable.Size() - 1); 72 return (g_StringTable.size() - 1);
71 } 73 }
72 74
73 // ============================================================================ 75 // ============================================================================
74 // 76 //
75 // Counts the amount of strings in the table. 77 // Counts the amount of strings in the table.
76 // 78 //
77 int CountStringsInTable() 79 int countStringsInTable()
78 { 80 {
79 return gStringTable.Size(); 81 return g_StringTable.size();
80 } 82 }

mercurial