Standardize function names to snake_case.
authorChristopher Peplin <chris.peplin@rhubarbtech.com>
Sun, 29 Dec 2013 19:20:12 +0000 (14:20 -0500)
committerChristopher Peplin <chris.peplin@rhubarbtech.com>
Sun, 29 Dec 2013 19:21:27 +0000 (14:21 -0500)
README.mkd
src/bitfield/bitarray.c
src/bitfield/bitfield.c
src/bitfield/bitfield.h
tests/bitfield_tests.c
tests/write_tests.c

index 76feddb..836b151 100644 (file)
@@ -11,9 +11,9 @@ started, here are examples using the API:
 ## Bitfield Manipulation
 
     uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
-    uint8_t result = getByte(data, sizeof(data), 0);
-    uint8_t result = getNibble(data, sizeof(data), 0);
-    fail_unless(copyBitsRightAligned(data, 4, 4, 12, result, 4));
+    uint8_t result = get_byte(data, sizeof(data), 0);
+    uint8_t result = get_nibble(data, sizeof(data), 0);
+    fail_unless(copy_bits_right_aligned(data, 4, 4, 12, result, 4));
 
 ## 8 Byte Bitfield Decoding
 
index f8c2352..35fc2d9 100644 (file)
@@ -20,7 +20,7 @@ static const uint8_t reverse_mask[] =
 static const uint8_t reverse_mask_xor[] =
     { 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00 };
 
-bool copyBits(const uint8_t* source_origin, const uint16_t source_length,
+bool copy_bits(const uint8_t* source_origin, const uint16_t source_length,
         const uint16_t source_offset, uint16_t bit_count,
         uint8_t* destination_origin, const uint16_t destination_length,
         const uint16_t destination_offset) {
@@ -118,10 +118,10 @@ uint8_t find_end_bit(const uint16_t numBits) {
     return endBit == 0 ? CHAR_BIT : endBit;
 }
 
-bool copyBitsRightAligned(const uint8_t source[], const uint16_t source_length,
+bool copy_bits_right_aligned(const uint8_t source[], const uint16_t source_length,
                 const uint16_t offset, const uint16_t bit_count,
                 uint8_t* destination, const uint16_t destination_length) {
-    return copyBits(source, source_length, offset, bit_count, destination,
+    return copy_bits(source, source_length, offset, bit_count, destination,
             destination_length,
             // provide a proper destination offset so the result is right
             // aligned
index 3bf00ac..7dfa7cd 100644 (file)
@@ -5,10 +5,10 @@
 
 #define NIBBLE_SIZE (CHAR_BIT / 2)
 
-uint8_t getNibble(const uint8_t source[], const uint8_t source_length,
+uint8_t get_nibble(const uint8_t source[], const uint8_t source_length,
                 const uint8_t nibble_index) {
     uint8_t byte_index = nibble_index / 2;
-    uint8_t result = getByte(source, source_length, byte_index);
+    uint8_t result = get_byte(source, source_length, byte_index);
     if(nibble_index % 2 == 0) {
         result >>= NIBBLE_SIZE;
     }
@@ -16,7 +16,7 @@ uint8_t getNibble(const uint8_t source[], const uint8_t source_length,
     return result;
 }
 
-uint8_t getByte(const uint8_t source[], const uint8_t source_length,
+uint8_t get_byte(const uint8_t source[], const uint8_t source_length,
         const uint8_t byte_index) {
     if(byte_index < source_length) {
         return source[byte_index];
index 6f5f1c1..52ed143 100644 (file)
@@ -17,7 +17,7 @@ extern "C" {
  *
  * Returns the retreived nibble, right aligned in a uint8_t.
  */
-uint8_t getNibble(const uint8_t source[], const uint8_t source_length,
+uint8_t get_nibble(const uint8_t source[], const uint8_t source_length,
                 const uint8_t nibble_index);
 
 /* Public: Return a single byte from the byte array, with range checking.
@@ -28,7 +28,7 @@ uint8_t getNibble(const uint8_t source[], const uint8_t source_length,
  *
  * Returns the retreived byte.
  */
-uint8_t getByte(const uint8_t source[], const uint8_t source_length,
+uint8_t get_byte(const uint8_t source[], const uint8_t source_length,
         const uint8_t byte_index);
 
 /* Public: Copy a range of bits from one bit array to another.
@@ -44,7 +44,7 @@ uint8_t getByte(const uint8_t source[], const uint8_t source_length,
  *
  *      uint8_t source[4] = {0x11, 0x22, 0x33, 0x44};
  *      uint8_t destination[4] = {0};
- *      copyBits(source, sizeof(source), 8, 8, destination,
+ *      copy_bits(source, sizeof(source), 8, 8, destination,
  *              sizeof(destination), 0);
  *      // destination[0] == 0x22
  *      // destination[1] == 0x0
@@ -73,7 +73,7 @@ uint8_t getByte(const uint8_t source[], const uint8_t source_length,
  * Returns true if the copy was successful and false if the range exceeded the
  * size of the source or destination, or if the range size negative or 0.
  */
-bool copyBits(const uint8_t* source_origin, const uint16_t source_length,
+bool copy_bits(const uint8_t* source_origin, const uint16_t source_length,
         const uint16_t source_offset, uint16_t bit_count,
         uint8_t* destination_origin, const uint16_t destination_length,
         const uint16_t destination_offset);
@@ -88,7 +88,7 @@ bool copyBits(const uint8_t* source_origin, const uint16_t source_length,
  *
  *      uint8_t source[4] = {0x11, 0x22, 0x33, 0x44};
  *      uint8_t destination[4] = {0};
- *      copyBitsRightAligned(source, sizeof(source), 8, 8, destination,
+ *      copy_bits_right_aligned(source, sizeof(source), 8, 8, destination,
  *              sizeof(destination));
  *      // destination[0] == 0x0
  *      // destination[1] == 0x0
@@ -98,13 +98,13 @@ bool copyBits(const uint8_t* source_origin, const uint16_t source_length,
  *      int value = (int)destination;
  *      // value == 0x22 == 32
  *
- * The arguments are the same as copyBits, but without the destination_offset
+ * The arguments are the same as copy_bits, but without the destination_offset
  * option - that's set automatically to right align the result.
  *
  * Returns true if the copy was successful and false if the range exceeded the
  * size of the source or destination, or if the range size negative or 0.
  */
-bool copyBitsRightAligned(const uint8_t source[], const uint16_t source_length,
+bool copy_bits_right_aligned(const uint8_t source[], const uint16_t source_length,
                 const uint16_t offset, const uint16_t bit_count,
                 uint8_t* destination, const uint16_t destination_length);
 
index f6287c1..3f54eee 100644 (file)
@@ -5,9 +5,9 @@
 START_TEST (test_get_byte)
 {
     uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
-    uint8_t result = getByte(data, sizeof(data), 0);
+    uint8_t result = get_byte(data, sizeof(data), 0);
     ck_assert_int_eq(result, 0x12);
-    result = getByte(data, sizeof(data), 3);
+    result = get_byte(data, sizeof(data), 3);
     ck_assert_int_eq(result, 0x78);
 }
 END_TEST
@@ -15,11 +15,11 @@ END_TEST
 START_TEST (test_get_nibble)
 {
     uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
-    uint8_t result = getNibble(data, sizeof(data), 0);
+    uint8_t result = get_nibble(data, sizeof(data), 0);
     ck_assert_int_eq(result, 0x1);
-    result = getNibble(data, sizeof(data), 1);
+    result = get_nibble(data, sizeof(data), 1);
     ck_assert_int_eq(result, 0x2);
-    result = getNibble(data, sizeof(data), 2);
+    result = get_nibble(data, sizeof(data), 2);
     ck_assert_int_eq(result, 0x3);
 }
 END_TEST
@@ -28,7 +28,7 @@ START_TEST (test_get_bits_out_of_range)
 {
     uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
     uint8_t result[4];
-    fail_if(copyBitsRightAligned(data, 4, 25, 16, result, 4));
+    fail_if(copy_bits_right_aligned(data, 4, 25, 16, result, 4));
 }
 END_TEST
 
@@ -36,7 +36,7 @@ START_TEST (test_get_bits)
 {
     uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
     uint8_t result[4] = {0};
-    fail_unless(copyBitsRightAligned(data, 4, 0, 16, result, 4));
+    fail_unless(copy_bits_right_aligned(data, 4, 0, 16, result, 4));
     ck_assert_int_eq(result[0], 0x12);
     ck_assert_int_eq(result[1], 0x34);
 }
@@ -46,7 +46,7 @@ START_TEST (test_get_uneven_bits)
 {
     uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
     uint8_t result[4] = {0};
-    fail_unless(copyBitsRightAligned(data, 4, 4, 12, result, 4));
+    fail_unless(copy_bits_right_aligned(data, 4, 4, 12, result, 4));
     ck_assert_int_eq(result[0], 0x2);
     ck_assert_int_eq(result[1], 0x34);
 }
index 8cc35e2..4091ac4 100644 (file)
@@ -27,7 +27,6 @@ START_TEST (test_encode_bool)
     ck_assert_int_eq(value, 0x0000000000000000LLU);
 }
 END_TEST
-// TODO test encode bool
 
 Suite* canwriteSuite(void) {
     Suite* s = suite_create("write");