Bug fixes + tabbing
[iotcloud.git] / version2 / src / C / IoTString.h
index bd838bb3ce8626634998ce586d8f55a3ff99cbbc..1fb527f03a9977233377a1796c0c2c47e656993c 100644 (file)
@@ -9,9 +9,9 @@
  * @version 1.0
  */
 
-inline int hashCharArray(Array<char> *array) {
+inline unsigned int hashCharArray(Array<char> *array) {
        uint len = array->length();
-       int hash = 0;
+       unsigned int hash = 0;
        for (uint i = 0; i < len; i++) {
                hash = 31 * hash + array->get(i);
        }
@@ -22,7 +22,7 @@ class IoTString {
 private:
        Array<char> *array;
        IoTString() {}
-       int hashvalue;
+       unsigned int hashvalue;
        /**
         * Builds an IoTString object around the char array.  This
         * constructor makes a copy, so the caller is free to modify the char array.
@@ -37,7 +37,7 @@ public:
        IoTString(const char *_array) {
                int32_t len = strlen(_array);
                array = new Array<char>(len);
-               strcpy(array->internalArray(), _array);
+               memcpy(array->internalArray(), _array, len);
                hashvalue = hashCharArray(array);
        }
 
@@ -50,6 +50,8 @@ public:
                delete array;
        }
 
+       char get(uint i) {return array->get(i);}
+
        /**
         * Internal method to grab a reference to our char array.  Caller
         * must not modify it.
@@ -77,18 +79,18 @@ public:
                return result == 0;
        }
 
-       int hashValue() { return hashvalue;}
+       unsigned int hashValue() { return hashvalue;}
        int length() { return array->length(); }
        friend IoTString *IoTString_shallow(Array<char> *_array);
 };
 
-IoTString *IoTString_shallow(Array<char> *_array) {
+inline IoTString *IoTString_shallow(Array<char> *_array) {
        IoTString *str = new IoTString();
        str->array = _array;
        return str;
 }
 
-inline int hashString(IoTString *a) {
+inline unsigned int hashString(IoTString *a) {
        return a->hashValue();
 }