summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-03-21 18:20:24 +0000
committerMike Buland <eichlan@xagasoft.com>2007-03-21 18:20:24 +0000
commit7edb08f083dbe1408285a083e4132673b6e1d7be (patch)
tree3769d4de0431de4d3f3e2cc87964e5b32bad4e71 /src
parent759aca25caaaf9a2b22297c4336f12c002d2faac (diff)
downloadlibbu++-7edb08f083dbe1408285a083e4132673b6e1d7be.tar.gz
libbu++-7edb08f083dbe1408285a083e4132673b6e1d7be.tar.bz2
libbu++-7edb08f083dbe1408285a083e4132673b6e1d7be.tar.xz
libbu++-7edb08f083dbe1408285a083e4132673b6e1d7be.zip
Fixed another random bug in the string compare for raw strings.
Diffstat (limited to '')
-rw-r--r--src/hash.cpp4
-rw-r--r--src/tests/hashtest2.cpp70
2 files changed, 8 insertions, 66 deletions
diff --git a/src/hash.cpp b/src/hash.cpp
index 004d6dd..c52e6b1 100644
--- a/src/hash.cpp
+++ b/src/hash.cpp
@@ -45,7 +45,7 @@ template<> bool __cmpHashKeys<const char *>( const char * const &a, const char *
45 return true; 45 return true;
46 46
47 for(int j=0; a[j] == b[j]; j++ ) 47 for(int j=0; a[j] == b[j]; j++ )
48 if( *a == '\0' ) 48 if( a[j] == '\0' )
49 return true; 49 return true;
50 50
51 return false; 51 return false;
@@ -74,7 +74,7 @@ template<> bool __cmpHashKeys<char *>( char * const &a, char * const &b )
74 return true; 74 return true;
75 75
76 for(int j=0; a[j] == b[j]; j++ ) 76 for(int j=0; a[j] == b[j]; j++ )
77 if( *a == '\0' ) 77 if( a[j] == '\0' )
78 return true; 78 return true;
79 79
80 return false; 80 return false;
diff --git a/src/tests/hashtest2.cpp b/src/tests/hashtest2.cpp
index 9ac75d5..74700fd 100644
--- a/src/tests/hashtest2.cpp
+++ b/src/tests/hashtest2.cpp
@@ -1,72 +1,14 @@
1#include "hash.h" 1#include "hash.h"
2#include <string.h> 2#include <string.h>
3 3
4typedef struct CC
5{
6 const char *sKey;
7 const char *sData;
8} CC;
9
10char *c(const char *s)
11{
12 int l = strlen(s);
13 char *o = new char[l+1];
14 o[l] = '\0';
15 memcpy(o, s, l);
16
17 return o;
18}
19
20CC *mkCC(const char *k, const char *d)
21{
22 CC *o = new CC;
23 o->sKey = c(k);
24 o->sData = c(d);
25 return o;
26}
27
28void klCC(CC *c)
29{
30 delete[] c->sKey;
31 delete[] c->sData;
32 delete c;
33}
34
35typedef Hash<const char *, CC *> CCHash;
36
37int main() 4int main()
38{ 5{
39 char buf1[200]; 6 char *a, *b;
40 char buf2[200]; 7 a = new char[10];
41 CCHash h; 8 b = new char[10];
42 CC *tmp; 9 strcpy( a, "Hey there");
43 10 strcpy( b, "Hey there");
44 for(int i=0;i<10;i++) 11 printf("Same: %s\n", __cmpHashKeys( a, b )?"yes":"no");
45 {
46 sprintf(buf1, "key_%d", i);
47 sprintf(buf2, "data_%d", i);
48 tmp = mkCC(buf1, buf2);
49 h[tmp->sKey] = tmp;
50 }
51
52 for(int i=0;i<12;i++)
53 {
54 sprintf(buf1, "key_%d", i);
55 if(h.has(buf1))
56 {
57 tmp = h[buf1];
58 printf("GOT %s = %s\n", tmp->sKey, tmp->sData);
59 }
60 else
61 printf("%s is not in the table.\n", buf1);
62 }
63
64 CCHash::iterator it = h.begin();
65 for(;it!=h.end();it++)
66 {
67 tmp = (*it).second;
68 klCC(tmp);
69 }
70 12
71 return 0; 13 return 0;
72} 14}